MybatisPlusConfig.java
@EnableTransactionManagement
@Configuration
@MapperScan("com.hwx.api.mapper")
public class MybatisPlusConfig {
/*
* 分页器 使用分页接口必须有这个
* */
@Bean
public PaginationInterceptor paginationInterceptor(){
PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
// 攻击 SQL 阻断解析器、加入解析链
List sqlParserList = new ArrayList<>();
sqlParserList.add(new BlockAttackSqlParser());
paginationInterceptor.setSqlParserList(sqlParserList);
return paginationInterceptor;
}
/*
* 逻辑删除必须有这个
* 并且实体类字段上加上@TableLogic注解
* @TableLogic
* private Integer deleted;
* */
@Bean
public ISqlInjector sqlInjector() {
return new LogicSqlInjector();
}
}
PaginationInterceptor 分页拦截器 一定要加,不然分页无效
Page page =new Page<>(pageIndex,pageSize);
iStoreUserChildrenService.page(page,queryWrapper)
就可以返回分页数据
@GetMapping("findByAttributes")
@ApiOperation(value = "按属性分页获取小孩列表")
@ApiImplicitParams({@ApiImplicitParam(paramType = "query", dataType = "String", name = "unionId", value = "unionId"),
@ApiImplicitParam(paramType = "query", dataType = "String", name = "name", value = "姓名"),
@ApiImplicitParam(paramType = "query", dataType = "Long", name = "age", value = "年龄"),
@ApiImplicitParam(paramType = "query", dataType = "String", name = "order", value = "排序方式(asc、desc)"),
@ApiImplicitParam(paramType = "query", dataType = "String", name = "orderProp", value = "排序字段"),
@ApiImplicitParam(paramType = "query", dataType = "String", name = "pageIndex", value = "当前页码"),
@ApiImplicitParam(paramType = "query", dataType = "String", name = "pageSize", value = "页码大小")})
public ReturnValue> findByAttributes(String unionId,
Integer age,
String name,
@RequestParam(defaultValue = "desc")String order,
@RequestParam(defaultValue = "unionId")String orderProp,
@RequestParam(defaultValue = "1")Long pageIndex,
@RequestParam(defaultValue = "10") Long pageSize){
QueryWrapper queryWrapper=new QueryWrapper<>();
if(unionId != null) {
queryWrapper.eq("unionId", unionId);
}
if(age != null){
queryWrapper.eq("age",age);
}
if(name != null){
queryWrapper.like("name",name);
}
if(order != "desc"){
queryWrapper.orderByAsc(orderProp);
}else{
queryWrapper.orderByDesc(orderProp);
}
Page page =new Page<>(pageIndex,pageSize);
return new ReturnValue>(iStoreUserChildrenService.page(page,queryWrapper));
}
application.yml
mybatis-plus:
global-config:
db-config:
logic-delete-value: 1 # 逻辑已删除值(默认为 1)
logic-not-delete-value: 0 # 逻辑未删除值(默认为 0)
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
@ApiModel(value="KnowledgeArticle对象", description="knowledge_article information")
public class KnowledgeArticle extends BaseEntity {
private static final long serialVersionUID = 1L;
@TableId(value = "articleId", type = IdType.AUTO)
private Long articleId;
private String guid;
@TableField("storeId")
private Long storeId;
@TableField("typeId")
private Long typeId;
private String title;
private String author;
private String summary;
private String content;
@TableField("publushTime")
private LocalDateTime publushTime;
@TableField("createTime")
private LocalDateTime createTime;
@TableField("showAll")
private String showAll;
@TableField("showStore")
private String showStore;
private String reserver1;
private String reserver2;
private String reserver3;
@TableLogic
private Integer deleted;
@TableField(exist = false)
private String typeName;
}
@DeleteMapping("delete")
@ApiOperation(value = "根据id删除文章类型")
@ApiImplicitParams({@ApiImplicitParam( dataType = "String", name = "id", value = "id", required = true)})
public ReturnValue removeById(@RequestParam String id){
iKnowledgeArticleService.removeById(id);
return new ReturnValue(ErrorCode.ERROR_SUCCESS_DELETE);
}