HQL 模糊查询

(1)HQL查询语句

String hql = "from Subject as s where s.subname like :name and s.subinfo like :info"; 

Query query = session.createQuery(hql); 
query.setString("name","%"+name+"%"); 
query.setString("info","%"+info+"%");

 

(2)HQL查询语句(查询条件只能为英文或数字,汉字在传递到hibernate内部时出现乱码问题)

String hql = "from Subject as s where s.subname like '%"+name+"%' and s.subinfo like '%"+info+"%'";

Query query = session.createQuery(hql);

注:Subject为数据库表subject映射的类;它有相应的属性subname、subinfo及相应的get和set方法;sub为Subject的一个实例化对象。

你可能感兴趣的:(HQL)