基于javaweb+mysql的ssm+maven校园相册管理系统(java+ssm+html+bootstrap+layui+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SSM+Maven校园相册管理系统(java+ssm+html+bootstrap+layui+mysql)
项目介绍
实现了用户登录与注册,查看首页,查看我的相册,添加相册,提交评论,修改密码等功能
环境需要
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项目:是;
技术栈
- 后端:Spring+SpringMVC+Mybatis 2. 前端:html+CSS+JavaScript+bootstrap+layui
使用说明
- 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven; 若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中jdbc.properties配置文件中的数据库配置改为自己的配置; 4. 运行项目,在浏览器中输入 http://localhost:8080/ssm_xcselect
@Override
public Map<String,String[]> getParameterMap() {
Map<String,String[]> map = new LinkedHashMap<>();
Map<String,String[]> parameters = super.getParameterMap();
for (String key : parameters.keySet()) {
String[] values = parameters.get(key);
for (int i = 0; i < values.length; i++) {
values[i] = xssEncode(values[i]);
}
map.put(key, values);
}
return map;
}
@Override
public String getHeader(String name) {
String value = super.getHeader(xssEncode(name));
if (StringUtils.isNotBlank(value)) {
value = xssEncode(value);
}
return value;
}
private String xssEncode(String input) {
return htmlFilter.filter(input);
}
/**
* 获取最原始的request
*/
public HttpServletRequest getOrgRequest() {
return orgRequest;
}
/**
* 获取最原始的request
*/
public static HttpServletRequest getOrgRequest(HttpServletRequest request) {
if (request instanceof XssHttpServletRequestWrapper) {
return ((XssHttpServletRequestWrapper) request).getOrgRequest();
}
return request;
}
}
package com.learn.controller;
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") Long id){
NewsEntity news = newsService.queryObject(id);
return R.ok().put("news", news);
}
/**
* 保存
*/
@RequestMapping("/save")
public R save(@RequestBody NewsEntity news){
newsService.save(news);
return R.ok();
}
/**
* 修改
*/
@RequestMapping("/update")
public R update(@RequestBody NewsEntity news){
newsService.update(news);
return R.ok();
}
/**
* 删除
*/
@RequestMapping("/delete")
public R delete(@RequestBody Long[] ids){
newsService.deleteBatch(ids);
return R.ok();
}
}
package com.learn.aop;
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") Long id){
NewsEntity news = newsService.queryObject(id);
return R.ok().put("news", news);
}
/**
* 保存
*/
@RequestMapping("/save")
public R save(@RequestBody NewsEntity news){
newsService.save(news);
return R.ok();
}
/**
* 修改
*/
@RequestMapping("/update")
public R update(@RequestBody NewsEntity news){
newsService.update(news);
return R.ok();
}
/**
* 删除
*/
@RequestMapping("/delete")
public R delete(@RequestBody Long[] ids){
newsService.deleteBatch(ids);
return R.ok();
}
}
package com.learn.aop;
@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);
public R select(){
//查询列表数据
List<SysMenuEntity> menuList = sysMenuService.queryNotButtonList();
//添加顶级菜单
SysMenuEntity root = new SysMenuEntity();
root.setMenuId(0L);
root.setName("一级菜单");
root.setParentId(-1L);
root.setOpen(true);
menuList.add(root);
return R.ok().put("menuList", menuList);
}
/**
* 角色授权菜单
*/
@RequestMapping("/perms")
@RequiresPermissions("sys:menu:perms")
public R perms(){
//查询列表数据
List<SysMenuEntity> menuList = null;
//只有超级管理员,才能查看所有管理员列表
if(getUserId() == Constant.SUPER_ADMIN){
menuList = sysMenuService.queryList(new HashMap<String, Object>());
}else{
menuList = sysMenuService.queryUserList(getUserId());
}
return R.ok().put("menuList", menuList);
}
/**
* 菜单信息
*/
@RequestMapping("/info/{menuId}")
@RequiresPermissions("sys:menu:info")
public R info(@PathVariable("menuId") Long menuId){
SysMenuEntity menu = sysMenuService.queryObject(menuId);
* 列表
*/
@RequestMapping("/list")
public R list(@RequestParam Map<String, Object> params){
//查询列表数据
Query query = new Query(params);
List<CommentEntity> commentList = commentService.queryList(query);
int total = commentService.queryTotal(query);
PageUtils pageUtil = new PageUtils(commentList, 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<CommentEntity> commentList = commentService.queryList(query);
return R.ok().put("list", commentList );
}
/**
* 信息
*/
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") Long id){
CommentEntity comment = commentService.queryObject(id);
return R.ok().put("comment", comment);
}
/**
* 保存
*/
@RequestMapping("/save")
public R save(@RequestBody CommentEntity comment){
commentService.save(comment);
String tables = orgRequest.getParameter("tables");
tableNames = JSON.parseArray(tables).toArray(tableNames);
byte[] data = sysGeneratorService.generatorCode(tableNames);
response.reset();
response.setHeader("Content-Disposition", "attachment; filename=\"renren.zip\"");
response.addHeader("Content-Length", "" + data.length);
response.setContentType("application/octet-stream; charset=UTF-8");
IOUtils.write(data, response.getOutputStream());
}
}
package com.learn.controller;
/**
*
*
* @email 123456@qq.com
*/
*/
@SysLog("保存菜单")
@RequestMapping("/save")
@RequiresPermissions("sys:menu:save")
public R save(@RequestBody SysMenuEntity menu){
//数据校验
verifyForm(menu);
sysMenuService.save(menu);
return R.ok();
}
/**
* 修改
*/
@SysLog("修改菜单")
@RequestMapping("/update")
@RequiresPermissions("sys:menu:update")
public R update(@RequestBody SysMenuEntity menu){
//数据校验
verifyForm(menu);
sysMenuService.update(menu);
return R.ok();
}
/**
* 删除
*/
@SysLog("删除菜单")
@RequestMapping("/delete")
@RequiresPermissions("sys:menu:delete")
public R delete(@RequestBody Long[] menuIds){
for(Long menuId : menuIds){
if(menuId.longValue() <= 30){
return R.error("系统菜单,不能删除");
}
}
sysMenuService.deleteBatch(menuIds);
return R.ok();
}
/**
* 用户菜单列表
*/
@RequestMapping("/user")
public R user(){
String path = null;
if (upload != null && !upload.isEmpty()) {
String url = MultipartFileUtil.uploadFile("/cdn", upload, request);
path = url;
}
// 返回“图像”选项卡并显示图片
out.println("<script type=\"text/javascript\">");
out.println("window.parent.CKEDITOR.tools.callFunction(" + CKEditorFuncNum + ",'" + path + "','')");
out.println("</script>");
} catch (RuntimeException e) {
out.println("<script type=\"text/javascript\">");
out.println("window.parent.CKEDITOR.tools.callFunction(" + CKEditorFuncNum + ",'','" + e.getMessage() + "');");
out.println("</script>");
}
}
}
package com.learn.controller;
/**
/**
* 列表
*/
@RequestMapping("/list2")
public R list2(@RequestParam Map<String, Object> params) {
params.put("user", super.getUserId());
Query query = new Query(params);
List<PicEntity> picList = picService.queryList(query);
return R.ok().put("list", picList);
}
/**
* 信息
*/
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") Long id) {
PicEntity pic = picService.queryObject(id);
pic.setUrl("/ssm_xcselect/"+pic.getUrl());
return R.ok().put("pic", pic);
}
/**
* 保存
*/
@RequestMapping("/save")
public R save(@RequestBody PicEntity pic) {
pic.setUser(super.getUserId());
picService.save(pic);
return R.ok();
}
/**
* 修改
*/
@RequestMapping("/update")
public R update(@RequestBody PicEntity pic) {
picService.update(pic);
return R.ok();
}
*/
@RequestMapping("/save")
public R save(@RequestBody PicEntity pic) {
pic.setUser(super.getUserId());
picService.save(pic);
return R.ok();
}
/**
* 修改
*/
@RequestMapping("/update")
public R update(@RequestBody PicEntity pic) {
picService.update(pic);
return R.ok();
}
/**
* 删除
*/
@RequestMapping("/delete")
public R delete(@RequestBody Long[] ids) {
picService.deleteBatch(ids);
return R.ok();
}
}
package com.learn.xss;
/**
* XSS过滤处理
* @email 123456@qq.com
*/
public class XssHttpServletRequestWrapper extends HttpServletRequestWrapper {
//没被包装过的HttpServletRequest(特殊场景,需求自己过滤)
HttpServletRequest orgRequest;
@Override
public String getParameter(String name) {
String value = super.getParameter(xssEncode(name));
if (StringUtils.isNotBlank(value)) {
value = xssEncode(value);
}
return value;
}
@Override
public String[] getParameterValues(String name) {
String[] parameters = super.getParameterValues(name);
if (parameters == null || parameters.length == 0) {
return null;
}
for (int i = 0; i < parameters.length; i++) {
parameters[i] = xssEncode(parameters[i]);
}
return parameters;
}
@Override
public Map<String,String[]> getParameterMap() {
Map<String,String[]> map = new LinkedHashMap<>();
Map<String,String[]> parameters = super.getParameterMap();
for (String key : parameters.keySet()) {
String[] values = parameters.get(key);
for (int i = 0; i < values.length; i++) {
values[i] = xssEncode(values[i]);
}
map.put(key, values);
}
return map;
}
@Override
public String getHeader(String name) {
String value = super.getHeader(xssEncode(name));
if (StringUtils.isNotBlank(value)) {
value = xssEncode(value);
}
return value;
}
*/
@RequestMapping("/save")
public R save(@RequestBody AlbumEntity album) {
album.setUser(super.getUserId());
albumService.save(album);
return R.ok();
}
/**
* 修改
*/
@RequestMapping("/update")
public R update(@RequestBody AlbumEntity album) {
albumService.update(album);
return R.ok();
}
/**
* 删除
*/
@RequestMapping("/delete")
public R delete(@RequestBody Long[] ids) {
albumService.deleteBatch(ids);
for (Long id : ids) {
Map<String, Object> para = new HashMap<>();
para.put("album", id);
for (PicEntity pic : this.picService.queryList(para)) {
this.picService.delete(pic.getId());
}
}
return R.ok();
}
}
package com.learn.controller;
}
package com.learn.controller;
/**
* @email 123456@qq.com
*/
@RestController
@RequestMapping("api")
public class ApiController extends AbstractController {
@Autowired
private PicService picService;
@Autowired
CommentService commentService;
@RequestMapping("/pics")
public R list2(@RequestParam Map<String, Object> params) {
Query query = new Query(params);
List<PicEntity> picList = picService.queryList(query);
return R.ok().put("list", picList);
}
@RequestMapping("/pic/{id}")
public R info(@PathVariable("id") Long id) {
PicEntity pic = picService.queryObject(id);
pic.setView(pic.getView() + 1);
this.picService.update(pic);
return R.ok().put("pic", pic);
}
@RequestMapping("/comment")
public R info(Long id, String content) {
PicEntity pic = picService.queryObject(id);
CommentEntity comment = new CommentEntity();
comment.setContent(content);
comment.setPic(id);
if (ex instanceof RRException) {
r.put("code", ((RRException) ex).getCode());
r.put("msg", ((RRException) ex).getMessage());
}else if(ex instanceof DuplicateKeyException){
r = R.error("该数据已存在,请重新输入");
}else if(ex instanceof AuthorizationException){
r = R.error("没有权限,请联系管理员授权");
}else{
r = R.error();
}
//记录异常日志
logger.error(ex.getMessage(), ex);
String json = JSON.toJSONString(r);
response.getWriter().print(json);
} catch (Exception e) {
logger.error("RRExceptionHandler 异常处理失败", e);
}
return new ModelAndView();
}
}
package com.learn.controller;
/**
* @email 123456@qq.com
*/
@RestController
@RequestMapping("api")
public class ApiController extends AbstractController {
map.put(key, values);
}
return map;
}
@Override
public String getHeader(String name) {
String value = super.getHeader(xssEncode(name));
if (StringUtils.isNotBlank(value)) {
value = xssEncode(value);
}
return value;
}
private String xssEncode(String input) {
return htmlFilter.filter(input);
}
/**
* 获取最原始的request
*/
public HttpServletRequest getOrgRequest() {
return orgRequest;
}
/**
* 获取最原始的request
*/
public static HttpServletRequest getOrgRequest(HttpServletRequest request) {
if (request instanceof XssHttpServletRequestWrapper) {
return ((XssHttpServletRequestWrapper) request).getOrgRequest();
}
return request;
}
}
package com.learn.controller;
Method method = signature.getMethod();
SysLogEntity sysLog = new SysLogEntity();
SysLog syslog = method.getAnnotation(SysLog.class);
if(syslog != null){
//注解上的描述
sysLog.setOperation(syslog.value());
}
//请求的方法名
String className = joinPoint.getTarget().getClass().getName();
String methodName = signature.getName();
sysLog.setMethod(className + "." + methodName + "()");
//请求的参数
Object[] args = joinPoint.getArgs();
String params = JSON.toJSONString(args[0]);
sysLog.setParams(params);
//获取request
HttpServletRequest request = HttpContextUtils.getHttpServletRequest();
//设置IP地址
sysLog.setIp(IPUtils.getIpAddr(request));
//用户名
String username = ShiroUtils.getUserEntity().getUsername();
sysLog.setUsername(username);
sysLog.setCreateDate(new Date());
//保存系统日志
sysLogService.save(sysLog);
}
}
package com.learn.utils;
/**
* IP地址
*
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", getUser());
}
/**
* 修改登录用户密码
*/
@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")