源码获取:俺的博客首页 "资源" 里下载!
项目
介绍首页、公告消息、垃圾资讯、个人账号、个人收藏、垃圾政策、技术设备
后台管理、人员管理、内容管理、模块管理、个人收藏
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;
5.数据库:MySql 5.7版本;
6.是否Maven项目:是;
技术栈
1. 后端:SpringBoot
2. 前端:Thymeleaf+HTML+CSS+jQuery
使用说明
1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中application.yml配置文件中的数据库配置改为自己的配置;
登陆管理控制层:
/**
*
* 登录相关
*/
@Controller
public class SysLoginController {
@Autowired
private Producer producer;
@Autowired
private SysUserService sysUserService;
@RequestMapping("captcha.jpg")
public void captcha(HttpServletResponse response) throws ServletException, IOException {
response.setHeader("Cache-Control", "no-store, no-cache");
response.setContentType("image/jpeg");
//生成文字验证码
String text = producer.createText();
//生成图片验证码
BufferedImage image = producer.createImage(text);
//保存到shiro session
ShiroUtils.setSessionAttribute(Constants.KAPTCHA_SESSION_KEY, text);
ServletOutputStream out = response.getOutputStream();
ImageIO.write(image, "jpg", out);
}
/**
* 登录
*/
@ResponseBody
@RequestMapping(value = "/sys/login", method = RequestMethod.POST)
public R login(String username, String password, String captcha) throws IOException {
String kaptcha = ShiroUtils.getKaptcha(Constants.KAPTCHA_SESSION_KEY);
System.out.println("==验证码=="+kaptcha);
System.out.println("==password=="+password);
System.out.println("==username=="+username);
if(!captcha.equalsIgnoreCase(kaptcha)){
return R.error("验证码不正确");
}
if(password==null){
return R.error("密码不能为空");
}
try {
Subject subject = ShiroUtils.getSubject();
//sha256加密
password = new Sha256Hash(password).toHex();
System.out.println("==sha256加密==="+password);
UsernamePasswordToken token = new UsernamePasswordToken(username, password);
subject.login(token);
} catch (UnknownAccountException e) {
return R.error(e.getMessage());
} catch (IncorrectCredentialsException e) {
return R.error(e.getMessage());
} catch (LockedAccountException e) {
return R.error(e.getMessage());
} catch (AuthenticationException e) {
return R.error("账户验证失败");
}
return R.ok();
}
/**
*/
@ResponseBody
@RequestMapping(value = "/sys/reg", method = RequestMethod.POST)
public R reg(String username, String password, String captcha) throws IOException {
// String kaptcha = ShiroUtils.getKaptcha(Constants.KAPTCHA_SESSION_KEY);
// if(!captcha.equalsIgnoreCase(kaptcha)){
// return R.error("验证码不正确");
// }
//sha256加密
SysUserEntity user = new SysUserEntity();
user.setUsername(username);
user.setPassword(password);
user.setStatus(1);
List<Long> roles = new ArrayList<>();
roles.add(1L);
user.setRoleIdList(roles);
this.sysUserService.save(user);
return R.ok();
}
/**
* 退出
*/
@RequestMapping(value = "logout", method = RequestMethod.GET)
public String logout() {
ShiroUtils.logout();
return "redirect:login.html";
}
}
角色管理控制层:
/**
* 角色管理
*
*
*/
@RestController
@RequestMapping("/sys/role")
public class SysRoleController extends AbstractController {
@Autowired
private SysRoleService sysRoleService;
@Autowired
private SysRoleMenuService sysRoleMenuService;
/**
* 角色列表
*/
@RequestMapping("/list")
@RequiresPermissions("sys:role:list")
public R list(@RequestParam Map<String, Object> params){
//如果不是超级管理员,则只查询自己创建的角色列表
// if(getUserId() != Constant.SUPER_ADMIN){
// params.put("createUserId", getUserId());
// }
//查询列表数据
Query query = new Query(params);
List<SysRoleEntity> list = sysRoleService.queryList(query);
int total = sysRoleService.queryTotal(query);
PageUtils pageUtil = new PageUtils(list, total, query.getLimit(), query.getPage());
return R.ok().put("page", pageUtil);
}
/**
* 角色列表
*/
@RequestMapping("/select")
@RequiresPermissions("sys:role:select")
public R select(){
Map<String, Object> map = new HashMap<>();
//如果不是超级管理员,则只查询自己所拥有的角色列表
// if(getUserId() != Constant.SUPER_ADMIN){
// map.put("createUserId", getUserId());
// }
List<SysRoleEntity> list = sysRoleService.queryList(map);
return R.ok().put("list", list);
}
/**
* 角色信息
*/
@RequestMapping("/info/{roleId}")
@RequiresPermissions("sys:role:info")
public R info(@PathVariable("roleId") Long roleId){
SysRoleEntity role = sysRoleService.queryObject(roleId);
//查询角色对应的菜单
List<Long> menuIdList = sysRoleMenuService.queryMenuIdList(roleId);
role.setMenuIdList(menuIdList);
return R.ok().put("role", role);
}
/**
* 保存角色
*/
@SysLog("保存角色")
@RequestMapping("/save")
@RequiresPermissions("sys:role:save")
public R save(@RequestBody SysRoleEntity role){
ValidatorUtils.validateEntity(role);
role.setCreateUserId(getUserId());
sysRoleService.save(role);
return R.ok();
}
/**
* 修改角色
*/
@SysLog("修改角色")
@RequestMapping("/update")
@RequiresPermissions("sys:role:update")
public R update(@RequestBody SysRoleEntity role){
ValidatorUtils.validateEntity(role);
role.setCreateUserId(getUserId());
sysRoleService.update(role);
return R.ok();
}
/**
* 删除角色
*/
@SysLog("删除角色")
@RequestMapping("/delete")
@RequiresPermissions("sys:role:delete")
public R delete(@RequestBody Long[] roleIds){
sysRoleService.deleteBatch(roleIds);
return R.ok();
}
}
用户管理控制层:
/**
*
* 系统用户
*
*/
@RestController
@RequestMapping("/sys/user")
public class SysUserController extends AbstractController {
@Autowired
private SysUserService sysUserService;
@Autowired
private SysUserRoleService sysUserRoleService;
/**
* 所有用户列表
*/
@RequestMapping("/list")
public R list(@RequestParam Map<String, Object> params) {
//查询列表数据
Query query = new Query(params);
List<SysUserEntity> userList = sysUserService.queryList(query);
int total = sysUserService.queryTotal(query);
PageUtils pageUtil = new PageUtils(userList, total, query.getLimit(), query.getPage());
return R.ok().put("page", pageUtil);
}
@RequestMapping("/list2")
public R list2(@RequestParam Map<String, Object> params) {
//查询列表数据
Query query = new Query(params);
List<SysUserEntity> userList = sysUserService.queryList(query);
return R.ok().put("list", userList);
}
/**
* 获取登录的用户信息
*/
@RequestMapping("/info")
public R info() {
return R.ok().put("user", this.sysUserService.queryObject(getUser().getUserId()));
}
/**
* 修改登录用户密码
*/
@SysLog("修改密码")
@RequestMapping("/password")
public R password(String password, String newPassword) {
Assert.isBlank(newPassword, "新密码不为能空");
//sha256加密
password = new Sha256Hash(password).toHex();
//sha256加密
newPassword = new Sha256Hash(newPassword).toHex();
//更新密码
int count = sysUserService.updatePassword(getUserId(), password, newPassword);
if (count == 0) {
return R.error("原密码不正确");
}
//退出
ShiroUtils.logout();
return R.ok();
}
@SysLog("修改个人信息")
@RequestMapping("/updateInfo")
public R updateInfo(@RequestBody SysUserEntity user) {
this.sysUserService.update(user);
return R.ok();
}
/**
* 用户信息
*/
@RequestMapping("/info/{userId}")
public R info(@PathVariable("userId") Long userId) {
SysUserEntity user = sysUserService.queryObject(userId);
//获取用户所属的角色列表
List<Long> roleIdList = sysUserRoleService.queryRoleIdList(userId);
user.setRoleIdList(roleIdList);
return R.ok().put("user", user);
}
/**
* 保存用户
*/
@SysLog("保存用户")
@RequestMapping("/save")
public R save(@RequestBody SysUserEntity user) {
ValidatorUtils.validateEntity(user, AddGroup.class);
user.setCreateUserId(getUserId());
sysUserService.save(user);
return R.ok();
}
/**
* 修改用户
*/
@SysLog("修改用户")
@RequestMapping("/update")
public R update(@RequestBody SysUserEntity user) {
ValidatorUtils.validateEntity(user, UpdateGroup.class);
user.setCreateUserId(getUserId());
sysUserService.update(user);
return R.ok();
}
/**
* 删除用户
*/
@SysLog("删除用户")
@RequestMapping("/delete")
public R delete(@RequestBody Long[] userIds) {
if (ArrayUtils.contains(userIds, 1L) || ArrayUtils.contains(userIds, -1L)) {
return R.error("系统管理员不能删除");
}
if (ArrayUtils.contains(userIds, getUserId())) {
return R.error("当前用户不能删除");
}
sysUserService.deleteBatch(userIds);
return R.ok();
}
}
源码获取:俺的博客首页 "资源" 里下载!