Mybatis-Plus官網測試用例
@Configuration
@MapperScan("com.baomidou.cloud.service.*.mapper*")
public class MybatisPlusConfig {@Beanpublic PaginationInterceptor
paginationInterceptor() {PaginationInterceptor paginationInterceptor
= new PaginationInterceptor();paginationInterceptor
.setCountSqlParser(new JsqlParserCountOptimize(true));return paginationInterceptor
;}
}
2. 調整修改后的代碼 MyBatisPlusConfig.java
@EnableTransactionManagement
@MapperScan("com.macro.cloud.mapper")
@Configuration
public class MyBatisPlusConfig {@Beanpublic MybatisPlusInterceptor
mybatisPlusInterceptor(){MybatisPlusInterceptor interceptor
= new MybatisPlusInterceptor();PaginationInnerInterceptor innerInterceptor
=new PaginationInnerInterceptor();innerInterceptor
.setDbType(DbType
.MYSQL
);innerInterceptor
.setOverflow(true);interceptor
.addInnerInterceptor(new OptimisticLockerInnerInterceptor());interceptor
.addInnerInterceptor(innerInterceptor
);return interceptor
;}@Beanpublic ConfigurationCustomizer
configurationCustomizer(){return mybatisConfiguration
-> mybatisConfiguration
.setUseGeneratedShortKey(false);}
}
實體類 User.java
@Data
@AllArgsConstructor
@NoArgsConstructor
public class User {@TableId(type
= IdType
.AUTO
)private Long id
;private String name
;private Integer age
;private String email
;@TableField(fill
= FieldFill
.INSERT
)private Date createTime
;@TableField(fill
= FieldFill
.INSERT_UPDATE
)private Date updateTime
;@Versionprivate Integer version
;@TableLogic(value
= "0",delval
= "1")@TableField(fill
=FieldFill
.INSERT
)private Integer deleteFlag
;
}
3.映射類:UserMapper.java
public interface UserMapper extends BaseMapper<User>{
}
UserController.java
RequestMapping("user")
@Controller
@Api(tags
= "用戶管理")
public class UserController {@AutowiredUserMapper userMapper
;@ApiOperation("分頁查詢")@ResponseBody@GetMapping("/getUsers")public Page
<User> getUsers(@RequestParam int current
,@RequestParam int size
){Page
<User> page
=new Page<>(current
,size
);Page
<User> userPage
= userMapper
.selectPage(page
, null
);return userPage
;}}
測試結果
{
“records”: [
{
“id”: 1,
“name”: “Jone”,
“age”: 18,
“email”: “test1@baomidou.com”,
“createTime”: “2020-12-29T23:50:05.000+00:00”,
“updateTime”: “2020-12-29T23:50:05.000+00:00”,
“version”: 0,
“deleteFlag”: 0
},
{
“id”: 2,
“name”: “Jack”,
“age”: 20,
“email”: “test2@baomidou.com”,
“createTime”: “2020-12-29T23:50:05.000+00:00”,
“updateTime”: “2020-12-29T23:50:05.000+00:00”,
“version”: 0,
“deleteFlag”: 0
},
{
“id”: 3,
“name”: “Tom”,
“age”: 28,
“email”: “test3@baomidou.com”,
“createTime”: “2020-12-29T23:50:05.000+00:00”,
“updateTime”: “2020-12-29T23:50:05.000+00:00”,
“version”: 0,
“deleteFlag”: 0
}
],
“total”: 9,
“size”: 3,
“current”: 1,
“orders”: [],
“optimizeCountSql”: true,
“hitCount”: false,
“countId”: null,
“maxLimit”: null,
“searchCount”: true,
“pages”: 3
}
總結
以上是生活随笔為你收集整理的SpringBoot整合Mybatis-Plus分页失效,Mybatis-Plus 3.4.1分页插件失效踩坑的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。