package com.cxhello.admin.controller;
import com.cxhello.admin.entity.Role;
import com.cxhello.admin.entity.User;
import com.cxhello.admin.service.RoleService;
import com.cxhello.admin.service.UserService;
import com.cxhello.admin.utils.Result;
import com.cxhello.admin.utils.ResultUtils;
import com.github.pagehelper.PageInfo;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
/**
* @author CaiXiaoHui
* @create 2019/11/9 22:47
*/
@Controller
@RequestMapping("/admin/user")
public class UserController {
private static final Logger logger = LogManager.getLogger(UserController.class);
@Autowired
private UserService userService;
@Autowired
private RoleService roleService;
@RequestMapping(value = { "/", "/index" })
public String index() {
return "admin/user/index";
}
@RequestMapping("/list")
@ResponseBody
public PageInfo<User> list(@RequestParam(value = "searchText",required = false) String searchText,PageInfo pageInfo){
return userService.findAllByLike(searchText,pageInfo);
}
@RequestMapping(value = "/add")
public String add(Model model) {
return "admin/user/form";
}
@RequestMapping(value = "/edit/{id}")
public String edit(@PathVariable Integer id,Model model){
User user = userService.selectUserById(id);
model.addAttribute("user",user);
return "admin/user/form";
}
@RequestMapping(value = "/edit")
@ResponseBody
public Result edit(User user){
try {
userService.saveOrUpdate(user);
} catch (Exception e) {
logger.error(e.getMessage());
return ResultUtils.getMsg("系统异常,请稍后重试!");
}
return ResultUtils.getMsg("更新成功");
}
@RequestMapping("/delete/{id}")
@ResponseBody
public Result delete(@PathVariable("id") Integer id){
try {
userService.delete(id);
} catch (Exception e) {
logger.error(e.getMessage());
return ResultUtils.getFailResult();
}
return ResultUtils.getSuccessResult();
}
@RequestMapping(value = "/grant/{id}", method = RequestMethod.GET)
public String grant(@PathVariable Integer id, Model model) {
User user = userService.selectUserById(id);
model.addAttribute("user", user);
//用户拥有的角色
List<Role> userRoleList = userService.selectUserRoles(id);
List<Integer> roleIds = new ArrayList<Integer>();
for (Role role : userRoleList) {
roleIds.add(role.getId());
}
model.addAttribute("roleIds", roleIds);
List<Role> roleList = roleService.findAll();
model.addAttribute("roleList", roleList);
return "admin/user/grant";
}
@RequestMapping(value = "/grant/{id}", method = RequestMethod.POST)
@ResponseBody
public Result grant(@PathVariable Integer id, String[] roleIds) {
try{
userService.grant(id,roleIds);
}catch (Exception e){
logger.error(e.getMessage());
return ResultUtils.getMsg(e.getMessage());
}
return ResultUtils.getMsg("操作成功");
}
@RequestMapping(value = "/updatePwd", method = RequestMethod.GET)
public String updatePwd() {
return "admin/user/updatePwd";
}
@RequestMapping(value = "/updatePwd", method = RequestMethod.POST)
@ResponseBody
public Result updatePwd(String oldPassword, String password1, String password2){
try {
Subject subject = SecurityUtils.getSubject();
Object principal = subject.getPrincipal();
if(principal== null){
return ResultUtils.getMsg("您尚未登录");
}
userService.updatePwd((User)principal,oldPassword,password1,password2);
return ResultUtils.getSuccessResult();
} catch (Exception e) {
logger.error(e.getMessage());
return ResultUtils.getResult(400,e.getMessage());
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
基于SpringBoot2+Shiro+Thymeleaf的后台管理系统.zip
共416个文件
html:96个
js:87个
png:62个
需积分: 5 0 下载量 93 浏览量
2023-08-07
23:19:47
上传
评论
收藏 3.73MB ZIP 举报
温馨提示
基于java、jsp、servlet、mysql、springboot等技术构建的系统,适合毕设项目、课设作业。资源中的源码都是经过本地编译过可运行的,下载后按照文档配置好环境就可以运行。资源项目的难度比较适中,内容都是经过助教老师审定过的,应该能够满足学习、使用需求,如果有需要的话可以放心下载使用。
资源推荐
资源详情
资源评论
收起资源包目录
基于SpringBoot2+Shiro+Thymeleaf的后台管理系统.zip (416个子文件)
summernote-bs3.css 149KB
style.css 142KB
bootstrap.min.css 118KB
animate.css 67KB
datepicker3.css 34KB
font-awesome.css 34KB
bootstrap-rtl.css 32KB
font-awesome.min.css 26KB
ambiance.css 26KB
style.min.css 25KB
sweetalert.css 18KB
simditor.css 18KB
ui.jqgrid.css 17KB
jasny-bootstrap.min.css 14KB
jquery-ui-1.10.4.custom.min.css 14KB
chosen.css 13KB
dropzone.css 12KB
fullcalendar.css 11KB
layim.css 11KB
layer.css 11KB
summernote.css 10KB
plyr.css 10KB
awesome.css 9KB
webuploader-demo.css 8KB
codemirror.css 7KB
awesome-bootstrap-checkbox.css 7KB
toastr.min.css 7KB
blueimp-gallery.min.css 7KB
metroStyle.css 7KB
zTreeStyle.css 6KB
laydate.css 6KB
jquery.steps.css 6KB
blueimp-gallery.css 6KB
footable.core.css 6KB
dataTables.bootstrap.css 5KB
bootstrap-table.min.css 4KB
clockpicker.css 4KB
basic.css 4KB
style.css 4KB
laydate.css 3KB
bootstrap-colorpicker.min.css 3KB
cropper.min.css 3KB
ion.rangeSlider.css 3KB
jquery.nouislider.css 3KB
layer.ext.css 3KB
bootstrap-markdown.min.css 3KB
jquery.gritter.css 3KB
blueimp-gallery-video.css 2KB
login.css 2KB
ion.rangeSlider.skinFlat.css 2KB
bootstrap-duallistbox.css 2KB
blueimp-gallery-indicator.css 2KB
custom.css 1KB
bootstrap-multiselect.css 1KB
bootstrap-treeview.css 1KB
demo.css 918B
fullcalendar.print.css 692B
switchery.css 643B
webuploader.css 543B
morris-0.4.3.min.css 445B
Dockerfile 456B
fontawesome-webfont.eot 67KB
glyphicons-halflings-regular.eot 20KB
footable.eot 5KB
loading-0.gif 6KB
xubox_loading0.gif 6KB
zTreeStandard.gif 5KB
metro.gif 5KB
loading.gif 4KB
xubox_loading3.gif 2KB
xubox_loading2.gif 2KB
loading-2.gif 2KB
throbber.gif 2KB
loading-upload.gif 2KB
xubox_loading1.gif 701B
loading-1.gif 701B
loading.gif 381B
loading.gif 381B
loading.gif 381B
loading.gif 166B
line_conn.gif 45B
ie-spacer.gif 43B
.gitattributes 483B
.gitattributes 86B
.gitignore 2KB
.gitignore 73B
fontawesome.html 138KB
index_v1.html 86KB
form_advanced.html 58KB
glyphicons.html 52KB
table_data_tables.html 51KB
clients.html 50KB
table_foo_table.html 40KB
buttons.html 35KB
form_basic.html 34KB
widgets.html 30KB
table_bootstrap.html 30KB
social_feed.html 27KB
index.html 26KB
typography.html 25KB
共 416 条
- 1
- 2
- 3
- 4
- 5
资源评论
独处东汉
- 粉丝: 297
- 资源: 820
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功