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
相关推荐
Async Cipher几秒前
TypeScript 的用法
前端·typescript
web打印社区1 分钟前
vue页面打印:printjs实现与进阶方案推荐
前端·javascript·vue.js·electron·html
diediedei3 分钟前
Python字典与集合:高效数据管理的艺术
jvm·数据库·python
气可鼓不可泄3 分钟前
将dmpython 封装在容器镜像里
数据库·python
m0_561359676 分钟前
超越Python:下一步该学什么编程语言?
jvm·数据库·python
mango_mangojuice9 分钟前
Linux学习笔记 1.19
linux·服务器·数据库·笔记·学习
We་ct11 分钟前
LeetCode 30. 串联所有单词的子串:从暴力到高效,滑动窗口优化详解
前端·算法·leetcode·typescript
小马爱打代码13 分钟前
Spring AI 实战:Agent 基础搭建与核心能力解析
java·人工智能·spring
csdn2015_14 分钟前
springboot task
java·spring boot·后端
czlczl2002092524 分钟前
Spring Boot :如何高性能地在 Filter 中获取响应体(Response Body)
java·spring boot·后端