JAVA全系列 教程
3762个小节阅读:7095.1k
目录
C语言快速入门
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
后台用户也称为管理员,每个管理员能在后台进行的操作不同,所以不同的管理员有不同的权限。在项目中,权限表的设计为用户—角色
多对多,角色—权限
多对多,既一个用户有多个角色,一个角色有多个权限。所以后台首先要拥有用户管理、角色管理、权限管理的功能。
我们首先编写用户管理中的查询用户功能。
编写AdminMapper
xxxxxxxxxx
public interface AdminMapper extends BaseMapper<Admin> {
}
编写AdminService
xxxxxxxxxx
@Service
public class AdminService {
@Autowired
private AdminMapper adminMapper;
// 分页查询管理员
public Page<Admin> findPage(int page, int size){
Page selectPage = adminMapper.selectPage(new Page(page, size), null);
return selectPage;
}
}
在启动类扫描mapper
接口,注册mybatis-plus
分页插件
xxxxxxxxxx
@SpringBootApplication
@MapperScan("com.itbaizhan.travel.mapper")
public class TravelApplication {
public static void main(String[] args) {
SpringApplication.run(TravelApplication.class, args);
}
// 注册分页插件
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor(){
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
return interceptor;
}
}
编写AdminController
xxxxxxxxxx
@Controller
@RequestMapping("/backstage/admin")
public class AdminController {
@Autowired
private AdminService adminService;
@RequestMapping("/all")
public ModelAndView all(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int size) {
Page<Admin> adminPage = adminService.findPage(page, size);
ModelAndView modelAndView = new ModelAndView();
modelAndView.addObject("adminPage", adminPage);
modelAndView.setViewName("/backstage/admin_all");
return modelAndView;
}
}