Introduce dependencies
<dependency> <groupId></groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.1.2</version> </dependency>
User Entity Class
@ApiModel(description = "User Entity") public class User { /** * serialVersionUID */ @ApiModelProperty(value = "Primary Key") private Integer id; @ApiModelProperty(value = "username") private String username; @ApiModelProperty(value = "Real Nickname") private String realname; @ApiModelProperty(value = "gender") private String sex; @ApiModelProperty(value = "Work number") private String jobNum; @ApiModelProperty(value = "Status 0 Enable 1 Disable") private Integer isDel; @ApiModelProperty(value = "department") private Integer departmentId; private String departmentName; @ApiModelProperty(value = "password") private String password;// User password @ApiModelProperty(value = "cell phone") private String mobile;// cell phone private Integer createUser; private Integer editUser; @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") private Date gmtCreate; @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") private Date gmtUpdate; }
controller
@PostMapping("/likeUser") @ApiOperation("Fuzzy Query-Pagination") public ApiResponse<User> getLikeUser(@RequestBody Map<String, Object> queryMap) { try { return ((queryMap)); } catch (Exception e) { ("Fuzzy query - paging failed", e); return ("Fuzzy query - paging failed"); } }
service
IPage<User> getLikeUser(Map<String, Object> queryMap);
impl
Impl General Operation
@Override public IPage<User> getLikeUser(Map<String, Object> params) { long size = (((("limit")), "10")); long current = (((("page")), "1")); QueryWrapper<User> q = new QueryWrapper<>(); Object username= ("username"); Object realname= ("realname"); Object sex= ("sex"); Object jobNum= ("jobNum"); Object mobile= ("mobile"); // Sort Object sort = ("sort"); if (null != username && ().trim().length() > 0) { ().like(User::getUsername, username); } if (null != realname) { ().like(User::getRealname, realname); } if (null != jobNum) { ().eq(User::getJobNum, jobNum); } if (null != startTime && null != endTime) { // GE means GREATER THAN OR EQUAL is greater than or equal to // LE is LESS THAN OR EQUAL is less than or equal to ().ge(User::getCreateTime, startTime); ().le(User::getCreateTime, endTime); } if (("ASC")) { // Lift ().orderByAsc(User::getCreateTime); } else if (("DESC")) { ().orderByDesc(User::getCreateTime); } IPage<USer> page = ( new Page<>(current, size), q); return page; }
impl custom parameters rewrite Sql
- Idea: Normal use
Page<TcmcAlarm> page = new Page<>(current, size);
Pagination plugin - -return
IPage<User> iPage = (page,username);
When passing parameters, enter custom parameters and page - SQL access normally
@Override public IPage<TcmcAlarm> selectUSer(Map<String, Object> params) { long size = (((("limit")), "10")); long current = (((("page")), "1")); String id= ("devId").toString(); String username= ("username").toString(); // Use of pagination Page<User> page = new Page<>(current, size); // Custom SQL IPage<User> iPage = (page, username); return iPage; } // mapper IPage<TcmcAlarm> selectUser(Page page, @Param("username") String username ; // sql <select resultType=""> select * from user where username LIKE CONCAT('%', #{username}, '%') </select>
Write Sql directly in impl and pass it into xml as a parameter
// Complex splicing This is the simplest way to write it, directly splicing "," "#" ","_" "-" and so onString UNION = "UNION ALL "; // TB_SQL sql snippetString join = (UNION).join(TB_SQL); Page<User> page = new Page<>(current, size); IPage<User> iPage = (page, join); // mapper IPage<User> selectUser(Page page, @Param("data") String data); // xml <select resultType=""> ${data} </select>
This is the article about Java IPage paging and custom SQL. For more related Java IPage paging content, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!