适合于刚学习了SSM框架,想找项目练手的同学,那么本例非常适合你,希望能帮助有需要的初学者,不喜勿喷,另外有相关不足,希望大家可以指出,谢谢!
使用的技术
SSM + Layui + Maven + Ajax
Layui 是一款前端 UI 框架,遵循原生 HTML/CSS/JS 的书写与组织形式。其外在极简,却又不失饱满的内在,体积轻盈,组件丰盈,非常适合界面的快速开发。 准确地说,她更多是为服务端程序员量身定做,你无需涉足各种前端工具的复杂配置,只需面对浏览器本身。
Layui官网地址 https://www.layui.com/
开发工具及数据库
IDEA + MySQL 5.x
项目部署
linux centos 7.x + tomcat 8.5
现在已经更新到2.0版本 https://blog.csdn.net/qq_39207647/article/details/103878722
先上截图
项目总体包结构 数据库设计 ![在这里插入图片描述](https://img-blog.csdnimg.cn/20190822105447459.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM5MjA3NjQ3,size_16,color_FFFFFF,t_70)
登录界面 需要填写验证码
![](https://img-blog.csdnimg.cn/20190822101911574.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM5MjA3NjQ3,size_16,color_FFFFFF,t_70)
登录成功后的首页界面
![在这里插入图片描f'f述](https://img-blog.csdnimg.cn/20190822102324762.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM5MjA3NjQ3,size_16,color_FFFFFF,t_70)
个人面板
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190822102513416.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM5MjA3NjQ3,size_16,color_FFFFFF,t_70)
记录管理员登录日志
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190822102538676.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM5MjA3NjQ3,size_16,color_FFFFFF,t_70)
用户管理界面
前端请求列表代码片段
table.render({
id:'userList'
,elem: '#userList'
,url: ctx+'/user/getAllUserList'// 数据接口
,limit:10// 每页默认数
,limits:[10,20,30,40]
,cols: [[ // 表头
{field:'username', title: '登录名', align: 'center',width:110}
,{field:'sex', title: '性别' , align: 'center',templet : '#sexTpl',width:60}
,{field:'birthday', title: '生日' , align: 'center',templet : '{{ formatTime(d.birthday,"yyyy-MM-dd")}}',width:110}
,{field:'phone', title: '电话', align: 'center' ,width:120}
,{field:'email', title: 'E-mail' , align: 'center',width:180}
,{field:'status', title: '状态', width:80, templet : '#statusTpl',width:95, align: 'center'}
,{field:'roleId', title: '等级' , align: 'center', templet : '#levelTpl',width:120}
,{field:'createTime', title: '注册时间' , align: 'center',templet : '{{ formatTime(d.createTime,"yyyy-MM-dd hh:mm:ss")}}' ,width:170}
,{field:'address', title: '地址', align: 'center' }
,{field:'note', title: '备注', align: 'center' }
, {field: 'right', title: '操作', align: 'center', toolbar: "#barDemo",width:150}
]]
,page: true // 开启分页
,loading:true
,where: {timestamp: (new Date()).valueOf()}
});
form.on('switch(statusSwitch)', function(data){
var status = this.checked ? 1 : 0;
var id = this.value;
$.ajax({
url : ctx + '/user/updateUserStatusById',
type : "get",
data:{
status:status,
id:id
},
success : function(d) {
if (d.code == 0) {
layer.msg("更新用户状态成功!");
} else {
layer.msg("权限不足!", {
icon : 5
});
}
}
})
});
获取用户列表和更新用户信息后台代码片段
@Controller
@RequestMapping("/user")
public class UserController {
@Autowired
private UserService userService;
/*
*获取所有用户列表
*/
@RequestMapping("getAllUserList")
@ResponseBody
public ResultUtil getAllUserList(Integer page, Integer limit,UserSearch search) {
return userService.getAllUserList(page, limit,search);
}
/*
*增加新用户
*/
@RequestMapping("insertUser")
@ResponseBody
public ResultUtil insUser(User user){
//防止浏览器提交
User user1 = userService.selUserByUsername(user.getUsername());
if(null != user1){
return new ResultUtil(500,"用户名已存在,请重新填写!");
}
try {
userService.insertUser(user);
return ResultUtil.ok();
} catch (Exception e) {
return new ResultUtil(502,"网络错误,请检查网络!");
}
}
/*
*检查是否有同名用户,防止用户名重复
*/
@RequestMapping("checkUserByUsername/{username}")
@ResponseBody
public ResultUtil checkUserByUsername(@PathVariable("username")String username){
User user = userService.selUserByUsername(username);
if(user!=null){
return new ResultUtil(500,"用户名已存在,请重新填写!");
}
return new ResultUtil(0);
}
/*
*更新用户状态
*/
@RequestMapping("updateUserStatusById")
@ResponseBody
public ResultUtil updateUserStatusById(int id, int status) {
return userService.updateUserStatusById(id, status);
}
/*
*更新用户信息
*/
@RequestMapping("updateUser")
@ResponseBody
public ResultUtil updateUser(User user) throws ParseException {
return userService.updateUser(user);
}
}
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190822102710108.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM5MjA3NjQ3,size_16,color_FFFFFF,t_70)
管理员管理
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190822102845868.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM5MjA3NjQ3,size_16,color_FFFFFF,t_70) ![在这里插入图片描述](https://img-blog.csdnimg.cn/20190822102930845.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM5MjA3NjQ3,size_16,color_FFFFFF,t_70)
角色管理列表
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190822102811348.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM5MjA3NjQ3,size_16,color_FFFFFF,t_70)
/*
* 得到指定角色权限树
*/
@RequestMapping(value="/xtreedata",produces = {"text/json;charset=UTF-8"})
@ResponseBody
public String xtreeData(@RequestParam(value="roleId", defaultValue="-1") Long roleId) {
Admin admin = new Admin();
admin.setRoleId(roleId);
return GsonUtil.entityToJson(adminService.getXtreeData(admin));
}
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190822103244962.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM5MjA3NjQ3,size_16,color_FFFFFF,t_70) ![在这里插入图片描述](https://img-blog.csdnimg.cn/20190822102857791.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM5MjA3NjQ3,size_16,color_FFFFFF,t_70)
菜单管理
不同权限的管理员登录到后台看到的左侧菜单栏不同,超级管理员可以管理其他管理员的权 ![在这里插入图片描述](https://img-blog.csdnimg.cn/201908221031320.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM5MjA3NjQ3,size_16,color_FFFFFF,t_70)
/*
* 维护菜单信息
*/
@RequestMapping("/menuForm")
@ResponseBody
public ResultUtil menuForm(Menu menus,String flag){
if(StringUtils.isBlank(flag)){
//同级菜单名不相同
List data=adminService.checkNameSameLevel(menus);
Menu m = adminService.getMenuById(menus.getMenuId());
Boolean f=false;
if(m.getName().equals(menus.getName())||data.size()==0){
f=true;
}
if(!f||data.size()>1){
return ResultUtil.error("同级菜单名不能相同!");
}
menus.setSpread("false");
adminService.updMenu(menus);
return ResultUtil.ok("修改成功!");
}else if(menus.getMenuId()!=1){
menus.setParentId(menus.getMenuId());
//规定只能3级菜单
Menu m=adminService.getMenuById(menus.getMenuId());
if(m!=null&&m.getParentId()!=0){
Menu m1=adminService.getMenuById(m.getParentId());
if(m1!=null&&m1.getParentId()!=0){
return ResultUtil.error("此菜单不允许添加子菜单!");
}
}
//同级菜单名不相同
List data=adminService.checkNameSameLevel(menus);
if(data.size()>0){
return ResultUtil.error("同级菜单名不能相同!");
}
menus.setMenuId(null);
menus.setSpread("false");
adminService.insMenu(menus);
return ResultUtil.ok("添加成功!");
}else{
return ResultUtil.error("此菜单不允许操作!");
}
}
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190822103212319.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM5MjA3NjQ3,size_16,color_FFFFFF,t_70)
项目源码已上传到github SSM+Layui 后台管理
如果对您有帮助,点点关注,加个 star,会不断更新噢!
宠辱不惊,闲看庭前花开花落 去留无意,漫随天外云卷云舒
|