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
相关推荐
史蒂芬_丁20 分钟前
Qt, C++数据类型扩展问题
数据库·c++·qt
nbwenren27 分钟前
node.js内置模块之---crypto 模块
java
lpfasd12327 分钟前
MariaDB Docker容器权限配置问题分析与解决方案
数据库·docker·mariadb
我命由我123451 小时前
React - 类组件 setState 的 2 种写法、LazyLoad、useState
前端·javascript·react.js·html·ecmascript·html5·js
weyyhdke1 小时前
springboot和springframework版本依赖关系
java·spring boot·后端
自由生长20242 小时前
IndexedDB的观察
前端
chools2 小时前
Java后端拥抱AI开发之个人学习路线 - - Spring AI【第一期】
java·人工智能·学习·spring·ai
Yvonne爱编码2 小时前
数据库---Day2 数据库操作
数据库
IT_陈寒2 小时前
Vite热更新坑了我三天,原来配置要这么写
前端·人工智能·后端
斯班奇的好朋友阿法法2 小时前
离线ollama导入Qwen3.5-9B.Q8_0.gguf模型
开发语言·前端·javascript