赞
踩
作者主页:夜未央5788
简介:Java领域优质创作者、Java项目、学习资料、技术互助
文末获取源码
一款由jsp+ssm(spring+springmvc+mybatis)+mysql实现的垃圾分类查询管理系统,项目包含完整源码和sql脚本。
系统主要实现的功能有:
1:前端垃圾分类查询,前端采用bootstrap框架,自适应设备的。
2:后台菜单管理、角色权限管理、用户管理、日志管理、垃圾分类管理、垃圾管理等功能。
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.是否Maven项目: 否;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目
6.数据库:MySql 5.7版本;
1. 后端:Spring SpringMVC MyBatis
2. 前端:JSP+bootstrap
1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 将项目中db.properties配置文件中的数据库配置改为自己的配置
3. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;
若为maven项目,导入成功后请执行maven clean;maven install命令,配置tomcat,然后运行;
4. 运行项目,输入localhost:8080/ 登录
- package com.ischoolbar.programmer.controller.home;
-
- import java.awt.image.BufferedImage;
- import java.io.IOException;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
-
- import javax.imageio.ImageIO;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import javax.servlet.http.HttpSession;
-
- import org.apache.commons.lang.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Controller;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import org.springframework.web.bind.annotation.RequestParam;
- import org.springframework.web.bind.annotation.ResponseBody;
- import org.springframework.web.servlet.ModelAndView;
-
- import com.ischoolbar.programmer.entity.admin.Authority;
- import com.ischoolbar.programmer.entity.admin.Menu;
- import com.ischoolbar.programmer.entity.admin.Role;
- import com.ischoolbar.programmer.entity.admin.Rubbish;
- import com.ischoolbar.programmer.entity.admin.RubbishCategory;
- import com.ischoolbar.programmer.entity.admin.User;
- import com.ischoolbar.programmer.service.admin.AuthorityService;
- import com.ischoolbar.programmer.service.admin.LogService;
- import com.ischoolbar.programmer.service.admin.MenuService;
- import com.ischoolbar.programmer.service.admin.RoleService;
- import com.ischoolbar.programmer.service.admin.RubbishCategoryService;
- import com.ischoolbar.programmer.service.admin.RubbishService;
- import com.ischoolbar.programmer.service.admin.UserService;
- import com.ischoolbar.programmer.util.CpachaUtil;
- import com.ischoolbar.programmer.util.MenuUtil;
-
- /**
- * 系统操作类控制器
- * @author llq
- *
- */
- @Controller
- @RequestMapping("/home")
- public class HomeController {
-
- @Autowired
- private RubbishCategoryService rubbishCategoryService;
-
- @Autowired
- private RubbishService rubbishService;
-
- /**
- * 系统登录后的主页
- * @param model
- * @return
- */
- @RequestMapping(value="/index",method=RequestMethod.GET)
- public ModelAndView index(ModelAndView model){
- model.setViewName("home/index");
- return model;//WEB-INF/views/+system/index+.jsp = WEB-INF/views/system/index.jsp
- }
-
- /**
- * 系统登录后的欢迎页
- * @param model
- * @return
- */
- @RequestMapping(value="/search",method=RequestMethod.GET)
- public ModelAndView search(@RequestParam(name="k",required=false,defaultValue="") String name,ModelAndView model){
- RubbishCategory rubbishCategory = null;
- if(!StringUtils.isEmpty(name)){
- //先查询垃圾表
- List<Rubbish> rubbishList = rubbishService.findByName(name);
- if(rubbishList != null && rubbishList.size() > 0){
- rubbishCategory = rubbishList.get(0).getRubbishCategory();
- }else{
- //若垃圾表未查询到,再查询分类表
- List<RubbishCategory> rubbishCategoryList = rubbishCategoryService.findByCommon(name);
- if(rubbishCategoryList != null && rubbishCategoryList.size() > 0)
- rubbishCategory = rubbishCategoryList.get(0);
- }
- }
- model.addObject("k", name);
- model.addObject("rubbishCategory", rubbishCategory);
- model.setViewName("home/search");
- return model;
- }
-
- }
- package com.ischoolbar.programmer.controller.admin;
-
- import java.util.Date;
- import java.util.HashMap;
- import java.util.Map;
-
- import org.apache.commons.lang.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Controller;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import org.springframework.web.bind.annotation.RequestParam;
- import org.springframework.web.bind.annotation.ResponseBody;
- import org.springframework.web.servlet.ModelAndView;
-
- import com.ischoolbar.programmer.entity.admin.Log;
- import com.ischoolbar.programmer.page.admin.Page;
- import com.ischoolbar.programmer.service.admin.LogService;
-
- /**
- *
- * @author llq
- *
- */
- @RequestMapping("/admin/news")
- @Controller
- public class NewsController {
-
- @Autowired
- private LogService logService;
-
- @RequestMapping(value="/list",method=RequestMethod.GET)
- public ModelAndView list(ModelAndView model){
- model.setViewName("news/list");
- return model;
- }
-
- /**
- * 获取日志列表
- * @param page
- * @param content
- * @param roleId
- * @param sex
- * @return
- */
- @RequestMapping(value="/list",method=RequestMethod.POST)
- @ResponseBody
- public Map<String, Object> getList(Page page,
- @RequestParam(name="content",required=false,defaultValue="") String content
- ){
- Map<String, Object> ret = new HashMap<String, Object>();
- Map<String, Object> queryMap = new HashMap<String, Object>();
- queryMap.put("content", content);
- queryMap.put("offset", page.getOffset());
- queryMap.put("pageSize", page.getRows());
- ret.put("rows", logService.findList(queryMap));
- ret.put("total", logService.getTotal(queryMap));
- return ret;
- }
-
- /**
- * 添加日志
- * @param user
- * @return
- */
- @RequestMapping(value="/add",method=RequestMethod.POST)
- @ResponseBody
- public Map<String, String> add(Log log){
- Map<String, String> ret = new HashMap<String, String>();
- if(log == null){
- ret.put("type", "error");
- ret.put("msg", "请填写正确的日志信息!");
- return ret;
- }
- if(StringUtils.isEmpty(log.getContent())){
- ret.put("type", "error");
- ret.put("msg", "请填写日志内容!");
- return ret;
- }
- log.setCreateTime(new Date());
- if(logService.add(log) <= 0){
- ret.put("type", "error");
- ret.put("msg", "日志添加失败,请联系管理员!");
- return ret;
- }
- ret.put("type", "success");
- ret.put("msg", "日志添加成功!");
- return ret;
- }
-
-
-
- /**
- * 批量删除日志
- * @param ids
- * @return
- */
- @RequestMapping(value="/delete",method=RequestMethod.POST)
- @ResponseBody
- public Map<String, String> delete(String ids){
- Map<String, String> ret = new HashMap<String, String>();
- if(StringUtils.isEmpty(ids)){
- ret.put("type", "error");
- ret.put("msg", "选择要删除的数据!");
- return ret;
- }
- if(ids.contains(",")){
- ids = ids.substring(0,ids.length()-1);
- }
- if(logService.delete(ids) <= 0){
- ret.put("type", "error");
- ret.put("msg", "日志删除失败,请联系管理员!");
- return ret;
- }
- ret.put("type", "success");
- ret.put("msg", "日志删除成功!");
- return ret;
- }
- }
- package com.ischoolbar.programmer.controller.admin;
-
- import java.util.HashMap;
- import java.util.Map;
-
- import org.apache.commons.lang.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Controller;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import org.springframework.web.bind.annotation.RequestParam;
- import org.springframework.web.bind.annotation.ResponseBody;
- import org.springframework.web.servlet.ModelAndView;
-
- import com.ischoolbar.programmer.entity.admin.Rubbish;
- import com.ischoolbar.programmer.page.admin.Page;
- import com.ischoolbar.programmer.service.admin.RubbishCategoryService;
- import com.ischoolbar.programmer.service.admin.RubbishService;
-
- /**
- * 垃圾管理控制器
- * @author llq
- *
- */
- @RequestMapping("/admin/rubbish")
- @Controller
- public class RubbishController {
- @Autowired
- private RubbishCategoryService rubbishCategoryService;
- @Autowired
- private RubbishService rubbishService;
-
- /**
- * 垃圾列表页面
- * @param model
- * @return
- */
- @RequestMapping(value="/list",method=RequestMethod.GET)
- public ModelAndView list(ModelAndView model){
- model.addObject("rubbishCategoryList", rubbishCategoryService.findList(null));
- model.setViewName("rubbish/list");
- return model;
- }
-
- /**
- * 获取垃圾列表
- * @param page
- * @param name
- * @param roleId
- * @param sex
- * @return
- */
- @RequestMapping(value="/list",method=RequestMethod.POST)
- @ResponseBody
- public Map<String, Object> getList(Page page,
- @RequestParam(name="name",required=false,defaultValue="") String name,
- Long categoryId
- ){
- Map<String, Object> ret = new HashMap<String, Object>();
- Map<String, Object> queryMap = new HashMap<String, Object>();
- if(categoryId != null){
- queryMap.put("categoryId", categoryId);
- }
- queryMap.put("name", name);
- queryMap.put("offset", page.getOffset());
- queryMap.put("pageSize", page.getRows());
- ret.put("rows", rubbishService.findList(queryMap));
- ret.put("total", rubbishService.getTotal(queryMap));
- return ret;
- }
-
- /**
- * 添加垃圾
- * @param rubbish
- * @return
- */
- @RequestMapping(value="/add",method=RequestMethod.POST)
- @ResponseBody
- public Map<String, String> add(Rubbish rubbish){
- Map<String, String> ret = new HashMap<String, String>();
- if(rubbish == null){
- ret.put("type", "error");
- ret.put("msg", "请填写正确的垃圾信息!");
- return ret;
- }
- if(StringUtils.isEmpty(rubbish.getName())){
- ret.put("type", "error");
- ret.put("msg", "请填写垃圾名!");
- return ret;
- }
- if(rubbishService.add(rubbish) <= 0){
- ret.put("type", "error");
- ret.put("msg", "垃圾添加失败,请联系管理员!");
- return ret;
- }
- ret.put("type", "success");
- ret.put("msg", "添加成功!");
- return ret;
- }
-
- /**
- * 编辑垃圾
- * @param rubbish
- * @return
- */
- @RequestMapping(value="/edit",method=RequestMethod.POST)
- @ResponseBody
- public Map<String, String> edit(Rubbish rubbish){
- Map<String, String> ret = new HashMap<String, String>();
- if(rubbish == null){
- ret.put("type", "error");
- ret.put("msg", "请填写正确的垃圾信息!");
- return ret;
- }
- if(StringUtils.isEmpty(rubbish.getName())){
- ret.put("type", "error");
- ret.put("msg", "请填写垃圾名!");
- return ret;
- }
-
- if(rubbishService.edit(rubbish) <= 0){
- ret.put("type", "error");
- ret.put("msg", "垃圾添加失败,请联系管理员!");
- return ret;
- }
- ret.put("type", "success");
- ret.put("msg", "编辑成功!");
- return ret;
- }
-
- /**
- * 批量删除垃圾
- * @param id
- * @return
- */
- @RequestMapping(value="/delete",method=RequestMethod.POST)
- @ResponseBody
- public Map<String, String> delete(Long id){
- Map<String, String> ret = new HashMap<String, String>();
- if(id == null){
- ret.put("type", "error");
- ret.put("msg", "选择要删除的数据!");
- return ret;
- }
- try {
- if(rubbishService.delete(id) <= 0){
- ret.put("type", "error");
- ret.put("msg", "垃圾删除失败,请联系管理员!");
- return ret;
- }
- } catch (Exception e) {
- // TODO: handle exception
- ret.put("type", "error");
- ret.put("msg", "该垃圾下存在垃圾,请先删除垃圾!");
- return ret;
- }
- ret.put("type", "success");
- ret.put("msg", "垃圾删除成功!");
- return ret;
- }
-
- }
- package com.ischoolbar.programmer.controller.admin;
-
- import java.awt.image.BufferedImage;
- import java.io.IOException;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
-
- import javax.imageio.ImageIO;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import javax.servlet.http.HttpSession;
-
- import org.apache.commons.lang.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Controller;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import org.springframework.web.bind.annotation.RequestParam;
- import org.springframework.web.bind.annotation.ResponseBody;
- import org.springframework.web.servlet.ModelAndView;
-
- import com.ischoolbar.programmer.entity.admin.Authority;
- import com.ischoolbar.programmer.entity.admin.Menu;
- import com.ischoolbar.programmer.entity.admin.Role;
- import com.ischoolbar.programmer.entity.admin.User;
- import com.ischoolbar.programmer.service.admin.AuthorityService;
- import com.ischoolbar.programmer.service.admin.LogService;
- import com.ischoolbar.programmer.service.admin.MenuService;
- import com.ischoolbar.programmer.service.admin.RoleService;
- import com.ischoolbar.programmer.service.admin.UserService;
- import com.ischoolbar.programmer.util.CpachaUtil;
- import com.ischoolbar.programmer.util.MenuUtil;
-
- /**
- * 系统操作类控制器
- * @author llq
- *
- */
- @Controller
- @RequestMapping("/system")
- public class SystemController {
-
- @Autowired
- private UserService userService;
-
- @Autowired
- private RoleService roleService;
-
- @Autowired
- private AuthorityService authorityService;
-
- @Autowired
- private MenuService menuService;
-
- @Autowired
- private LogService logService;
-
- /**
- * 系统登录后的主页
- * @param model
- * @return
- */
- @RequestMapping(value="/index",method=RequestMethod.GET)
- public ModelAndView index(ModelAndView model,HttpServletRequest request){
- List<Menu> userMenus = (List<Menu>)request.getSession().getAttribute("userMenus");
- model.addObject("topMenuList", MenuUtil.getAllTopMenu(userMenus));
- model.addObject("secondMenuList", MenuUtil.getAllSecondMenu(userMenus));
- model.setViewName("system/index");
- return model;//WEB-INF/views/+system/index+.jsp = WEB-INF/views/system/index.jsp
- }
-
- /**
- * 系统登录后的欢迎页
- * @param model
- * @return
- */
- @RequestMapping(value="/welcome",method=RequestMethod.GET)
- public ModelAndView welcome(ModelAndView model){
- model.setViewName("system/welcome");
- return model;
- }
- /**
- * 登陆页面
- * @param model
- * @return
- */
- @RequestMapping(value="/login",method=RequestMethod.GET)
- public ModelAndView login(ModelAndView model){
- model.setViewName("system/login");
- return model;
- }
-
- /**
- * 登录表单提交处理控制器
- * @param user
- * @param cpacha
- * @return
- */
- @RequestMapping(value="/login",method=RequestMethod.POST)
- @ResponseBody
- public Map<String, String> loginAct(User user,String cpacha,HttpServletRequest request){
- Map<String, String> ret = new HashMap<String, String>();
- if(user == null){
- ret.put("type", "error");
- ret.put("msg", "请填写用户信息!");
- return ret;
- }
- if(StringUtils.isEmpty(cpacha)){
- ret.put("type", "error");
- ret.put("msg", "请填写验证码!");
- return ret;
- }
- if(StringUtils.isEmpty(user.getUsername())){
- ret.put("type", "error");
- ret.put("msg", "请填写用户名!");
- return ret;
- }
- if(StringUtils.isEmpty(user.getPassword())){
- ret.put("type", "error");
- ret.put("msg", "请填写密码!");
- return ret;
- }
- Object loginCpacha = request.getSession().getAttribute("loginCpacha");
- if(loginCpacha == null){
- ret.put("type", "error");
- ret.put("msg", "会话超时,请刷新页面!");
- return ret;
- }
- if(!cpacha.toUpperCase().equals(loginCpacha.toString().toUpperCase())){
- ret.put("type", "error");
- ret.put("msg", "验证码错误!");
- logService.add("用户名为"+user.getUsername()+"的用户登录时输入验证码错误!");
- return ret;
- }
- User findByUsername = userService.findByUsername(user.getUsername());
- if(findByUsername == null){
- ret.put("type", "error");
- ret.put("msg", "该用户名不存在!");
- logService.add("登录时,用户名为"+user.getUsername()+"的用户不存在!");
- return ret;
- }
- if(!user.getPassword().equals(findByUsername.getPassword())){
- ret.put("type", "error");
- ret.put("msg", "密码错误!");
- logService.add("用户名为"+user.getUsername()+"的用户登录时输入密码错误!");
- return ret;
- }
- //说明用户名密码及验证码都正确
- //此时需要查询用户的角色权限
- Role role = roleService.find(findByUsername.getRoleId());
- List<Authority> authorityList = authorityService.findListByRoleId(role.getId());//根据角色获取权限列表
- String menuIds = "";
- for(Authority authority:authorityList){
- menuIds += authority.getMenuId() + ",";
- }
- if(!StringUtils.isEmpty(menuIds)){
- menuIds = menuIds.substring(0,menuIds.length()-1);
- }
- List<Menu> userMenus = menuService.findListByIds(menuIds);
- //把角色信息、菜单信息放到session中
- request.getSession().setAttribute("admin", findByUsername);
- request.getSession().setAttribute("role", role);
- request.getSession().setAttribute("userMenus", userMenus);
- ret.put("type", "success");
- ret.put("msg", "登录成功!");
- logService.add("用户名为{"+user.getUsername()+"},角色为{"+role.getName()+"}的用户登录成功!");
- return ret;
- }
-
- /**
- * 后台退出注销功能
- * @param request
- * @return
- */
- @RequestMapping(value="/logout",method=RequestMethod.GET)
- public String logout(HttpServletRequest request){
- HttpSession session = request.getSession();
- session.setAttribute("admin", null);
- session.setAttribute("role", null);
- request.getSession().setAttribute("userMenus", null);
- return "redirect:login";
- }
-
- /**
- * 修改密码页面
- * @param model
- * @return
- */
- @RequestMapping(value="/edit_password",method=RequestMethod.GET)
- public ModelAndView editPassword(ModelAndView model){
- model.setViewName("system/edit_password");
- return model;
- }
-
- @RequestMapping(value="/edit_password",method=RequestMethod.POST)
- @ResponseBody
- public Map<String, String> editPasswordAct(String newpassword,String oldpassword,HttpServletRequest request){
- Map<String, String> ret = new HashMap<String, String>();
- if(StringUtils.isEmpty(newpassword)){
- ret.put("type", "error");
- ret.put("msg", "请填写新密码!");
- return ret;
- }
- User user = (User)request.getSession().getAttribute("admin");
- if(!user.getPassword().equals(oldpassword)){
- ret.put("type", "error");
- ret.put("msg", "原密码错误!");
- return ret;
- }
- user.setPassword(newpassword);
- if(userService.editPassword(user) <= 0){
- ret.put("type", "error");
- ret.put("msg", "密码修改失败,请联系管理员!");
- return ret;
- }
- ret.put("type", "success");
- ret.put("msg", "密码修改成功!");
- logService.add("用户名为{"+user.getUsername()+"},的用户成功修改密码!");
- return ret;
- }
-
- /**
- * 本系统所有的验证码均采用此方法
- * @param vcodeLen
- * @param width
- * @param height
- * @param cpachaType:用来区别验证码的类型,传入字符串
- * @param request
- * @param response
- */
- @RequestMapping(value="/get_cpacha",method=RequestMethod.GET)
- public void generateCpacha(
- @RequestParam(name="vl",required=false,defaultValue="4") Integer vcodeLen,
- @RequestParam(name="w",required=false,defaultValue="100") Integer width,
- @RequestParam(name="h",required=false,defaultValue="30") Integer height,
- @RequestParam(name="type",required=true,defaultValue="loginCpacha") String cpachaType,
- HttpServletRequest request,
- HttpServletResponse response){
- CpachaUtil cpachaUtil = new CpachaUtil(vcodeLen, width, height);
- String generatorVCode = cpachaUtil.generatorVCode();
- request.getSession().setAttribute(cpachaType, generatorVCode);
- BufferedImage generatorRotateVCodeImage = cpachaUtil.generatorRotateVCodeImage(generatorVCode, true);
- try {
- ImageIO.write(generatorRotateVCodeImage, "gif", response.getOutputStream());
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
如果也想学习本系统,下面领取。关注并回复:045ssm
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。