mybatis update语句成功后,返回指定的字段
·
mybatis update语句成功后,返回指定的字段
mapper---------------------------------------将 keyColumn 属性的 num 映射到 YourBean 中的num属性
<update id="upt">
<selectKey resultType="java.lang.Integer" keyColumn="num" keyProperty="num" order="AFTER">
SELECT (SELECT num FROM your_table WHERE id = #{id}) goodsNum from DUAL
</selectKey>
UPDATE your_table SET num = num + #{num} WHERE id = #{id}
</update>
dao------------------------------------------传参要用 YourBean 不是(@Param("num") Integer num)
Integer upt(YourBean yourBean);
service--------------------------------------
@Transactional(rollbackFor = Exception.class)
public void uptSome(YourBean yourBean) {
yourMapper.upt(yourBean);
//**
if (!ObjectUtils.isEmpty(yourBean.getNum()) && yourBean.getNum() <= 0) {
throw new RuntimeException("xxxx数量不足");
}
}
bean-----------------------------------------
@Setter
@Getter
public class YourBean implements Serializable {
private static final long serialVersionUID = 1L;
@NotNull(message = "id为空", groups = UpdateGroup.class)
private Long id;
@NotNull(message = "数量为空", groups = {AddGroup.class, UpdateGroup.class})
private Integer num;
}
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)