欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

mybatis-plus使用注解多条件查询,整合bootstrap-table

程序员文章站 2024-03-05 16:44:25
...

mybatis-plus使用注解多条件查询,整合bootstrap-table

POM.XML

		<dependency>
			<groupId>com.baomidou</groupId>
			<artifactId>mybatis-plus-boot-starter</artifactId>
			<version>3.2.0</version>
		</dependency>

Mapper层

// 查询所有用户和权限

@Select("<script>SELECT u.username,u.staffname,u.staffage,u.staffsex,u.homeaddress,u.did,u.email,u.photo,u.phone,r.rname FROM b_user u\r\n"
		+ "INNER JOIN b_user_role ur ON u.userid = ur.uid\r\n"
		+ "INNER JOIN b_role r ON ur.rid = r.roleid where 1=1 <when test='generaid==null or generaid==\"\"'>and u.did=2</when> </script>")
List<UserRoleCostom> selectUserRole(GeneralDto dto);

分页多条件查询工具类

public class PageBean<T> implements Serializable{
	private Long total;//满足条件的总记录数
	private List<T> rows;//所请求的当前页的数据集合
	public Long getTotal() {
		return total;
	}
	public void setTotal(Long total) {
		this.total = total;
	}
	public List<T> getRows() {
		return rows;
	}
	public void setRows(List<T> rows) {
		this.rows = rows;
	}
	
}
public class PageVoUtils {
	public static <T> PageBean<T> convertTopageVo(PageInfo<T> pageInfo) {
		PageBean<T> pagevo = new PageBean<T>();
		pagevo.setTotal(pageInfo.getTotal());
		pagevo.setRows(pageInfo.getList());
		return pagevo;
	}
}

Service层

//查询全部用户权限
	public PageInfo<UserRoleCostom> selectUserRole(GeneralDto dto,int pageNumber,int pageSize){
		PageHelper.startPage(pageNumber, pageSize);
		List<UserRoleCostom> selectUserPermission = this.userMapper.selectUserRole(dto);
		PageInfo<UserRoleCostom> pageInfo=new PageInfo<>(selectUserPermission);
		return pageInfo;
	}

Conreoller层

@RequestMapping("/userRolePermission")
public @ResponseBody PageBean<UserRoleCostom> selectUserRole(GeneralDto dto,
		@RequestParam(defaultValue = "1", name = "pageNumber") int pageNumber,
		@RequestParam(defaultValue = "10", name = "pageSize") int pageSize) {
	PageInfo<UserRoleCostom> pageInfo = this.userService.selectUserRole(dto, pageNumber,pageSize );
	PageBean<UserRoleCostom> pageBean = PageVoUtils.convertTopageVo(pageInfo);
	return pageBean;
}