开发总结-Dao层(Mapper层)

Mybatis-plus新用法

VehicleBO one = vehicleService.getOne(Wrappers.<VehicleBO>lambdaQuery().eq(VehicleBO::getVin, reqVo.getVin()));

boolean b = bizAccountApplyService.remove(Wrappers.<BizAccountApplyBO>lambdaQuery().eq(BizAccountApplyBO::getId, 1457753126076448l));

iBizAccountService.update(Wrappers.<BizAccountBO>lambdaUpdate().setSql("follow_count=follow_count+1").eq(BizAccountBO::getId, accountId));

mybatisPlus坑

字段更新为null 默认不生效,除非加上updateStrategy = FieldStrategy.IGNORED

@ApiModelProperty(value = "贷款类型")
@TableField(value = "LOAN_TYPE", updateStrategy = FieldStrategy.IGNORED)
private String loanType;

Cause: java.sql.SQLIntegrityConstraintViolationException: ORA-01400: 无法将 NULL 插入 (“ZHXY_RSW_LOCAL”.“T_EXAM_SUBJECT”.“ID”)
使用mybatis-plus插入时,明明设置了id的值,还报这个错
解决办法:在id字段上,添加 @TableId(type = IdType.INPUT)
在这里插入图片描述

条件是表中的某个字段不为null时,添加过滤

在这里插入图片描述
上面这样写会报错,下面这样写才对
在这里插入图片描述

left join时左表过滤用where,右表过滤用and

说有下面两张表
在这里插入图片描述
在这里插入图片描述
– 找出每个班级的名称及其对应的女同学数量

SELECT c.name, count(s.name) as num 
FROM classes c left join students s 
on s.class_id = c.id 
and s.gender = 'f'
group by c.name

– 找出一班的同学总数

SELECT c.name, count(s.name) as num 
FROM classes c left join students s 
on s.class_id = c.id 
where c.name = '一班' 
group by c.name

mysql分组后 组内排序 然后取每组第一条结果

需求:按room_id分组后,组内按data_time排序,然后取每组的第一条数据
可能看不懂,但就这么写没错,亲测正确(必须加limit)

		select t.* from (
            select t1.room_id,t2.room_name,t1.queuing_time,t1.in_num
            from t_meal_room t2
            left join t_meal_data t1 on t1.room_id=t2.id
            order by t1.data_time desc 
limit 999999999
        )  t  group by room_id 

resultMap

适用场景:类似一个项目多个合同
在这里插入图片描述

<resultMap id="projectManegeMap" type="com.iflytek.project.base.vo.resp.ProjMoneyManageVo">
    <result column="PROJECT_ID" property="projectId"/>
    <result column="PROJECT_NAME" property="projectName"/>
    <result column="PROJECT_CODE" property="projectCode"/>
    <result column="PROJECT_STAGE" property="projectStage"/>
    <result column="ESTIMATED_INVESTMENT_AMOUNT" property="estimatedInvestmentAmount"/>
    <!--ProjMoneyManageVo有属性 List<ContractInfo> contractList-->
    <collection property="contractList" javaType="list" ofType="com.iflytek.project.base.vo.resp.ContractInfo">
        <result column="CONTRACT_ID" property="contractId"/>
        <result column="CONTRACT_MONEY" property="contractMoney"/>
        <result column="SIGN_DATE" property="signDate"/>
        <result column="PAYMENTS_NUM" property="paymentsNum"/>
        <result column="CURRENT_NUM" property="currentNum"/>
        <result column="PAYED_MONEY" property="payedMoney"/>
        <result column="TOPAY_MONEY" property="topayMoney"/>
        <result column="PAYMENTS_PER" property="paymentsPer"/>
        <result column="PAYED_TOPAY" property="payedTopay"/>
        <result column="PAYED_PER" property="payedPer"/>
    </collection>
</resultMap>

in 占位符

mapper接口ids传数组String[]

List<TTopicFileStorage> selectFileList(@Param("ids") String[] ids, @Param("stage") String stage);

mapper.xml

and d.id IN
<foreach collection="ids" index="index" item="item" open="(" separator="," close=")">
    #{item}
</foreach>

或者
mapper接口idList传列表List

List<ProjectFileResp> getProjectFileByIds(@Param("idList") List<String> idList);

mapper.xml

<if test='idList != null and idList.size() >0'
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一个不回家的男人

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值