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

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

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

 mapper:

   void updateAnimalAge(@Param(Constants.WRAPPER) Wrapper wrapper, @Param("age") int reducedAge);

xml:

    
        update `animal` set `age` = `age` - #{age}
        
           ${ew.sqlSegment}
        
    

service:

    @org.junit.Test
    public void test() {
        ArrayList strings = Lists.newArrayList();
        strings.add("1775e2db7fb5e0d9b8e98d4137f58b91");
        strings.add("23d210703b33bd67b901e147f874a831");

        int reducedAge = 1;

        LambdaQueryWrapper wrapper = new QueryWrapper().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:

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

你可能感兴趣的:(java,前端,数据库)