模糊查询:
@Select({
"SELECT * FROM account where account like CONCAT('%',#{query},'%') or email like CONCAT('%',#{query},'%')"
})
Account findAccountByAccountOrMail(@Param("query") String query);
批量添加:
@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);
批量删除:
@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);
批量修改:
@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);
批量查询:
@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里面不仅可以判空,还可以判断是否满足某个条件
@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);
条件查询:
*/
@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 条件查询 批量增删改查功能,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
# mybatis
# 条件查询
# mybatis增删改查
# 详解MyBatis直接执行SQL查询及数据批量插入
# Mybatis如何根据List批量查询List结果
# mybatis接收以逗号分隔的字符串批量查询方式
# mybatis批量新增、删除、查询和修改方式
# MyBatis的五种批量查询实例总结
# 小编
# 类目
# 还可以
# 在此
# 给大家
# 所述
# 给我留言
# 感谢大家
# 判断是否
# 疑问请
# 有任何
# insertLabelForCompany
# Long
# Delete
# List
相关文章:
建站主机选购指南与交易推荐:核心配置解析
独立制作一个网站多少钱,建立网站需要花多少钱?
建站之星如何实现网站加密操作?
制作农业网站的软件,比较好的农业网站推荐一下?
如何选择靠谱的建站公司加盟品牌?
网站制作公司,橙子建站是合法的吗?
电商网站制作多少钱一个,电子商务公司的网站制作费用计入什么科目?
建站之星图片链接生成指南:自助建站与智能设计教程
如何做网站制作流程,*游戏网站怎么搭建?
如何选择网络建站服务器?高效建站必看指南
网站制作费用多少钱,一个网站的运营,需要哪些费用?
如何自定义建站之星网站的导航菜单样式?
寿县云建站:智能SEO优化与多行业模板快速上线指南
公司网站制作费用多少,为公司建立一个网站需要哪些费用?
公司网站设计制作厂家,怎么创建自己的一个网站?
如何彻底卸载建站之星软件?
太平洋网站制作公司,网络用语太平洋是什么意思?
活动邀请函制作网站有哪些,活动邀请函文案?
青岛网站建设如何选择本地服务器?
企业网站制作费用多少,企业网站空间一般需要多大,费用是多少?
如何在IIS中新建站点并解决端口绑定冲突?
定制建站方案优化指南:企业官网开发与建站费用解析
建站之星官网登录失败?如何快速解决?
如何选择适合PHP云建站的开源框架?
如何快速完成中国万网建站详细流程?
香港代理服务器配置指南:高匿IP选择、跨境加速与SEO优化技巧
网站广告牌制作方法,街上的广告牌,横幅,用PS还是其他软件做的?
沈阳个人网站制作公司,哪个网站能考到沈阳事业编招聘的信息?
宝塔面板如何快速创建新站点?
上海网站制作网站建设公司,建筑电工证网上查询系统入口?
如何配置IIS站点权限与局域网访问?
如何正确下载安装西数主机建站助手?
广平建站公司哪家专业可靠?如何选择?
如何在阿里云部署织梦网站?
网站制作外包价格怎么算,招聘网站上写的“外包”是什么意思?
如何在西部数码注册域名并快速搭建网站?
长沙做网站要多少钱,长沙国安网络怎么样?
Swift中循环语句中的转移语句 break 和 continue
,制作一个手机app网站要多少钱?
昆明网站制作哪家好,昆明公租房申请网上登录入口?
自助网站制作软件,个人如何自助建网站?
建站之星ASP如何实现CMS高效搭建与安全管理?
如何用低价快速搭建高质量网站?
音乐网站服务器如何优化API响应速度?
焦点电影公司作品,电影焦点结局是什么?
php能控制zigbee模块吗_php通过串口与cc2530 zigbee通信【介绍】
专业商城网站制作公司有哪些,pi商城官网是哪个?
如何在IIS中新建站点并配置端口与物理路径?
建站上市公司网站建设方案与SEO优化服务定制指南
大连网站制作费用,大连新青年网站,五年四班里的视频怎样下载啊?
*请认真填写需求信息,我们会在24小时内与您取得联系。