基于javaweb+mysql的ssm+maven药店药品管理系统(java+ssm+html+jquery+tomcat+mysql)
私信源码获取及调试交流
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb的SSM+Maven药店药品管理系统(java+ssm+html+jquery+tomcat+mysql)
项目介绍
该项目是前后台的医药管理系统(写在了一个web项目里),
简单明了,界面高端大气,共6张表
后台管理系统用于药片的管理,
前台系统是用户购买药片,下订单使用。
主要功能介绍:
药品管理系统-后台:
订单管理
添加、编辑、删除
药品管理
添加、编辑、删除 - 药品名、药品类别、单价
药品类别管理
添加、编辑、删除 - 类别名称、描述
用户管理
添加、编辑、删除 - 用户名、电话、描述
药品商城-前台:
前台页面展示药品类别、药品缩略图、药品详情、可购买、加入购物车、形成订单
配置环境
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版本;
技术栈
- 后端:Spring SpringMVC MyBatis 2. 前端:html+jQuery+javascript
使用步骤
1 使用IDEA/Eclipse导入MedicinesMS项目
2 使用Navicat或者其它工具,导入并执行sql文件 medicine_ms.sql,在项目的数据库配置文件db.properties中修改数据库相关配置,包括数据库名称、数据库用户名、密码等;
3 使用tomcat启动项目,项目名是/MedicinesMS 注:请固定为此项目名,否则会产生异常
4 访问后台系统http://localhost:8080/MedicinesMS/admin_login.html
进入登录页面,用户名 admin,密码123
5 在后台系统上添加药品信息
6 访问前台页面http://localhost:8080/MedicinesMS/login.html,
使用用户名 admin,密码123登录,购买要求,形成订单。
resultMap.put("state", "fail"); resultMap.put("reason", ErrorInfoUtil.getErrorInfo("user.login.check.null")); } return resultMap; } /** * 获取指定用户ID的用户信息 * @param userIds 用户ID数组 * @return Map 返回相关状态及信息 * @throws Exception 异常 */ @RequestMapping(value = "getSomeUser") public @ResponseBody Map<String, Object> getSomeUser(@RequestParam(value = "userIds[]") String[] userIds) throws Exception { List<User> users = userService.getSomeUser(userIds); Map<String, Object> result = new HashMap<String, Object>(); if (users.size() > 0) { result.put("state", "success"); result.put("result", users); } else { result.put("state", "fail"); result.put("reason", null); } return result; } /** * 获取用户总量 * @return Map 返回相关状态及信息 * @throws Exception 异常 */ @RequestMapping(value = "getUserCount") public @ResponseBody Map<String, Object> getUserCount() throws Exception { int count = userService.count(); Map<String, Object> result = new HashMap<String, Object>(); if (count > 0) { result.put("state", "success"); result.put("result", count); } else {
复制
* Version: 1.0 */ @Controller @RequestMapping(value = "medicine/medicine_type", method = {RequestMethod.POST}) public class MedicineTypeController { @Autowired MedicineTypeService medicineTypeService; /** * 获取指定ID的药品类型信息 * @param typeIds String[] 药品类型ID数组 * @return Map 返回相关状态及信息 * @throws Exception 异常 */ @RequestMapping(value = "getSomeMedicineType") public @ResponseBody Map<String, Object> getSomeMedicineType(@RequestParam(value = "typeIds[]") String[] typeIds) throws Exception { List<MedicineType> medicineTypes = medicineTypeService.getSomeMedicineType(typeIds); Map<String, Object> result = new HashMap<String, Object>(); if (medicineTypes.size() > 0) { result.put("state", "success"); result.put("result", medicineTypes); } else { result.put("state", "fail"); result.put("reason", null); } return result; } /** * 获取药品类型总量 * @return Map 返回相关状态及信息 * @throws Exception 异常 */ @RequestMapping(value = "getMedicineTypeCount") public @ResponseBody Map<String, Object> getMedicineTypeCount() throws Exception { int count = medicineTypeService.count(); Map<String, Object> result = new HashMap<String, Object>(); if (count > 0) { result.put("state", "success"); result.put("result", count); } else { result.put("state", "fail"); result.put("reason", 0); } return result; } /**
复制
* @return Map 返回相关状态及信息 * @throws Exception 异常 */ @RequestMapping(value = "deleteSomeMedicine") public @ResponseBody Map<String, Object> deleteSomeMedicine(@RequestParam(value = "medicineIds[]") String[] medicineIds) throws Exception { int deleteNum = medicineService.deleteSomeMedicine(medicineIds); Map<String, Object> result = new HashMap<String, Object>(); if (deleteNum > 0) { result.put("state", "success"); result.put("result", deleteNum); } else { result.put("state", "fail"); result.put("reason", null); } return result; } /** * 添加药品 * @param medicine 药品信息 * @return Map 返回相关状态及信息 * @throws Exception 异常 */ @RequestMapping(value = "addMedicine") public @ResponseBody Map<String, Object> addMedicine(@RequestBody Medicine medicine) throws Exception { int addCount = medicineService.addMedicine(medicine); Map<String, Object> result = new HashMap<String, Object>(); if (addCount > 0) { result.put("state", "success"); result.put("result", addCount); } else { result.put("state", "fail"); result.put("reason", 0); } return result; } /**
复制
@Override public int getFilteredCount(Medicine medicine) throws Exception { if (medicine.getTypeId().equals("")) { medicine.setTypeId(null); } medicine.setState(1); return medicineMapper.countBySelective(medicine); } } /** * Description: 药品业务接口 * Author: clw * Version: 1.0 */ public interface MedicineService { /** * 获取指定数量的药品 * @param medTypeId 药品类型ID * @param offset 偏移量 * @param limit 返回限制条数 * @return List<Medicine> 药品集合 * @throws Exception 异常 */ List<Medicine> getFilteredLimitMedicine(String medTypeId, int offset, int limit) throws Exception; /** * 获取指定ID量的药品 * @param medicineIds String[] 类型ID的列表 * @return List<Medicine> 药品集合 * @throws Exception 异常 */ List<Medicine> getSomeMedicine(String[] medicineIds) throws Exception; /**
复制
result.put("result", adminList); } else { result.put("state", "fail"); result.put("reason", null); } return result; } /** * 根据管理员ID更新管理员信息 * @param admin 新的管理员信息 * @return Map 返回相关状态及信息 * @throws Exception 异常 */ @RequestMapping(value = "updateAdminById") public @ResponseBody Map<String, Object> updateAdminById(@RequestBody Admin admin) throws Exception { int updateCount = adminService.updateById(admin); Map<String, Object> result = new HashMap<String, Object>(); if (updateCount > 0) { result.put("state", "success"); result.put("result", updateCount); } else { result.put("state", "fail"); result.put("reason", 0); } return result; } /** * 根据管理员ID数组删除一些管理员信息 * @param adminIds 管理员ID数组 * @return Map 返回相关状态及信息 * @throws Exception 异常 */ @RequestMapping(value = "deleteSomeAdmin") public @ResponseBody Map<String, Object> deleteSomeAdmin(@RequestParam(value = "adminIds[]") String[] adminIds) throws Exception { int deleteNum = adminService.deleteSomeAdmin(adminIds); Map<String, Object> result = new HashMap<String, Object>();
复制
} /** * 获取药品总量 * @return Map 返回相关状态及信息 * @throws Exception 异常 */ @RequestMapping(value = "getMedicineCount") public @ResponseBody Map<String, Object> getMedicineCount() throws Exception { int count = medicineService.count(); Map<String, Object> result = new HashMap<String, Object>(); if (count > 0) { result.put("state", "success"); result.put("result", count); } else { result.put("state", "fail"); result.put("reason", 0); } return result; } /** * 根据药品ID更新药品信息 * @param medicine 新的药品信息 * @return Map 返回相关状态及信息 * @throws Exception 异常 */ @RequestMapping(value = "updateMedicineById") public @ResponseBody Map<String, Object> updateMedicineById(@RequestBody Medicine medicine) throws Exception { int updateCount = medicineService.updateById(medicine); Map<String, Object> result = new HashMap<String, Object>(); if (updateCount > 0) { result.put("state", "success"); result.put("result", updateCount); } else { result.put("state", "fail"); result.put("reason", 0); } return result; } /** * 根据药品ID数组删除一些药品信息 * @param medicineIds 药品ID数组 * @return Map 返回相关状态及信息 * @throws Exception 异常 */ @RequestMapping(value = "deleteSomeMedicine") public @ResponseBody Map<String, Object> deleteSomeMedicine(@RequestParam(value = "medicineIds[]") String[] medicineIds) throws Exception { int deleteNum = medicineService.deleteSomeMedicine(medicineIds); Map<String, Object> result = new HashMap<String, Object>();
复制
} /** * 根据用户ID更新用户信息 * @param user 新的用户信息 * @return Map 返回相关状态及信息 * @throws Exception 异常 */ @RequestMapping(value = "updateUserById") public @ResponseBody Map<String, Object> updateUserById(@RequestBody User user) throws Exception { int updateCount = userService.updateById(user); Map<String, Object> result = new HashMap<String, Object>(); if (updateCount > 0) { result.put("state", "success"); result.put("result", updateCount); } else { result.put("state", "fail"); result.put("reason", 0); } return result; } /** * 根据用户ID数组删除一些用户信息 * @param userIds 用户ID数组 * @return Map 返回相关状态及信息 * @throws Exception 异常 */ @RequestMapping(value = "deleteSomeUser") public @ResponseBody Map<String, Object> deleteSomeUser(@RequestParam(value = "userIds[]") String[] userIds) throws Exception { int deleteNum = userService.deleteSomeUser(userIds); Map<String, Object> result = new HashMap<String, Object>(); if (deleteNum > 0) { result.put("state", "success"); result.put("result", deleteNum); } else { result.put("state", "fail"); result.put("reason", null); } return result; } /** * 添加用户 * @param user 用户信息 * @return Map 返回相关状态及信息 * @throws Exception 异常 */ @RequestMapping(value = {"addUser", "registerUser"}) public @ResponseBody Map<String, Object> addUser(@RequestBody User user) throws Exception { int addCount = userService.addUser(user);
复制
} /** * 根据订单ID数组删除一些订单信息 * @param ordersIds 订单ID数组 * @return Map 返回相关状态及信息 * @throws Exception 异常 */ @RequestMapping(value = "deleteSomeOrders") public @ResponseBody Map<String, Object> deleteSomeOrders(@RequestParam(value = "ordersIds[]") String[] ordersIds) throws Exception { int deleteNum = ordersService.deleteSomeOrders(ordersIds); Map<String, Object> result = new HashMap<String, Object>(); if (deleteNum > 0) { result.put("state", "success"); result.put("result", deleteNum); } else { result.put("state", "fail"); result.put("reason", null); } return result; } /** * 添加多条订单信息 * @param ordersList 订单集合 * @return Map 返回相关状态及信息 * @throws Exception 异常 */ @RequestMapping(value = "addSomeOrders") public @ResponseBody Map<String, Object> addSomeOrders(@RequestBody List<Orders> ordersList) throws Exception { int addNum = ordersService.addSomeOrders(ordersList); Map<String, Object> result = new HashMap<String, Object>(); if (addNum > 0) { result.put("state", "success"); result.put("result", addNum); } else { result.put("state", "fail"); result.put("reason", null); } return result; } }
复制
*/ @RequestMapping(value = "updateUserById") public @ResponseBody Map<String, Object> updateUserById(@RequestBody User user) throws Exception { int updateCount = userService.updateById(user); Map<String, Object> result = new HashMap<String, Object>(); if (updateCount > 0) { result.put("state", "success"); result.put("result", updateCount); } else { result.put("state", "fail"); result.put("reason", 0); } return result; } /** * 根据用户ID数组删除一些用户信息 * @param userIds 用户ID数组 * @return Map 返回相关状态及信息 * @throws Exception 异常 */ @RequestMapping(value = "deleteSomeUser") public @ResponseBody Map<String, Object> deleteSomeUser(@RequestParam(value = "userIds[]") String[] userIds) throws Exception { int deleteNum = userService.deleteSomeUser(userIds); Map<String, Object> result = new HashMap<String, Object>(); if (deleteNum > 0) { result.put("state", "success"); result.put("result", deleteNum); } else { result.put("state", "fail"); result.put("reason", null); } return result; } /** * 添加用户 * @param user 用户信息 * @return Map 返回相关状态及信息 * @throws Exception 异常 */
复制
result.put("state", "fail"); result.put("reason", null); } return result; } /** * 根据管理员ID更新管理员信息 * @param admin 新的管理员信息 * @return Map 返回相关状态及信息 * @throws Exception 异常 */ @RequestMapping(value = "updateAdminById") public @ResponseBody Map<String, Object> updateAdminById(@RequestBody Admin admin) throws Exception { int updateCount = adminService.updateById(admin); Map<String, Object> result = new HashMap<String, Object>(); if (updateCount > 0) { result.put("state", "success"); result.put("result", updateCount); } else { result.put("state", "fail"); result.put("reason", 0); } return result; } /** * 根据管理员ID数组删除一些管理员信息 * @param adminIds 管理员ID数组 * @return Map 返回相关状态及信息 * @throws Exception 异常 */ @RequestMapping(value = "deleteSomeAdmin") public @ResponseBody Map<String, Object> deleteSomeAdmin(@RequestParam(value = "adminIds[]") String[] adminIds) throws Exception { int deleteNum = adminService.deleteSomeAdmin(adminIds); Map<String, Object> result = new HashMap<String, Object>(); if (deleteNum > 0) { result.put("state", "success"); result.put("result", deleteNum); } else { result.put("state", "fail"); result.put("reason", null); } return result; }
复制
/** * 获取指定数量的药品信息 * @param offset 偏移量 * @param limit 返回限制条数 * @return Map 返回相关状态及信息 * @throws Exception 异常 */ @RequestMapping(value = "getFilteredLimitMedicine") public @ResponseBody Map<String, Object> getFilteredLimitMedicine(@RequestParam(value = "medTypeId", defaultValue = "") String medTypeId, @RequestParam(value = "offset") int offset, @RequestParam(value = "limit") int limit) throws Exception { medTypeId = "".equals(medTypeId) ? null : medTypeId; List<Medicine> medicines = medicineService.getFilteredLimitMedicine(medTypeId, offset, limit); Map<String, Object> result = new HashMap<String, Object>(); if (medicines.size() > 0) { result.put("state", "success"); result.put("result", medicines); } else { result.put("state", "fail"); result.put("reason", null); } return result; } /** * 获取指定ID的药品信息 * @param medicineIds String[] 药品ID数组 * @return Map 返回相关状态及信息 * @throws Exception 异常 */ @RequestMapping(value = "getSomeMedicine") public @ResponseBody Map<String, Object> getSomeMedicine(@RequestParam(value = "medicineIds[]") String[] medicineIds) throws Exception { List<Medicine> medicines = medicineService.getSomeMedicine(medicineIds); Map<String, Object> result = new HashMap<String, Object>(); if (medicines.size() > 0) { result.put("state", "success"); result.put("result", medicines); } else { result.put("state", "fail"); result.put("reason", null); } return result; } /** * 获取药品总量 * @return Map 返回相关状态及信息 * @throws Exception 异常
复制
result.put("state", "success"); result.put("result", addCount); } else { result.put("state", "fail"); result.put("reason", 0); } return result; } /** * 药品图片上传 * @param medicinePic 药品图片 * @return Map 返回相关状态及信息 * @throws Exception 异常 */ @RequestMapping(value = "addMedicinePic") public @ResponseBody Map<String, Object> addMedicinePic(HttpServletRequest request, @RequestParam("medicinePic") MultipartFile medicinePic) throws Exception { Map<String, Object> result = new HashMap<String, Object>(); String imgPath = medicineService.uploadFile(request, medicinePic); System.out.println("upload img path: " + imgPath); if (imgPath != null) { result.put("state", "success"); result.put("result", imgPath); } else { result.put("state", "fail"); result.put("reason", null); } return result; } /** * 根据过滤条件过滤查询药品总数 * @param medicine 药品过滤信息 * @return Map 返回相关状态及信息 * @throws Exception 异常 */ @RequestMapping(value = "getFilteredMedicineCount") public @ResponseBody Map<String, Object> getFilteredMedicineCount(@RequestBody Medicine medicine) throws Exception { System.out.println("getFilteredMedicineCount --- medicine: " + medicine); Map<String, Object> result = new HashMap<String, Object>(); int count = medicineService.getFilteredCount(medicine); if (count > 0) { result.put("state", "success"); result.put("result", count); } else { result.put("state", "fail"); result.put("reason", null); } return result; }
复制
*/ int deleteSomeMedicine(String[] medicineIds) throws Exception; /** * 添加药品 * @param medicine 药品信息 * @return int 添加条数 * @throws Exception 异常 */ int addMedicine(Medicine medicine) throws Exception; /** * 上传药品图片 * @param request 请求对象 * @param imgFile 图片信息 * @return 访问图片的路径 */ String uploadFile(HttpServletRequest request, MultipartFile imgFile) throws Exception; /** * 根据过滤条件查看药品总量 * @param medicine 药品过滤信息 * @return int 药品总量 * @throws Exception 异常 */ int getFilteredCount(Medicine medicine) throws Exception; } /** * Description: 登录拦截器 * Author: clw
复制
} /** * 根据药品ID数组删除一些药品信息 * @param medicineIds 药品ID数组 * @return Map 返回相关状态及信息 * @throws Exception 异常 */ @RequestMapping(value = "deleteSomeMedicine") public @ResponseBody Map<String, Object> deleteSomeMedicine(@RequestParam(value = "medicineIds[]") String[] medicineIds) throws Exception { int deleteNum = medicineService.deleteSomeMedicine(medicineIds); Map<String, Object> result = new HashMap<String, Object>(); if (deleteNum > 0) { result.put("state", "success"); result.put("result", deleteNum); } else { result.put("state", "fail"); result.put("reason", null); } return result; } /** * 添加药品 * @param medicine 药品信息 * @return Map 返回相关状态及信息 * @throws Exception 异常 */ @RequestMapping(value = "addMedicine") public @ResponseBody Map<String, Object> addMedicine(@RequestBody Medicine medicine) throws Exception { int addCount = medicineService.addMedicine(medicine); Map<String, Object> result = new HashMap<String, Object>(); if (addCount > 0) { result.put("state", "success"); result.put("result", addCount); } else { result.put("state", "fail"); result.put("reason", 0); } return result; }
复制
* @param medicine 药品信息 * @return int 添加条数 * @throws Exception 异常 */ int addMedicine(Medicine medicine) throws Exception; /** * 上传药品图片 * @param request 请求对象 * @param imgFile 图片信息 * @return 访问图片的路径 */ String uploadFile(HttpServletRequest request, MultipartFile imgFile) throws Exception; /** * 根据过滤条件查看药品总量 * @param medicine 药品过滤信息 * @return int 药品总量 * @throws Exception 异常 */ int getFilteredCount(Medicine medicine) throws Exception; } /** * Description: 登录拦截器 * Author: clw * Version: 1.0 */ public class LoginInterceptor implements HandlerInterceptor { public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object o) throws Exception { String url = request.getRequestURI(); if (url.indexOf("login.action") > 0 || url.indexOf("registerUser.action") > 0) { return true; } HttpSession session = request.getSession(); String username = (String) session.getAttribute("username"); System.out.println("*** username: " + username);
复制
String suffixName = fileName.substring(fileName.lastIndexOf(".") + 1); // 上传文件名(使用uuid命名) String newFileName = UUIDUtil.getUUID(); // 上传文件路径 String savePath = request.getServletContext().getRealPath("/medicine_images/"); String imgFullPath = savePath + newFileName + "." + suffixName; FileOutputStream out = new FileOutputStream(imgFullPath); out.write(imgFile.getBytes()); out.flush(); out.close(); return MedicineHUtil.IMGURL + newFileName + "." + suffixName; } return null; } @Override public int getFilteredCount(Medicine medicine) throws Exception { if (medicine.getTypeId().equals("")) { medicine.setTypeId(null); } medicine.setState(1); return medicineMapper.countBySelective(medicine); } } /** * Description: 药品业务接口 * Author: clw * Version: 1.0 */ public interface MedicineService { /** * 获取指定数量的药品 * @param medTypeId 药品类型ID * @param offset 偏移量 * @param limit 返回限制条数 * @return List<Medicine> 药品集合 * @throws Exception 异常
复制
/** * 根据管理员ID数组删除一些管理员信息 * @param adminIds 管理员ID数组 * @return Map 返回相关状态及信息 * @throws Exception 异常 */ @RequestMapping(value = "deleteSomeAdmin") public @ResponseBody Map<String, Object> deleteSomeAdmin(@RequestParam(value = "adminIds[]") String[] adminIds) throws Exception { int deleteNum = adminService.deleteSomeAdmin(adminIds); Map<String, Object> result = new HashMap<String, Object>(); if (deleteNum > 0) { result.put("state", "success"); result.put("result", deleteNum); } else { result.put("state", "fail"); result.put("reason", null); } return result; } /** * 添加管理员 * @param admin 用户信息 * @return Map 返回相关状态及信息 * @throws Exception 异常 */ @RequestMapping(value = "addAdmin") public @ResponseBody Map<String, Object> addAdmin(@RequestBody Admin admin) throws Exception { int addCount = adminService.addAdmin(admin); Map<String, Object> result = new HashMap<String, Object>(); if (addCount > 0) { result.put("state", "success"); result.put("result", addCount); } else { result.put("state", "fail"); result.put("reason", 0); } return result; }
复制
if (medicineTypes.size() > 0) { result.put("state", "success"); result.put("result", medicineTypes); } else { result.put("state", "fail"); result.put("reason", null); } return result; } /** * 根据药品类型ID更新药品类型信息 * @param medicineType 新的药品类型信息 * @return Map 返回相关状态及信息 * @throws Exception 异常 */ @RequestMapping(value = "updateMedicineTypeById") public @ResponseBody Map<String, Object> updateMedicineTypeById(@RequestBody MedicineType medicineType) throws Exception { int updateCount = medicineTypeService.updateById(medicineType); Map<String, Object> result = new HashMap<String, Object>(); if (updateCount > 0) { result.put("state", "success"); result.put("result", updateCount); } else { result.put("state", "fail"); result.put("reason", 0); } return result; } /** * 根据药品类型ID数组删除一些药品类型信息 * @param medicineTypeIds 药品类型ID数组 * @return Map 返回相关状态及信息 * @throws Exception 异常 */ @RequestMapping(value = "deleteSomeMedicineType") public @ResponseBody Map<String, Object> deleteSomeMedicineType(@RequestParam(value = "medicineTypeIds[]") String[] medicineTypeIds) throws Exception { int deleteNum = medicineTypeService.deleteSomeMedicineType(medicineTypeIds); Map<String, Object> re sult = new HashMap<String, Object>(); if (deleteNum > 0) { result.put("state", "success"); result.put("result", deleteNum); } else { result.put("state", "fail"); result.put("reason", null); } return result;
复制