在MyBatis Plus 2.2中,可以使用selectOne方法获取最大值。下面是一个示例代码:

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.beans.factory.annotation.Autowired;

public class MyService {

    @Autowired
    private BaseMapper<T> mapper;

    public Integer getMaxValue() {
        QueryWrapper<T> queryWrapper = Wrappers.query();
        queryWrapper.select("MAX(column_name) as max_value");
        T result = mapper.selectOne(queryWrapper);
        return result.getMaxValue();
    }
}

在上面的代码中,首先创建了一个QueryWrapper对象,然后使用select方法指定要查询的字段,并使用MAX函数获取最大值。最后使用selectOne方法执行查询,并将结果转换为实体类对象

mybatisplus 22 selectOne 获取max值

原文地址: http://www.cveoy.top/t/topic/h1zu 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录