MP、MybatisPlus、联表查询、自定义sql、Constants.WRAPPER、ew (二)

描述: 给定一个id列表,更新对应列表中动物的年龄,使得年龄都较少一岁。

要求:使用条件构造器构造条件。

mapper:

java 复制代码
   void updateAnimalAge(@Param(Constants.WRAPPER) Wrapper<Animal> wrapper, @Param("age") int reducedAge);

xml:

sql 复制代码
    <update id="updateAnimalAge">
        update `animal` set `age` = `age` - #{age}
        <where>
           ${ew.sqlSegment}
        </where>
    </update>

service:

java 复制代码
    @org.junit.Test
    public void test() {
        ArrayList<String> strings = Lists.newArrayList();
        strings.add("1775e2db7fb5e0d9b8e98d4137f58b91");
        strings.add("23d210703b33bd67b901e147f874a831");

        int reducedAge = 1;

        LambdaQueryWrapper<Animal> wrapper = new QueryWrapper<Animal>().lambda();

        wrapper.in(Animal::getId,strings);


        this.animalMapper.updateAnimalAge(wrapper,reducedAge);
//
//        if (successful.size() > 0) {
//            System.out.println("success!!");
//        } else {
//            System.out.println("failed!!");
//        }
        
    }

sql:

sql 复制代码
JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@3c50ad4b] will not be managed by Spring
==>  Preparing: update `animal` set `age` = `age` - ? WHERE (id IN (?,?)) 
==> Parameters: 1(Integer), 1775e2db7fb5e0d9b8e98d4137f58b91(String), 23d210703b33bd67b901e147f874a831(String)
<==    Updates: 2
相关推荐
xqqxqxxq28 分钟前
背单词软件技术笔记(V2.0扩展版)
java·笔记·python
GISer_Jing35 分钟前
AI营销增长:4大核心能力+前端落地指南
前端·javascript·人工智能
消失的旧时光-194337 分钟前
深入理解 Java 线程池(二):ThreadPoolExecutor 执行流程 + 运行状态 + ctl 原理全解析
java·开发语言
哈哈老师啊41 分钟前
Springboot学生综合测评系统hxtne(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面。
java·数据库·spring boot
4311媒体网1 小时前
帝国cms调用文章内容 二开基本操作
java·开发语言·php
小小8程序员1 小时前
Redis-10
数据库·redis·缓存
liuzhilongDBA1 小时前
从collation mismatch异常到其原理
数据库·version·glibc·postgres·collation
梁萌1 小时前
MySQL数据库分库分表介绍
数据库·mysql·shardingsphere·分库分表
明远湖之鱼1 小时前
一种基于 Service Worker 的渐进式渲染方案的基本原理
前端