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
相关推荐
爬山算法2 小时前
Redis(158)Redis的主从同步问题如何解决?
数据库·redis·缓存
小马爱打代码4 小时前
Spring Boot:模块化实战 - 保持清晰架构
java·spring boot·架构
遇到困难睡大觉哈哈4 小时前
Harmony os 静态卡片(ArkTS + FormLink)详细介绍
前端·microsoft·harmonyos·鸿蒙
小坏讲微服务4 小时前
SpringBoot4.0整合knife4j 在线文档完整使用
java·spring cloud·在线文档·knife4j·文档·接口文档·swagger-ui
8***Z894 小时前
springboot 异步操作
java·spring boot·mybatis
i***13244 小时前
Spring BOOT 启动参数
java·spring boot·后端
用户47949283569154 小时前
Bun 卖身 Anthropic!尤雨溪神吐槽:OpenAI 你需要工具链吗?
前端·openai·bun
坚持不懈的大白4 小时前
后端:SpringMVC
java
IT_Octopus4 小时前
(旧)Spring Securit 实现JWT token认证(多平台登录&部分鉴权)
java·后端·spring
kk哥88994 小时前
Spring详解
java·后端·spring