基于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
/**
* 代码生成器
*
* @email 123456@qq.com
*/
@Controller
@RequestMapping("/sys/generator")
public class SysGeneratorController {
@Autowired
private SysGeneratorService sysGeneratorService;
/**
* 列表
*/
@ResponseBody
@RequestMapping("/list")
@RequiresPermissions("sys:generator:list")
public R list(@RequestParam Map<String, Object> params){
//查询列表数据
Query query = new Query(params);
List<Map<String, Object>> list = sysGeneratorService.queryList(query);
int total = sysGeneratorService.queryTotal(query);
PageUtils pageUtil = new PageUtils(list, total, query.getLimit(), query.getPage());
return R.ok().put("page", pageUtil);
}
/**
* 生成代码
*/
/**
* 登录相关
*
* @email 123456@qq.com
*/
@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);
// if(!captcha.equalsIgnoreCase(kaptcha)){
// return R.error("验证码不正确");
// }
try {
Subject subject = ShiroUtils.getSubject();
//sha256加密
password = new Sha256Hash(password).toHex();
UsernamePasswordToken token = new UsernamePasswordToken(username, password);
subject.login(token);
} catch (UnknownAccountException e) {
public static final Logger logger = LoggerFactory.getLogger(MultipartFileUtil.class);
/**
* 根据文件名称获取后缀名
*
* @param fileName 文件名称
* @return 结果
*/
public static String getSuffix(String fileName) {
return fileName.substring(fileName.lastIndexOf(".") + 1);
}
/**
* 获取项目根路径
*
* @return 结果
*/
public static String getRootPath(HttpServletRequest request) {
String classPath = request.getSession().getServletContext().getRealPath( "/" );
String rootPath = "";
//windows下
if ("\\".equals(File.separator)) {
// rootPath = classPath.substring(1, classPath.indexOf("/WEB-INF/classes"));
rootPath = classPath;
rootPath = rootPath.replace("/", "\\");
}
//linux下
if ("/".equals(File.separator)) {
rootPath = classPath.substring(0, classPath.indexOf("/WEB-INF/classes"));
rootPath = rootPath.replace("\\", "/");
}
return rootPath;
}
/**
* 判断文件是否未空,或者没有数据
*
* @param file 文件
* @return 结果
*/
public static boolean isEmpty(MultipartFile file) {
return file == null || file.getSize() == 0 || "".equals(file.getOriginalFilename().trim());
}
String path = filePath + fileName;
//创建文件
File localFile = new File(path);
try {
file.transferTo(localFile);
} catch (IOException e) {
e.printStackTrace();
}
return prefix + "/" + fileName;
}
}
/**
* @email 123456@qq.com
*/
@RestController
@RequestMapping("pic")
public class PicController extends AbstractController {
@Autowired
private PicService picService;
* @email 123456@qq.com
*/
@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);
// if(!captcha.equalsIgnoreCase(kaptcha)){
// return R.error("验证码不正确");
// }
try {
Subject subject = ShiroUtils.getSubject();
//sha256加密
//查询列表数据
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);
return R.ok();
}
/**
* 相册
*
* @email 123456@qq.com
*/
@RestController
@RequestMapping("album")
public class AlbumController extends AbstractController {
@Autowired
private AlbumService albumService;
/**
* 列表
*/
@RequestMapping("/list")
public R list(@RequestParam Map<String, Object> params) {
//查询列表数据
Query query = new Query(params);
List<AlbumEntity> albumList = albumService.queryList(query);
int total = albumService.queryTotal(query);
PageUtils pageUtil = new PageUtils(albumList, total, query.getLimit(), query.getPage());
return R.ok().put("page", pageUtil);
}
/**
* @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);
comment.setCuser(super.getUserId());
comment.setPuser(pic.getUser());
this.commentService.save(comment);
return R.ok();
}
}
/**
* 角色授权菜单
*/
@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);
return R.ok().put("menu", menu);
}
/**
* 保存
*/
@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: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();
}
}
/**
* 上传的文件处理工具类
*
*/
/**
* 上传的文件处理工具类
*
*/
public class MultipartFileUtil {
public static final Logger logger = LoggerFactory.getLogger(MultipartFileUtil.class);
/**
* 根据文件名称获取后缀名
*
* @param fileName 文件名称
* @return 结果
*/
public static String getSuffix(String fileName) {
return fileName.substring(fileName.lastIndexOf(".") + 1);
}
/**
* 获取项目根路径
*
* @return 结果
*/
public static String getRootPath(HttpServletRequest request) {
String classPath = request.getSession().getServletContext().getRealPath( "/" );
String rootPath = "";
//windows下
if ("\\".equals(File.separator)) {
// rootPath = classPath.substring(1, classPath.indexOf("/WEB-INF/classes"));
rootPath = classPath;
rootPath = rootPath.replace("/", "\\");
}
//linux下
if ("/".equals(File.separator)) {
rootPath = classPath.substring(0, classPath.indexOf("/WEB-INF/classes"));
rootPath = rootPath.replace("\\", "/");
}
return rootPath;
}
/**
* 判断文件是否未空,或者没有数据
*
* @param file 文件
* @return 结果
/**
*
*
* @email 123456@qq.com
*/
@RestController
@RequestMapping("comment")
public class CommentController extends AbstractController {
@Autowired
private CommentService commentService;
/**
* 列表
*/
@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);
@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);
// if(!captcha.equalsIgnoreCase(kaptcha)){
// return R.error("验证码不正确");
// }
try {
Subject subject = ShiroUtils.getSubject();
//sha256加密
password = new Sha256Hash(password).toHex();
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("账户验证失败");
* 列表
*/
@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){
* 删除用户
*/
@SysLog("删除用户")
@RequestMapping("/delete")
@RequiresPermissions("sys:user: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();
}
}
/**
// 返回“图像”选项卡并显示图片
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>");
}
}
}
/**
* 角色管理
*
* @email 123456@qq.com
*/
@RestController
@RequestMapping("/sys/role")
public class SysRoleController extends AbstractController {
@Autowired
private SysRoleService sysRoleService;
@Autowired
private SysRoleMenuService sysRoleMenuService;
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("/delete")
public R delete(@RequestBody Long[] ids) {
picService.deleteBatch(ids);
* 选择菜单(添加、修改菜单)
*/
@RequestMapping("/select")
@RequiresPermissions("sys:menu:select")
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);
return R.ok().put("menu", menu);
}
/**
* 保存
*/
@SysLog("保存菜单")