基于javaweb和mysql的springboot+mybatis药店医药信息管理系统(JavaWeb JSP MySQL Servlet SSM SpringBoot Bootstrap)
·
基于javaweb和mysql的springboot+mybatis药店医药信息管理系统(JavaWeb JSP MySQL Servlet SSM SpringBoot Bootstrap)
私信源码获取及调试交流
私信源码获取及调试交流
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
技术框架
JavaBean MVC JSP SpringBoot MyBatis MySQL CSS JavaScript Bootstrap
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
登录、注册、退出、用户模块、公告模块、员工模块、进货模块、药品模块的增删改查管理
eclipse/MyEclipse运行:
idea运行:
/**
* 增加员工
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("employeeAdd")
public void add(Employee vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
vo.setCreateBy(((com.demo.vo.User) request.getSession().getAttribute("loginUser")).getId());
//调用Service层的增加(insert)方法
employeeService.insert(vo);
this.redirectList(request, response);
}
/**
* 删除员工
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("employeeDelete")
public void delete(HttpServletResponse response, HttpServletRequest request) throws IOException {
Serializable id = request.getParameter("id");
employeeService.delete(Arrays.asList(id));
this.redirectList(request, response);
}
/**
* 编辑员工
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("employeeEdit")
public void edit(Employee vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
employeeService.update(vo);
this.redirectList(request, response);
}
/**
* 获取员工的详细信息(详情页面与编辑页面要显示该员工的详情)并跳转回页面
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping({"employeeGet", "employeeEditPre"})
public void get(HttpServletResponse response, HttpServletRequest request) throws IOException {
Serializable id = request.getParameter("id");//取出主键id
Employee vo = employeeService.get(id);
String keyword = request.getParameter("keyword");
Map<String, Object> params = new HashMap();//用来保存控制层传进来的参数(查询条件)
params.put("searchColumn", searchColumn);//要查询的列
params.put("keyword", keyword/*keyword != null ? new String(keyword.getBytes("ISO-8859-1"), "UTF-8") : null*/);//查询的关键字
//User loginUser = (User) request.getSession().getAttribute("loginUser");
//if (!"管理员".equals(loginUser.getUserType())) {
// params.put("createBy", loginUser.getId());
//}
Map<String, Object> map = incomeService.list(params);
request.getSession().setAttribute("list", map.get("list"));
Integer totalRecord = (Integer) map.get("totalCount");//根据查询条件取出对应的总记录数,用于分页
String pageNum = request.getParameter("pageNum");//封装分页参数
com.demo.util.PageBean<Object> pb = new com.demo.util.PageBean(Integer.valueOf(pageNum != null ? pageNum : "1"), totalRecord);
params.put("startIndex", pb.getStartIndex());
params.put("pageSize", pb.getPageSize());
List list = (List) incomeService.list(params).get("list");//根据分页参数startIndex、pageSize查询出来的最终结果list
pb.setServlet("incomeList");
pb.setSearchColumn(searchColumn);
pb.setKeyword(keyword);
pb.setList(list);
request.getSession().setAttribute("pageBean", pb);
request.getSession().setAttribute("list", pb.getList());
response.sendRedirect("income_list.jsp");
}
}
@Controller
@Controller
@RequestMapping
public class EmployeeController {
@Autowired
private EmployeeService employeeService;
/**
* 增加员工
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("employeeAdd")
public void add(Employee vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
vo.setCreateBy(((com.demo.vo.User) request.getSession().getAttribute("loginUser")).getId());
//调用Service层的增加(insert)方法
employeeService.insert(vo);
this.redirectList(request, response);
}
/**
* 删除员工
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("employeeDelete")
public void delete(HttpServletResponse response, HttpServletRequest request) throws IOException {
Serializable id = request.getParameter("id");
employeeService.delete(Arrays.asList(id));
this.redirectList(request, response);
}
/**
* 编辑员工
*
* @param response
* @param request
* @throws IOException
}
/**
* 获取员工的详细信息(详情页面与编辑页面要显示该员工的详情)并跳转回页面
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping({"employeeGet", "employeeEditPre"})
public void get(HttpServletResponse response, HttpServletRequest request) throws IOException {
Serializable id = request.getParameter("id");//取出主键id
Employee vo = employeeService.get(id);
request.getSession().setAttribute("vo", vo);
String to = request.getRequestURI().toLowerCase().contains("get") ? "info" : "edit";//判断是去详情显示页面还是编辑页面
response.sendRedirect("employee_" + to + ".jsp");
}
/**
* 根据条件查询员工的列表并跳转回页面
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("employeeList")
public void list(HttpServletResponse response, HttpServletRequest request) throws IOException {
this.redirectList(request, response);
}
/**
* 跳转到列表页面
*
* @param request
* @param response
*/
private void redirectList(HttpServletRequest request, HttpServletResponse response) throws IOException {
//查询列和关键字
String searchColumn = request.getParameter("searchColumn");
String keyword = request.getParameter("keyword");
Map<String, Object> params = new HashMap();//用来保存控制层传进来的参数(查询条件)
params.put("searchColumn", searchColumn);//要查询的列
params.put("keyword", keyword/*keyword != null ? new String(keyword.getBytes("ISO-8859-1"), "UTF-8") : null*/);//查询的关键字
@Controller
public class AuthController extends HttpServlet {
@Autowired
private UserService userService;
@RequestMapping("authLogin")
public void login(HttpServletResponse response, HttpServletRequest request) throws IOException, ServletException {
String username = request.getParameter("username");
String password = request.getParameter("password");
String validationCode = request.getParameter("validationCode");
if (validationCode != null && !validationCode.equals(request.getSession().getAttribute("validationCode"))) {//验证码不通过
request.getSession().setAttribute("alert_msg", "错误:验证码不正确!");
request.getRequestDispatcher("login.jsp").forward(request, response);
return;
}
Map<String, Object> params = new HashMap();
int green = minColor + random.nextInt(maxColor - minColor);
// 获得蓝色的随机颜色值
int blue = minColor + random.nextInt(maxColor - minColor);
return new Color(red, green, blue);
}
}
@Controller
@RequestMapping
public class EmployeeController {
@Autowired
private EmployeeService employeeService;
/**
* 增加员工
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("employeeAdd")
public void add(Employee vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
vo.setCreateBy(((com.demo.vo.User) request.getSession().getAttribute("loginUser")).getId());
//调用Service层的增加(insert)方法
employeeService.insert(vo);
this.redirectList(request, response);
}
/**
* 删除员工
*
* @param response
* @param request
* @throws IOException
* @param response
*/
private void redirectList(HttpServletRequest request, HttpServletResponse response) throws IOException {
//查询列和关键字
String searchColumn = request.getParameter("searchColumn");
String keyword = request.getParameter("keyword");
Map<String, Object> params = new HashMap();//用来保存控制层传进来的参数(查询条件)
params.put("searchColumn", searchColumn);//要查询的列
params.put("keyword", keyword/*keyword != null ? new String(keyword.getBytes("ISO-8859-1"), "UTF-8") : null*/);//查询的关键字
Map<String, Object> map = noticeService.list(params);
request.getSession().setAttribute("list", map.get("list"));
Integer totalRecord = (Integer) map.get("totalCount");//根据查询条件取出对应的总记录数,用于分页
String pageNum = request.getParameter("pageNum");//封装分页参数
com.demo.util.PageBean<Object> pb = new com.demo.util.PageBean(Integer.valueOf(pageNum != null ? pageNum : "1"), totalRecord);
params.put("startIndex", pb.getStartIndex());
params.put("pageSize", pb.getPageSize());
List list = (List) noticeService.list(params).get("list");//根据分页参数startIndex、pageSize查询出来的最终结果list
pb.setServlet("noticeList");
pb.setSearchColumn(searchColumn);
pb.setKeyword(keyword);
pb.setList(list);
request.getSession().setAttribute("pageBean", pb);
request.getSession().setAttribute("list", pb.getList());
response.sendRedirect("notice_list.jsp");
}
}
@Configuration
public class CustomWebMvcConfigurer implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/*");
}
public class LoginInterceptor implements HandlerInterceptor {
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object o) throws Exception {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
HttpSession session = request.getSession();
//移除错误提示
* @param response
* @param request
* @throws IOException
*/
@RequestMapping({"incomeGet", "incomeEditPre"})
public void get(HttpServletResponse response, HttpServletRequest request) throws IOException {
Serializable id = request.getParameter("id");//取出主键id
Income vo = incomeService.get(id);
request.getSession().setAttribute("vo", vo);
String to = request.getRequestURI().toLowerCase().contains("get") ? "info" : "edit";//判断是去详情显示页面还是编辑页面
response.sendRedirect("income_" + to + ".jsp");
}
/**
* 根据条件查询进货的列表并跳转回页面
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("incomeList")
public void list(HttpServletResponse response, HttpServletRequest request) throws IOException {
this.redirectList(request, response);
}
/**
* 跳转到列表页面
*
* @param request
* @param response
*/
private void redirectList(HttpServletRequest request, HttpServletResponse response) throws IOException {
//查询列和关键字
String searchColumn = request.getParameter("searchColumn");
String keyword = request.getParameter("keyword");
Map<String, Object> params = new HashMap();//用来保存控制层传进来的参数(查询条件)
params.put("searchColumn", searchColumn);//要查询的列
params.put("keyword", keyword/*keyword != null ? new String(keyword.getBytes("ISO-8859-1"), "UTF-8") : null*/);//查询的关键字
//User loginUser = (User) request.getSession().getAttribute("loginUser");
//if (!"管理员".equals(loginUser.getUserType())) {
// params.put("createBy", loginUser.getId());
//}
Map<String, Object> map = incomeService.list(params);
request.getSession().setAttribute("list", map.get("list"));
Integer totalRecord = (Integer) map.get("totalCount");//根据查询条件取出对应的总记录数,用于分页
String pageNum = request.getParameter("pageNum");//封装分页参数
com.demo.util.PageBean<Object> pb = new com.demo.util.PageBean(Integer.valueOf(pageNum != null ? pageNum : "1"), totalRecord);
params.put("startIndex", pb.getStartIndex());
params.put("pageSize", pb.getPageSize());
*
* @param request
* @param response
*/
private void redirectList(HttpServletRequest request, HttpServletResponse response) throws IOException {
//查询列和关键字
String searchColumn = request.getParameter("searchColumn");
String keyword = request.getParameter("keyword");
Map<String, Object> params = new HashMap();//用来保存控制层传进来的参数(查询条件)
params.put("searchColumn", searchColumn);//要查询的列
params.put("keyword", keyword/*keyword != null ? new String(keyword.getBytes("ISO-8859-1"), "UTF-8") : null*/);//查询的关键字
//User loginUser = (User) request.getSession().getAttribute("loginUser");
//if (!"管理员".equals(loginUser.getUserType())) {
// params.put("createBy", loginUser.getId());
//}
Map<String, Object> map = employeeService.list(params);
request.getSession().setAttribute("list", map.get("list"));
Integer totalRecord = (Integer) map.get("totalCount");//根据查询条件取出对应的总记录数,用于分页
String pageNum = request.getParameter("pageNum");//封装分页参数
com.demo.util.PageBean<Object> pb = new com.demo.util.PageBean(Integer.valueOf(pageNum != null ? pageNum : "1"), totalRecord);
params.put("startIndex", pb.getStartIndex());
params.put("pageSize", pb.getPageSize());
List list = (List) employeeService.list(params).get("list");//根据分页参数startIndex、pageSize查询出来的最终结果list
pb.setServlet("employeeList");
pb.setSearchColumn(searchColumn);
pb.setKeyword(keyword);
pb.setList(list);
request.getSession().setAttribute("pageBean", pb);
request.getSession().setAttribute("list", pb.getList());
response.sendRedirect("employee_list.jsp");
}
}
@Controller
@RequestMapping
public class IncomeController {
@Autowired
private IncomeService incomeService;
/**
* 增加进货
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("incomeAdd")
public void add(Income vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
vo.setCreateBy(((com.demo.vo.User) request.getSession().getAttribute("loginUser")).getId());
//调用Service层的增加(insert)方法
incomeService.insert(vo);
this.redirectList(request, response);
}
/**
* 删除进货
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("incomeDelete")
public void delete(HttpServletResponse response, HttpServletRequest request) throws IOException {
Serializable id = request.getParameter("id");
incomeService.delete(Arrays.asList(id));
// 这三条语句都可以关闭浏览器的缓冲区,但是由于浏览器的版本不同,对这三条语句的支持也不同
// 因此,为了保险起见,建议同时使用这三条语句来关闭浏览器的缓冲区
response.setHeader("ragma", "No-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
// 设置图形验证码的长和宽(图形的大小)
int width = 90, height = 20;
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();// 获得用于输出文字的Graphics对象
Random random = new Random();
g.setColor(getRandomColor(180, 250));// 随机设置要填充的颜色
g.fillRect(0, 0, width, height);// 填充图形背景
// 设置初始字体
g.setFont(new Font("Times New Roman", Font.ITALIC, height));
g.setColor(getRandomColor(120, 180));// 随机设置字体颜色
// 用于保存最后随机生成的验证码
StringBuilder validationCode = new StringBuilder();
// 验证码的随机字体
String[] fontNames = {"Times New Roman", "Book antiqua", "Arial"};
for (int i = 0; i < 4; i++) {
// 随机设置当前验证码的字符的字体
g.setFont(new Font(fontNames[random.nextInt(3)], Font.ITALIC, height));
// 随机获得当前验证码的字符
char codeChar = codeChars.charAt(random.nextInt(charsLength));
validationCode.append(codeChar);
// 随机设置当前验证码字符的颜色
g.setColor(getRandomColor(10, 100));
// 在图形上输出验证码字符,x和y都是随机生成的
g.drawString(String.valueOf(codeChar), 16 * i + random.nextInt(7), height - random.nextInt(6));
}
HttpSession session = request.getSession();
session.setMaxInactiveInterval(5 * 60);
// 将验证码保存在session对象中,key为validation_code
session.setAttribute("validationCode", validationCode.toString());
g.dispose();// 关闭Graphics对象
OutputStream os = response.getOutputStream();
ImageIO.write(image, "JPEG", os);// 以JPEG格式向客户端发送图形验证码
}
@RequestMapping("authResetPassword")
public void resetPassword(HttpServletResponse response, HttpServletRequest request) throws IOException, ServletException {
String msg;
User loginUser = (User) request.getSession().getAttribute("loginUser");
String oldPassword = request.getParameter("oldPassword");
if (!loginUser.getPassword().equals(oldPassword)) {
msg = "原密码错误!";
} else {
String newPassword = request.getParameter("newPassword");
loginUser.setPassword(newPassword);
this.userService.update(loginUser);
msg = "修改成功!";
}
* 根据条件查询公告的列表并跳转回页面
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("noticeList")
public void list(HttpServletResponse response, HttpServletRequest request) throws IOException {
this.redirectList(request, response);
}
/**
* 跳转到列表页面
*
* @param request
* @param response
*/
private void redirectList(HttpServletRequest request, HttpServletResponse response) throws IOException {
//查询列和关键字
String searchColumn = request.getParameter("searchColumn");
String keyword = request.getParameter("keyword");
Map<String, Object> params = new HashMap();//用来保存控制层传进来的参数(查询条件)
params.put("searchColumn", searchColumn);//要查询的列
params.put("keyword", keyword/*keyword != null ? new String(keyword.getBytes("ISO-8859-1"), "UTF-8") : null*/);//查询的关键字
Map<String, Object> map = noticeService.list(params);
request.getSession().setAttribute("list", map.get("list"));
Integer totalRecord = (Integer) map.get("totalCount");//根据查询条件取出对应的总记录数,用于分页
String pageNum = request.getParameter("pageNum");//封装分页参数
com.demo.util.PageBean<Object> pb = new com.demo.util.PageBean(Integer.valueOf(pageNum != null ? pageNum : "1"), totalRecord);
params.put("startIndex", pb.getStartIndex());
params.put("pageSize", pb.getPageSize());
List list = (List) noticeService.list(params).get("list");//根据分页参数startIndex、pageSize查询出来的最终结果list
pb.setServlet("noticeList");
pb.setSearchColumn(searchColumn);
pb.setKeyword(keyword);
pb.setList(list);
request.getSession().setAttribute("pageBean", pb);
request.getSession().setAttribute("list", pb.getList());
response.sendRedirect("notice_list.jsp");
}
@Controller
@RequestMapping
public class EmployeeController {
@Autowired
private EmployeeService employeeService;
/**
* 增加员工
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("employeeAdd")
public void add(Employee vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
vo.setCreateBy(((com.demo.vo.User) request.getSession().getAttribute("loginUser")).getId());
//调用Service层的增加(insert)方法
employeeService.insert(vo);
this.redirectList(request, response);
}
/**
@Controller
@RequestMapping
public class IncomeController {
@Autowired
private IncomeService incomeService;
/**
* 增加进货
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("incomeAdd")
public void add(Income vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
vo.setCreateBy(((com.demo.vo.User) request.getSession().getAttribute("loginUser")).getId());
//调用Service层的增加(insert)方法
incomeService.insert(vo);
this.redirectList(request, response);
}
/**
* 删除进货
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("incomeDelete")
public void delete(HttpServletResponse response, HttpServletRequest request) throws IOException {
Serializable id = request.getParameter("id");
incomeService.delete(Arrays.asList(id));
this.redirectList(request, response);
}
@RequestMapping("medicineDelete")
public void delete(HttpServletResponse response, HttpServletRequest request) throws IOException {
Serializable id = request.getParameter("id");
medicineService.delete(Arrays.asList(id));
this.redirectList(request, response);
}
/**
* 编辑药品
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("medicineEdit")
public void edit(Medicine vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
medicineService.update(vo);
this.redirectList(request, response);
}
/**
* 获取药品的详细信息(详情页面与编辑页面要显示该药品的详情)并跳转回页面
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping({"medicineGet", "medicineEditPre"})
public void get(HttpServletResponse response, HttpServletRequest request) throws IOException {
Serializable id = request.getParameter("id");//取出主键id
Medicine vo = medicineService.get(id);
request.getSession().setAttribute("vo", vo);
String to = request.getRequestURI().toLowerCase().contains("get") ? "info" : "edit";//判断是去详情显示页面还是编辑页面
response.sendRedirect("medicine_" + to + ".jsp");
}
/**
* 根据条件查询药品的列表并跳转回页面
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("medicineList")
public void list(HttpServletResponse response, HttpServletRequest request) throws IOException {
this.redirectList(request, response);
}
Serializable id = request.getParameter("id");//取出主键id
Income vo = incomeService.get(id);
request.getSession().setAttribute("vo", vo);
String to = request.getRequestURI().toLowerCase().contains("get") ? "info" : "edit";//判断是去详情显示页面还是编辑页面
response.sendRedirect("income_" + to + ".jsp");
}
/**
* 根据条件查询进货的列表并跳转回页面
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("incomeList")
public void list(HttpServletResponse response, HttpServletRequest request) throws IOException {
this.redirectList(request, response);
}
/**
* 跳转到列表页面
*
* @param request
* @param response
*/
private void redirectList(HttpServletRequest request, HttpServletResponse response) throws IOException {
//查询列和关键字
String searchColumn = request.getParameter("searchColumn");
String keyword = request.getParameter("keyword");
Map<String, Object> params = new HashMap();//用来保存控制层传进来的参数(查询条件)
params.put("searchColumn", searchColumn);//要查询的列
params.put("keyword", keyword/*keyword != null ? new String(keyword.getBytes("ISO-8859-1"), "UTF-8") : null*/);//查询的关键字
//User loginUser = (User) request.getSession().getAttribute("loginUser");
//if (!"管理员".equals(loginUser.getUserType())) {
// params.put("createBy", loginUser.getId());
//}
Map<String, Object> map = incomeService.list(params);
request.getSession().setAttribute("list", map.get("list"));
Integer totalRecord = (Integer) map.get("totalCount");//根据查询条件取出对应的总记录数,用于分页
String pageNum = request.getParameter("pageNum");//封装分页参数
com.demo.util.PageBean<Object> pb = new com.demo.util.PageBean(Integer.valueOf(pageNum != null ? pageNum : "1"), totalRecord);
params.put("startIndex", pb.getStartIndex());
params.put("pageSize", pb.getPageSize());
List list = (List) incomeService.list(params).get("list");//根据分页参数startIndex、pageSize查询出来的最终结果list
pb.setServlet("incomeList");
pb.setSearchColumn(searchColumn);
pb.setKeyword(keyword);
pb.setList(list);
request.getSession().setAttribute("pageBean", pb);
request.getSession().setAttribute("list", pb.getList());
@Controller
@RequestMapping
public class IncomeController {
@Autowired
private IncomeService incomeService;
/**
* 增加进货
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("incomeAdd")
public void add(Income vo, HttpServletResponse response, HttpServletRequest request) throws IOException {
vo.setCreateBy(((com.demo.vo.User) request.getSession().getAttribute("loginUser")).getId());
//调用Service层的增加(insert)方法
incomeService.insert(vo);
this.redirectList(request, response);
}
/**
* 删除进货
*
* @param response
* @param request
* @throws IOException
*/
@RequestMapping("incomeDelete")
public void delete(HttpServletResponse response, HttpServletRequest request) throws IOException {
Serializable id = request.getParameter("id");
incomeService.delete(Arrays.asList(id));
this.redirectList(request, response);
}
/**
* 编辑进货
*













更多推荐
所有评论(0)