com.baomidou
mybatis-plus-boot-starter
2.3.3
@RequestMapping(value = "/staffFuzzyQuery", method = RequestMethod.GET)
@ApiOperation(value = "员工模糊查询")
public Object staffFuzzyQuery(String accessToken, @ModelAttribute Staff staff, @ModelAttribute PageVo pageVo) {
Page staffList = staffService.staffFuzzyQuery(staff, pageVo);
return staffList;
}
/**
* @Description: 员工模糊查询
* @auther: Hanweihu
* @date: 16:52 2019/3/26
* @param: [staff, pageNo, pageSize]
* @return: com.baomidou.mybatisplus.plugins.Page
*/
public Page staffFuzzyQuery(Staff staff, PageVo pageVo) {
Wrapper entity = new EntityWrapper<>(staff);
Page page = new Page<>(pageVo.getPageNumber(), pageVo.getPageSize());
List staffList = staffMapper.fuzzyQuery(page, staff);
return page.setRecords(staffList);
}
Wrapper类,Page类都导入mybatisplus包中的。Staff是你的实体类(即要查的表对应的实体类)。staffMapper是你的mapper接口。PageVo是一个我自定义的封装类,下面会贴出。
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
@Data
public class PageVo implements Serializable{
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "页号")
private int pageNumber;
@ApiModelProperty(value = "页面大小")
private int pageSize;
@ApiModelProperty(value = "排序字段")
private String sort;
@ApiModelProperty(value = "排序方式 asc/desc")
private String order;
}
@Data注解是lombok的,需安装插件,可百度,不再赘述
import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.baomidou.mybatisplus.plugins.Page;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
public interface StaffMapper extends BaseMapper {
// 模糊查询
List fuzzyQuery(Page page, @Param("staff") Staff staff);
}
xml中的if标签可根据你的业务情况编写。test判断时原来写法,是双引号,但执行判断时会报错,把test的双引号变为单引号,即可解决报错。
看上面controller,我有两个参数对象,staff实体类,我只给userName传了“明”,pagevo封装类只传了第几页,一页几条。