基于javaweb+mysql的ssm食品检测管理系统(java+ssm+javascript+layui+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SSM食品检测管理系统(java+ssm+javascript+layui+mysql)
项目介绍
本项目后台食品检测管理系统; (1)用户管理:用户登录、验证。 (2)任务管理:添加任务、检品受理。 (3)结果审核:上传结果、生成报告。 (4)仪器管理:仪器的使用和管理。 (5)样品管理:仪器的使用和管理。
(6)管理员设置:用户的管理。
技术栈
SSM+mysql+layui+CSS+JavaScript
使用说明
- 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中application.properties配置文件中的数据库配置改为自己的配置; 4. 运行项目,在浏览器中输入http://localhost:8080 访问
if(pageIndex != null){
try{
currentPageNo = Integer.valueOf(pageIndex);
}catch(NumberFormatException e){
return "error";
//总数量(表)
int totalCount = userService.getUserCount(queryUserName,queryUserRole);
//总页数
PageSupport pages=new PageSupport();
pages.setCurrentPageNo(currentPageNo);
pages.setPageSize(pageSize);
}else if(StringUtils.isNullOrEmpty(oldpassword)){//旧密码输入为空
resultMap.put("result", "error");
}else{
String sessionPwd = ((User)o).getUserPassword();
if(oldpassword.equals(sessionPwd)){
resultMap.put("result", "true");
}else{//旧密码输入不正确
resultMap.put("result", "false");
// response.setContentType("application/json");
request.setCharacterEncoding("utf-8");
String id = request.getParameter("uid");
if(!StringUtils.isNullOrEmpty(id)){
//调用后台方法得到user对象
User user = userService.getUserById(id);
System.out.println("------------> "+user);
model.addAttribute("user", user);
return url;
// request.getRequestDispatcher(url).forward(request, response);
return "error";
private void delUser(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String id = request.getParameter("uid");
Integer delId = 0;
try{
用户登录管理控制层:
@Controller
public class LoginServlet{
@Autowired
UserServiceImpl userService;
@Autowired
RoleServiceImpl roleService;
@Autowired
ProviderServiceImpl providerService;
@Autowired
delId = 0;
HashMap<String, String> resultMap = new HashMap<String, String>();
if(delId <= 0){
resultMap.put("delResult", "notexist");
}else{
if(userService.deleteUserById(delId)){
resultMap.put("delResult", "true");
}else{
resultMap.put("delResult", "false");
//把resultMap转换成json对象输出
// response.setContentType("application/json");
request.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
user.setModifyBy(((User)request.getSession().getAttribute(Constants.USER_SESSION)).getId());
user.setModifyDate(new Date());
if(userService.modify(user)){
return "redirect:/user.do?method=query";
// response.sendRedirect(request.getContextPath()+"/jsp/user.do?method=query");
}else{
return "usermodify";
// request.getRequestDispatcher("usermodify.jsp").forward(request, response);
private String getUserById(HttpServletRequest request, HttpServletResponse response, String url, Model model)
throws ServletException, IOException {
String id = request.getParameter("uid");
}System.out.println("111");
user.setCreatedBy(((User)session.getAttribute(Constants.USER_SESSION)).getId());System.out.println("222");
user.setCreationDate(new Date());System.out.println("333");
if(userService.add(user)){return "redirect:/user.do?method=query";}System.out.println("444");
return "useradd";
退出管理控制层:
@Controller
public class LogoutServlet{
@Autowired
UserServiceImpl userService;
@Autowired
RoleServiceImpl roleService;
@Autowired
return "frame";
}else{
//页面跳转(login.jsp)带出提示信息--转发
model.addAttribute("error", "用户名或密码不正确");
return "login";
//.forward(request, response);
用户管理控制层:
@Controller
public class UserServlet{
@Autowired
BillServiceImpl billService;
//把roleList转换成json对象输出
// response.setContentType("application/json");
request.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
PrintWriter outPrintWriter = response.getWriter();
outPrintWriter.write(JSONArray.toJSONString(roleList));
outPrintWriter.flush();
outPrintWriter.close();
private String query(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//查询用户列表
String queryUserName = request.getParameter("queryname");
try{
currentPageNo = Integer.valueOf(pageIndex);
}catch(NumberFormatException e){
return "error";
//总数量(表)
int totalCount = userService.getUserCount(queryUserName,queryUserRole);
//总页数
PageSupport pages=new PageSupport();
pages.setCurrentPageNo(currentPageNo);
pages.setPageSize(pageSize);
pages.setTotalCount(totalCount);
}else if(method != null && method.equals("query")){
return this.query(request, response);
}else if(method != null && method.equals("getrolelist")){
this.getRoleList(request, response);
}else if(method != null && method.equals("ucexist")){
this.userCodeExist(request, response);
}else if(method != null && method.equals("deluser")){
this.delUser(request, response);
}else if(method != null && method.equals("view")){
return this.getUserById(request, response,"userview",model);
}else if(method != null && method.equals("modify")){
return this.getUserById(request, response,"usermodify",model);
resultMap.put("userCode", "notexist");
//把resultMap转为json字符串以json的形式输出
//配置上下文的输出类型
// response.setContentType("application/json");
request.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
//从response对象中获取往外输出的writer对象
PrintWriter outPrintWriter = response.getWriter();
//把resultMap转为json字符串 输出
outPrintWriter.write(JSONArray.toJSONString(resultMap));
outPrintWriter.flush();//刷新
System.out.println("----------> "+userList.get(0).getAge());
request.setAttribute("userList", userList);
List<Role> roleList = null;
System.out.println(userList.get(0).getRole().getRoleName());
roleList = roleService.getRoleList();
System.out.println("===== "+roleList.get(0).getRoleCode()+"--------roleList:"+roleList.get(0).getRoleName());
request.setAttribute("roleList", roleList);
request.setAttribute("queryUserName", queryUserName);
request.setAttribute("queryUserRole", queryUserRole);
request.setAttribute("totalPageCount", totalPageCount);
request.setAttribute("totalCount", totalCount);
return "error";
//总数量(表)
int totalCount = userService.getUserCount(queryUserName,queryUserRole);
//总页数
PageSupport pages=new PageSupport();
pages.setCurrentPageNo(currentPageNo);
pages.setPageSize(pageSize);
pages.setTotalCount(totalCount);
int totalPageCount = pages.getTotalPageCount();
//控制首页和尾页
if(currentPageNo < 1){
currentPageNo = 1;
}else if(currentPageNo > totalPageCount){
request.getSession().setAttribute(Constants.USER_SESSION, user);
//页面跳转(frame.jsp)
return "frame";
}else{
//页面跳转(login.jsp)带出提示信息--转发
model.addAttribute("error", "用户名或密码不正确");
return "login";
//.forward(request, response);
用户管理控制层:
@Controller
public class UserServlet{
@Autowired
BillServiceImpl billService;
if(queryUserName == null){
queryUserName = "";
if(temp != null && !temp.equals("")){
queryUserRole = Integer.parseInt(temp);
if(pageIndex != null){
try{
currentPageNo = Integer.valueOf(pageIndex);
}catch(NumberFormatException e){
return "error";
//总数量(表)
int totalCount = userService.getUserCount(queryUserName,queryUserRole);
//总页数
PageSupport pages=new PageSupport();
pages.setCurrentPageNo(currentPageNo);
request.setAttribute(Constants.SYS_MESSAGE, "修改密码失败!");
}else{
request.setAttribute(Constants.SYS_MESSAGE, "修改密码失败!");
return "pwdmodify";
private void getPwdByUserId(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Object o = request.getSession().getAttribute(Constants.USER_SESSION);
String oldpassword = request.getParameter("oldpassword");
Map<String, String> resultMap = new HashMap<String, String>();
if(null == o ){//session过期
resultMap.put("result", "sessionerror");