源码获取:博客首页 "资源" 里下载!
本系统功能包括:springboot+springmvc+mybatis的流浪 猫救助系统,后台分为普通用户可管理员用,包括注册, 登录,流浪猫发布,评论,分享,后台管理,用户管理, 热门文章赞助等等功能,非常不错,可以以参考二次开发 学习使用。
环境配置: Jdk1.8 + Tomcat8.5 + Mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)
项目技术: JSP +SpringBoot + MyBatis + Json+ Css + JavaScript + JQuery + Ajax + PageHelper+ Maven等等。
/**
* 管理员权限控制类
*/
@Controller("Admin")
@RequestMapping("/admin")
public class Adminontroller {
@Autowired
private PageService pageService;
@Autowired
private RoleService roleService;
@Autowired
private PageRoleService pageRoleService;
@Autowired
private UserRoleService userRoleService;
@Autowired
private UserService userService;
private final Logger logger = LoggerFactory.getLogger(Adminontroller.class);
/**
* Method name: page
* Description: 跳转到页面设置页面
*
* @param model
* @return String
*/
@RequestMapping("/page")
public String page(Model model) {
List pageList = pageService.getAllPage();
model.addAttribute("pageList", pageList);
return "sa/page";
}
/**
* Method name: role
* Description: 跳转到角色设置页面
*
* @param model
* @return String
*/
@RequestMapping("/role")
public String role(Model model) {
return "sa/role";
}
/**
* Method name: getAllRole
* Description: 获取所有权限
*
* @return List
*/
@RequestMapping("/getAllRole")
@ResponseBody
public List getAllRole() {
return roleService.getAllRole();
}
/**
* Method name: getAllPage
* Description: 获取所有页面
*
* @return List
*/
@RequestMapping("/getAllPage")
@ResponseBody
public List getAllPage() {
return pageService.getAllPage();
}
/**
* Method name: getPageByRole
* Description: 获取某个角色的权限页面
*/
@RequestMapping("/getPageByRole")
@ResponseBody
public Object getPageByRole(Integer roleId) {
return pageService.getAllPageByRoleId(roleId);
}
/**
* Method name: updatePageById
* Description: 根据页面id更新页面
*
* @param page
* @return ResultMap
*/
@RequestMapping("/updatePageById")
@ResponseBody
public ResultMap updatePageById(Page page) {
return pageService.updatePageById(page);
}
/**
* Method name: addPage
* Description: 添加页面
*
* @param page
* @return Page
*/
@RequestMapping("/addPage")
@ResponseBody
public Page addPage(Page page) {
return pageService.addPage(page);
}
/**
* Method name: delPageById
* Description: 根据页面id删除页面
*
* @param id
* @return ResultMap
*/
@RequestMapping("/delPageById")
@ResponseBody
public ResultMap delPageById(Integer id) {
if (null == id) {
return new ResultMap().fail().message("参数错误");
}
return pageService.delPageById(id);
}
/**
* Method name: addRole
* Description: 增加角色
*
* @param name
* @return String
*/
@RequestMapping("/addRole")
@ResponseBody
public String addRole(String name) {
return roleService.addRole(name);
}
/**
* Method name: delManageRole
* Description: 根据角色id删除角色
*
* @param id
* @return String
*/
@RequestMapping("/delRole")
@ResponseBody
public String delRole(int id) {
// 删除角色
boolean flag1 = roleService.delRoleById(id);
// 删除角色_权限表
boolean flag2 = pageRoleService.delPageRoleByRoleId(id);
// 删除某个角色的所有用户
boolean flag3 = userRoleService.delUserRoleByRoleId(id);
if (flag1 && flag2 && flag3) {
return "SUCCESS";
}
return "ERROR";
}
/**
* Method name: updateRole
* Description: 根据权限id修改权限信息
*
* @param id
* @param name
* @return String
*/
@RequestMapping("/updateRole")
@ResponseBody
public String updateRole(Integer id, String name) {
int n = roleService.updateRoleById(id, name);
if (n != 0) {
return "SUCCESS";
}
return "ERROR";
}
/**
* Method name: addPageRoleByRoleId
* Description: 增加某个角色的权限页面
*
* @param roleId
* @param pageIds
* @return String
*/
@RequestMapping("/addPageRoleByRoleId")
@ResponseBody
public String addPageRoleByRoleId(Integer roleId, Integer[] pageIds) {
if (null == roleId) {
return "ERROR";
}
// 先删除老的权限
boolean flag1 = pageRoleService.delPageRoleByRoleId(roleId);
boolean flag2 = pageRoleService.addPageRoles(roleId, pageIds);
if (flag1 && flag2) {
return "SUCCESS";
}
return "ERROR";
}
/**
* Method name: getAllUserByMap
* Description: 根据角色查询下面所有的人员/非角色下所有人员
*/
@RequestMapping("/getAllUserByRoleId")
@ResponseBody
public Object getAllUserByRoleId(Integer roleId, String roleNot, Integer page, Integer limit) {
if (null == roleNot) {
return userService.getAllUserByRoleId(roleId, page, limit);
}
return userService.getAllUserByNotRoleId(roleId, page, limit);
}
/**
* Method name: delUserRoleByUserIdAndRoleId
* Description: 根据用户id权限id删除用户权限表
*
* @param userId
* @param roleId
* @return ResultMap
*/
@RequestMapping("/delUserRoleByUserIdAndRoleId")
@ResponseBody
public ResultMap delUserRoleByUserIdAndRoleId(String userId, Integer roleId) {
return userRoleService.delUserRoleByUserIdAndRoleId(userId, roleId);
}
/**
* Method name: selectUserRole
* Description: 跳转到选择用户角色页面
*
* @return String
*/
@RequestMapping("/selectUserRole")
public String selectUserRole() {
return "sa/selectUserRole";
}
/**
* Method name: addUserRole
* Description: 增加用户的角色
*
* @param roleId
* @param userIds
* @return String
*/
@RequestMapping("/addUserRole")
@ResponseBody
public String addUserRole(Integer roleId, String[] userIds) {
return userRoleService.addUserRole(roleId, userIds);
}
/**
* Method name: userAddPage
* Description: 用户添加页面
*
* @return String
*/
@RequestMapping(value = "/userAddPage")
public String userAddPage() {
return "sa/userAdd";
}
/**
* Method name: userPage
* Description: 用户管理页面
*
* @return String
*/
@RequestMapping(value = "/userPage")
public String userPage() {
return "sa/userList";
}
/**
* Method name: getAllUserByLimit
* Description: 根据条件获取所有用户
*
* @param userParameter
* @return Object
*/
@RequestMapping("/getAllUserByLimit")
@ResponseBody
public Object getAllUserByLimit(UserParameter userParameter) {
return userService.getAllUserByLimit(userParameter);
}
/**
* Method name: getAllDelUserByLimit
* Description: 获取所有删除用户
*
* @param userParameter
* @return Object
*/
@RequestMapping("/getAllDelUserByLimit")
@ResponseBody
public Object getAllDelUserByLimit(UserParameter userParameter) {
return userService.getAllDelUserByLimit(userParameter);
}
/**
* Method name: delUser
* Description: 批量删除用户
*
* @param ids
* @return String
*/
@RequestMapping(value = "delUser")
@ResponseBody
@Transactional
public String delUser(Long[] ids) {
Subject subject = SecurityUtils.getSubject();
User user = (User) subject.getPrincipal();
try {
for (Long id : ids) {
if (id.equals(user.getId())) {
return "DontOP";
}
userService.delUserById(id);
}
return "SUCCESS";
} catch (Exception e) {
logger.error("根据用户id更新用户异常", e);
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return "ERROR";
}
}
/**
* Method name: addUserPage
* Description: 增加用户界面
*
* @return String
*/
@RequestMapping(value = "/addUserPage")
public String addUserPage(Long userId, Model model) {
model.addAttribute("manageUser", userId);
if (null != userId) {
User user = userService.selectByPrimaryKey(userId);
model.addAttribute("manageUser", user);
}
return "sa/userAdd";
}
/**
* Method name: checkUserId
* Description: 检测用户账号是否存在
*
* @param userId
* @return User
*/
@ResponseBody
@RequestMapping("/checkUserId")
public User checkUserId(Long userId) {
return userService.selectByPrimaryKey(userId);
}
/**
* Method name: addUser
* Description: 用户添加
*
* @param user
* @return String
*/
@ResponseBody
@RequestMapping("/addUser")
public String addUser(User user) {
try {
user.setPassword(MD5.md5(user.getPassword()));
user.setCreateTime(new Date());
userService.addUser(user);
User u = userService.getUserByPhoneAndName(user.getPhone(), user.getName());
String[] ids = new String[1];
ids[0] = u.getId()+"";
// 医生角色
userRoleService.addUserRole(3, ids);
return "SUCCESS";
} catch (Exception e) {
return "ERR";
}
}
/**
* Method name: updateUser
* Description: 更新用户
*
* @param user
* @return String
*/
@ResponseBody
@RequestMapping("/updateUser")
public String updateUser(User user, Long oldId) {
return userService.updateUser(oldId, user);
}
/**
* Method name: delUserPage
* Description: 已删除用户列表
*
* @return String
*/
@RequestMapping("/delUserPage")
public String delUserPage() {
return "sa/userDelPage";
}
}
/**
* 登录控制类
*/
@Controller("OpenLogin")
@RequestMapping()
public class LoginController {
@Autowired
private ResultMap resultMap;
@Autowired
private UserService userService;
@Autowired
private PageService pageService;
@Autowired
private UserRoleService userRoleService;
private final Logger logger = LoggerFactory.getLogger(LoginController.class);
/**
* 返回 尚未登陆信息
*/
@RequestMapping(value = "/notLogin", method = RequestMethod.GET)
@ResponseBody
public ResultMap notLogin() {
logger.warn("尚未登陆!");
return resultMap.success().message("您尚未登陆!");
}
/**
* 返回 没有权限
*/
@RequestMapping(value = "/notRole", method = RequestMethod.GET)
@ResponseBody
public ResultMap notRole() {
Subject subject = SecurityUtils.getSubject();
User user = (User) subject.getPrincipal();
if (user != null) {
logger.info("{}---没有权限!", user.getName());
}
return resultMap.success().message("您没有权限!");
}
/**演示页面**/
@RequestMapping(value = "/demo/table", method = RequestMethod.GET)
public String demoTable() {
return "table";
}
@RequestMapping(value = "/demo/tu", method = RequestMethod.GET)
public String demoTu() {
return "tu";
}
@RequestMapping(value = "/demo/tu1", method = RequestMethod.GET)
public String tu1() {
return "tu1";
}
@RequestMapping(value = "/demo/tu2", method = RequestMethod.GET)
public String tu2() {
return "tu2";
}
@RequestMapping(value = "/demo/tu3", method = RequestMethod.GET)
public String tu3() {
return "tu3";
}
/**演示页面**/
/**
* Method name: logout
* Description: 退出登录
* @return String
*/
@RequestMapping(value = "/logout", method = RequestMethod.GET)
public String logout() {
Subject subject = SecurityUtils.getSubject();
User user = (User) subject.getPrincipal();
if (null != user) {
logger.info("{}---退出登录!", user.getName());
}
subject.logout();
return "login";
}
/**
* Method name: login
* Description: 登录验证
* Remark:
*
* @param username 用户名
* @param password 密码
* @return ResultMap
*/
@RequestMapping(value = "/login")
@ResponseBody
public ResultMap login(String username, String password) {
return userService.login(username, password);
}
/**
* Method name: login
* Description: 登录页面
*
* @return String login.html
*/
@RequestMapping(value = "/index")
public String login() {
return "login";
}
/**
* 注册页面 regist.html
*/
@RequestMapping(value = "/regist")
public String regist() {
return "regist";
}
/**
* 注册
*/
@RequestMapping(value = "/doRegist")
@ResponseBody
public ResultMap doRegist(User user) {
System.out.println(user);
User u = userService.getUserByPhoneAndName(user.getPhone(), null);
if (u != null){
return resultMap.success().message("该手机号已注册!");
}
try {
user.setPassword(MD5.md5(user.getPassword()));
user.setCreateTime(new Date());
userService.save(user);
String[] ids = new String[1];
ids[0] = user.getId()+"";
// 普通用户
userRoleService.addUserRole(2, ids);
return resultMap.success().message("注册成功");
}catch (Exception e){
e.printStackTrace();
return resultMap.fail().message("注册失败");
}
}
/**
* Method name: index
* Description: 登录页面
*
* @return String login.html
*/
@RequestMapping(value = "/")
public String index(Model model) {
Subject subject = SecurityUtils.getSubject();
User user = (User) subject.getPrincipal();
if (null != user) {
model.addAttribute("user", user);
List pageList = pageService.getAllRolePageByUserId(user.getId()+"");
model.addAttribute("pageList", pageList);
return "index";
} else {
return "login";
}
}
/**
* Method name: main
* Description: 进入主页面
* index.html
*/
@RequestMapping(value = "/main")
public String main(Model model) {
Subject subject = SecurityUtils.getSubject();
User user = (User) subject.getPrincipal();
if (null != user) {
model.addAttribute("user", user);
} else {
return "login";
}
List pageList = pageService.getAllRolePageByUserId(user.getId()+"");
model.addAttribute("pageList", pageList);
return "index";
}
/**
* Method name: checkUserPassword
* Description: 检测旧密码是否正确
*
* @param password 旧密码
* @return boolean 是否正确
*/
@RequestMapping(value = "/user/checkUserPassword")
@ResponseBody
public boolean checkUserPassword(String password) {
return userService.checkUserPassword(password);
}
/**
* Method name: updatePassword
* Description: 更新密码
*
* @param password 旧密码
* @return String 是否成功
*/
@RequestMapping(value = "/user/updatePassword")
@ResponseBody
public String updatePassword(String password) {
return userService.updatePassword(password);
}
}
/**
* 用户控制
*/
@Controller("User")
@RequestMapping("/user")
public class UserController {
private final Logger logger = LoggerFactory.getLogger(UserController.class);
private final ResultMap resultMap;
@Autowired
private UserService userService;
@Autowired
private UserRoleService userRoleService;
@Autowired
public UserController(ResultMap resultMap) {
this.resultMap = resultMap;
}
/**
* 返回有权限信息
*/
@RequestMapping(value = "/getMessage", method = RequestMethod.GET)
public ResultMap getMessage() {
return resultMap.success().message("您拥有用户权限,可以获得该接口的信息!");
}
/**
* 修改用户信息页面user/userEdit.html
*/
@RequestMapping(value = "/editUserPage")
public String editUserPage(Long userId, Model model) {
model.addAttribute("manageUser", userId);
if (null != userId) {
User user = userService.selectByPrimaryKey(userId);
model.addAttribute("manageUser", user);
}
return "user/userEdit";
}
/**
* 更新数据库
*/
@ResponseBody
@RequestMapping("/updateUser")
public String updateUser(User user) {
return userService.updateUser(user);
}
}
源码获取:博客首页 "资源" 里下载!