Mybatis 注解方式-按条件、批量增删改查

按条件查询

@Select("<script>" +
            "SELECT role_id,role_name " +
            "FROM `edu_base_role` " +
            "<where>" +
            "<if test=\"roleType != null\">" +
            "role_type=#{roleType} " +
            "</if>" +
            "</where>" +
            "</script>")
    List<MemRoleResult> selectMemRole(@Param("roleType") Integer roleType);

按条件更新

 @Update("<script>" +
            "UPDATE edu_member_rigths_dispose" +
            "<set>" +
            "<if test=\"mrId != null\">" +
            " mr_id = #{mrId}, " +
            "</if>" +
            "<if test=\"mrName != null\">" +
            "mr_name = #{mrName}," +
            "</if>" +
            "</set>" +
            "WHERE mrd_id = #{mrdId}" +
            "</script>")
    void updMemRightsDispose(MemRigthsDispose memRigthsDispose);

批量插入

  @Insert("<script>" +
            "INSERT INTO edu_member_user_rights_detail (" +
            "mrd_unit,mrd_remarks,murd_term_end_time,murd_status,murd_use_time,create_uid,create_time,del_status) VALUES " +
            " <foreach item='c' index='index' collection='addUserRightsDetailParamsList' separator=',' >" +
            " (#{c.mrdUnit},#{c.mrdRemarks},#{c.murdTermEndTime},#{c.murdStatus},#{c.murdUseTime},#{c.createUid}," +
            "#{c.createTime},#{c.delStatus}) " +
            " </foreach>" +
            "</script>")
    void addBatchUserRightsDetail(@Param("addUserRightsDetailParamsList")List<AddUserRightsDetailParams> addUserRightsDetailParamsList);

批量查询

@Select("<script>" + "SELECT " + LIST_COLUMNS + " FROM edu_tag_library WHERE del_status=0 "
            + "<if test = \"null != tlBizIds \" > " + "and tl_biz_id IN " +
            "<foreach item='tlBizId' index='index' collection='tlBizIds' open='(' separator=',' close=')'>" +
            "#{tlBizId}" +
            "</foreach>" +
            "</if></script>")
    List<TagLibrary> selectTagLibraryByTlBizId(@Param("tlBizIds") List<String> tlBizIds);
模糊查询
@Select("<script>" +
            "SELECT fc_id,fc_number,dept_name,job_name, create_name as applicantName,fc_type,fc_cost_item,fc_cost_project,fc_fee,fc_cost_date" +
            " from edu_fee_cost WHERE del_status=0 and ki_id=#{kiId}" +
            " <if test = \"null !=  fcNumber and fcNumber != ''\"> " +
            " and fc_number like CONCAT('%',#{fcNumber},'%') " +
            " </if> " +
            " <if test = \"null !=  applicantName and applicantName != ''\"> " +
            " and create_name like CONCAT('%',#{applicantName},'%') " +
            " </if> " +
            " <if test = \"null != fcStartDate and null !=fcEndDate and fcStartDate!='' and fcEndDate !='' \"> " +
            " and  DATE_FORMAT(fc_cost_date,'%Y-%m-%d') between #{fcStartDate} and #{fcEndDate} " +
            " </if> " +
            " <if test = \"null != fcStartFee and null !=fcEndFee and fcEndFee !=-1 \"> " +
            " and  fc_fee between #{fcStartFee} and #{fcEndFee} " +
            " </if> " +
            " <if test = \"null != fcStartFee  and null !=fcEndFee and fcEndFee==-1 \"> " +
            " and  fc_fee >= #{fcStartFee}" +
            " </if> " +
            " <if test = \"null != searchName and searchName !=''  \"> " +
            " and (fc_number like CONCAT('%',#{searchName},'%') or create_name like CONCAT('%',#{searchName},'%') or fc_cost_project like CONCAT('%',#{searchName},'%'))"+
            " </if> " +
            " <if test = \"null != fcType and fcType.size > 0 \">" +
            " and fc_type in"+
            "<foreach item='item' index='index' collection='fcType' open='(' separator=',' close=')'>" +
            " #{item} " +
            "</foreach>" +
            " </if> " +
            "</script>" )
    List<FeeCostPageResult> getFeeCostPage(FeeCostPageParam param);

批量更新

@Update("<script>" + " <foreach collection='list' item='item' index='index' separator=','> "
            + " UPDATE edu_tag_user_rel  " + " SET del_status = 1  " + " WHERE "
            + " <if test = \" item.usrId != null and item.usrId != '' \"> " + " tur_obj_id = #{item.usrId} " + " </if> "
            + " <if test = \" item.kiId != null and item.kiId != '' \"> " + " tur_obj_id = #{item.kiId} " + " </if> "
            + " <if test = \" item.tlBizId != null and item.tlBizId != '' \"> "
            + " AND tl_id = ( SELECT tl_id FROM edu_tag_library WHERE tl_biz_id = #{item.tlBizId} AND tl_source_type = 0 AND del_status = 0 AND enable_status = 1 ) "
            + " </if> " + " </foreach> " + "</script>")
    int delTurByBizId(List<DelTurParams> list);
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值