我正在尝试根据用户查询搜索名称 用户(ID,FNAME,L-NAME,..) 业务(ID,姓名,地址......)
我正在编写像
这样的hql查询 String hql1 = "select count(*) from Client as cl "
+ "where cl.id=:bid "
+ " and (cl.user.fname=:fname "
+ " or cl.user.lname=:lname "
+ " or cl.business.name=:name)";
Query query1 = session.createQuery(hql1).setParameter("bid", bid)
.setParameter("fname", name + "%").setParameter("lname", name + "%").setParameter("name", name + "%");
count = (Long) query1.uniqueResult();
我想搜索用户输入的字符串是用于fname还是用于lname或名称。 如果喜欢我必须去取的地方。 但这不是取数据。
答案 0 :(得分:1)
String hql1 = "select count(*) from Client as cl "
+ "where cl.id=:bid "
+ " and (cl.user.fname like :fname "
+ " or cl.user.lname like :lname "
+ " or cl.business.name like :name)";
Query query1 = session.createQuery(hql1).setParameter("bid", bid)
.setParameter("fname", "%"+name + "%").setParameter("lname", "%"+name + "%").setParameter("name", "%"+name + "%");
count = (Long) query1.uniqueResult();