Mybatis -> 分页查询(limit),使用map设置limit

xml

  List<Mybatis> selectlist(Map<String,Object> map);
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.dao.ImpMapper">
    <resultMap id="mybatismap" type="mybatis">
        <result column="psw" property="password"/>
    </resultMap>
    <select id="selectlist" resultMap="mybatismap">
        select * from mybatis_1 limit #{index},#{led}
    </select>
</mapper>

测试:使用map设置limit

  @Test
  public void test() {
    SqlSession session = Mybatisconfig.getSqlSession();
    ImpMapper mapper = session.getMapper(ImpMapper.class);
    HashMap<String, Object> map = new HashMap<>();
    map.put("index",1);
    map.put("led",2);
    List<Mybatis> selectlist = mapper.selectlist(map);
    for (Object o : selectlist) {
      System.out.println(o);
    }
    session.close();
  }
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在 Spring Boot 集成最新版的 Mybatis-Plus 分页查询,需要进行以下步骤: 1. 引入 Mybatis-Plus 的分页插件 ```xml <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.4.3.1</version> </dependency> ``` 2. 在配置文件进行配置 ```yaml mybatis-plus: mapper-locations: classpath*:mapper/**/*.xml configuration: map-underscore-to-camel-case: true log-impl: org.apache.ibatis.logging.stdout.StdOutImpl global-config: db-config: id-type: auto field-strategy: not_null table-prefix: t_ page-params: limit: 10 max-limit: 100 ``` 其,`mapper-locations` 配置了 Mapper 文件的地址,`configuration` 配置了 Mybatis 的全局配置,`global-config` 配置了 Mybatis-Plus 的全局配置,`page-params` 配置了分页参数的默认值。 3. 在 Mapper 接口添加分页方法 ```java public interface UserMapper extends BaseMapper<User> { List<User> selectUserPage(Page<User> page, @Param("name") String name); } ``` 4. 在 Service 层调用分页方法进行查询 ```java @Service public class UserServiceImpl implements UserService { @Autowired private UserMapper userMapper; @Override public Page<User> selectUserPage(int pageNum, int pageSize, String name) { Page<User> page = new Page<>(pageNum, pageSize); userMapper.selectUserPage(page, name); return page; } } ``` 其,`pageNum` 为当前页码,`pageSize` 为每页显示的数据量,`name` 为查询条件。分页查询将返回一个 `Page` 对象,其包含了当前页码、每页显示的数据量、总数据量等信息,以及查询到的数据列表。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值