模糊查询:
?
|
1
2
3
4
|
@Select({
"SELECT * FROM account where account like CONCAT('%',#{query},'%') or email like CONCAT('%',#{query},'%')"
})
Account findAccountByAccountOrMail(@Param("query") String query);
|
批量添加:
?
|
1
2
3
4
5
6
7
8
9
|
@Insert({
"<script>" +
"INSERT INTO company_label(company_id,label_id) values " +
" <foreach collection=\\"item\\" item=\\"item\\" index=\\"index\\" separator=\\",\\" > " +
" (#{companyId},#{item}) " +
" </foreach>" +
"</script>"
})
void insertLabelForCompany(@Param("companyId") Long companyId,@Param("item") List<Long> item);
|
批量删除:
?
|
1
2
3
4
5
6
7
8
|
@Delete({
"<script>delete from company_label where company_id = #{companyId} and label_id in " +
"<foreach collection = \\"item\\" item = \\"item\\" open=\\"(\\" separator=\\",\\" close=\\")\\">" +
"#{item}" +
"</foreach>" +
"</script>"
})
void removeLabelForCompany(@Param("companyId") Long companyId,@Param("item") List<Long> item);
|
批量修改:
?
|
1
2
3
4
5
|
@Update(value = "<script>" + "update banner b set b.display = #{status} where b.id in "+
"<foreach item = 'item' index = 'index' collection = 'ids' open = '(' separator = ',' close = ')'>#{item}</foreach>" +
"" +
"</script>")
int updateStatus(@Param("status") Long status, @Param("ids") Long[] ids);
|
批量查询:
?
|
1
2
3
4
5
6
7
|
@Select({
"<script>" +
"select * from product where id in" +
"<foreach item = 'item' index = 'index' collection = 'idList' open = '(' separator = ',' close = ')'>#{item}</foreach>" +
"</script>"
})
List<Product> findByIdList(@Param("idList")List<Long> idList);
|
条件查询,if里面不仅可以判空,还可以判断是否满足某个条件
?
|
1
2
3
4
5
6
7
8
9
|
@Select({
"<script>SELECT * FROM company where 1=1 and parent_id = #{companyId} " +
//平级
"<if test = \\"isScanSameLevelValue == 1\\">and type = #{type}</if>" +
"<if test = \\"isScanSameLevelValue == 0\\">and type != #{type}</if>" +
"</script> "
})
List<Company> findCompanyConditional(@Param("isScanSameLevelValue") String isScanSameLevelValue, @Param("isScanParentLevelValue") String isScanParentLevelValue, @Param("companyId") Long companyId, @Param("type") Integer type);
|
条件查询:
?
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
*/
@Lang(XMLLanguageDriver.class)
@Select({"<script>select DISTINCT p.* FROM `us_product`.`hot_category_surgery` hcs "+
"LEFT JOIN `us_product`.`product` p ON hcs.`product_id` =p.`id`"+
"LEFT JOIN `us_product`.`category_surgery` cs on cs.`product_id` =p.`id`"+
"LEFT JOIN `us_product`.`merchant_product` mp on mp.`product_id` = p.`id`"+
"LEFT JOIN `us_product`.`org_product` op on op.`product_id` =p.`id`"+
"where p.`type` =1 and p.`is_for_sale` =1 "+
" <if test=\\"hId != null\\"> and hcs.hot_category_id = #{hId} and p.id = hcs.product_id</if>" + //热门类目id
" <if test=\\"categoryId != null\\"> and cs.category_id = #{categoryId} and p.id = cs.product_id</if>" + //类目id
" <if test=\\"input != null\\"> and (p.name like CONCAT('%',#{input},'%') or p.company like CONCAT('%',#{input},'%')) </if> "+ //用户输入,包括商品名和店铺名,模糊
" <if test = \\" location != null\\"> and p.location like CONCAT('%',#{location},'%') </if> "+ //位置..
" <if test=\\"method != null\\"> and mp.filter_id = #{method} and p.id = mp.product_id</if> "+ //筛选条件 手术方式
" <if test=\\"org != null\\"> and op.filter_id = #{org} and p.id = op.product_id</if> "+ //筛选条件 所属机构
" ORDER BY sale_volume DESC"+
" </script>"
})
List<Product> findProductFromLocal(@Param("hId")Long hId,@Param("categoryId")Long categoryId,@Param("input")String input,@Param("method")Long method,@Param("org")Long org,@Param("location")String location);
|
以上所述是小编给大家介绍的Mybatis 条件查询 批量增删改查功能,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对快网idc网站的支持!
原文链接:http://blog.csdn.net/c568254965/article/details/73527347
相关文章
猜你喜欢
- 个人网站服务器域名解析设置指南:从购买到绑定全流程 2025-06-10
- 个人网站搭建:如何挑选具有弹性扩展能力的服务器? 2025-06-10
- 个人服务器网站搭建:如何选择适合自己的建站程序或框架? 2025-06-10
- 64M VPS建站:能否支持高流量网站运行? 2025-06-10
- 64M VPS建站:怎样选择合适的域名和SSL证书? 2025-06-10
TA的动态
- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
- 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
- 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
- 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
- 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
快网idc优惠网
QQ交流群
您的支持,是我们最大的动力!
热门文章
-
Laravel执行migrate命令提示:No such file or directory的解决方法
2025-05-29 43 -
2025-05-27 88
-
2025-05-26 65
-
2025-05-26 77
-
2025-05-27 84
热门评论

