一:嵌套查询示例:
select pt from PubTemp pt where pt.isshare = 1 and (pt.tplName like '%测试%' or pt.author like '%测试%')或者使用in查询:
String searchHql="select pt from PubTemp pt where pt.pubTempGroup.groupId="+groupId+" and pt.isshare = 1"
+ and pubtemp.tplId in (select pubtemp2.tplId from PubTemp pubtemp2 "
+"where pubtemp2.tplName like ? or pubtemp2.author like ?)";
二:中文查询无效果,但是java程序中和数据库均无乱码,或字符编码不同的问题
mysql数据库:jdbc连接如下:url="jdbc:mysql://127.0.0.1:3306/xhslapp?useUnicode=true&characterEncoding=UTF-8"
一定要在连接串上指明:
?useUnicode=true&characterEncoding=UTF-8
本文介绍了一种使用嵌套查询和IN查询的方法来提高数据库检索效率,并解决了中文查询时可能出现的问题。通过示例展示了如何进行精确匹配,以及如何确保数据库连接字符串正确配置以避免字符编码问题。
5万+

被折叠的 条评论
为什么被折叠?



