时间:2021-05-20
模糊查询:
@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 条件查询 批量增删改查功能,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
今天刚刚学习了mybatis,做了简单的对数据库的增删改查。在进行删除操作时,单条删除时很简单,但是批量删除的时候拼接删除条件却有些麻烦,现记录一下做法。Sql
一、简介Mybatis-Plus是一款MyBatis动态sql自动注入crud简化增删改查操作中间件。启动加载XML配置时注入mybatis单表动态SQL操作,
在使用MyBatis-plus的时候,一些基础的增删改查可以不用再自己写sql了:publicinterfaceUserDaoextendsBaseMapper
Mybatis的缓存mybatis是一个查询数据库的封装框架,主要是封装提供灵活的增删改sql,开发中,service层能够通过mybatis组件查询和修改数据
一个专门实现sqlserver数据库的增删改查,以及将查询的结果返回成表格等功能,分享代码如下usingSystem;usingSystem.Collectio