基于javaweb+mysql的ssm+maven药品管理系统(java+ssm+html+jquery+tomcat+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的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登录,购买要求,形成订单。
}
/**
* 根据药品类型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> 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 medicineType 药品信息
* @return Map 返回相关状态及信息
* @throws Exception 异常
*/
@RequestMapping(value = "addMedicineType")
public @ResponseBody
Map<String, Object> addMedicineType(@RequestBody MedicineType medicineType) throws Exception {
System.out.println(medicineType);
int addCount = medicineTypeService.addMedicineType(medicineType);
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;
}
/**
* 查询所有药品类型
* @return Map 返回相关状态及信息
* @throws Exception 异常
*/
@RequestMapping(value = "getAllMedicineType")
public @ResponseBody
Map<String, Object> getAllMedicineType() throws Exception {
* 获取指定数量的用户信息
* @param offset 偏移量
* @param limit 限制返回条数
* @return Map 返回相关状态及信息
* @throws Exception 异常
*/
@RequestMapping(value = "getLimitUser")
public @ResponseBody
Map<String, Object> getLimitUser(@RequestParam(value = "offset") int offset,
@RequestParam(value = "limit") int limit) throws Exception {
List<User> userList = userService.getLimitUser(offset, limit);
Map<String, Object> result = new HashMap<String, Object>();
if (userList.size() > 0) {
result.put("state", "success");
result.put("result", userList);
} else {
result.put("state", "fail");
result.put("reason", null);
}
return result;
}
/**
* 根据用户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 异常
*/
* @return List<Medicine> 药品集合
* @throws Exception 异常
*/
List<Medicine> getSomeMedicine(String[] medicineIds) throws Exception;
/**
* 获取药品总量
* @return int 药品的数量
* @throws Exception 异常
*/
int count() throws Exception;
/**
* 根据ID更新药品信息
* @param medicine 新的药品信息
* @return int 更新条数
* @throws Exception 异常
*/
int updateById(Medicine medicine) throws Exception;
/**
* 根据药品ID数组,删除一些药品数据
* @param medicineIds 药品ID数组
* @return int 删除条数
* @throws Exception 异常
*/
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 异常
}
/**
* Description: 用户控制器
* Author: clw
* Version: 1.0
*/
@Controller
@RequestMapping(value = "user/admin", method = {RequestMethod.POST})
public class AdminController {
@Autowired
AdminService adminService;
/**
* 登录Controller
* @param request HttpServletRequest 对象
* @param username 用户名
* @param password 密码
* @return Map 返回相关状态
* @throws Exception 异常
*/
@RequestMapping(value = "login")
public @ResponseBody
Map<String, String> login(HttpServletRequest request, @RequestParam(value = "username", defaultValue = "") String username,
@RequestParam(value = "password", defaultValue = "") String password) throws Exception {
Admin admin = adminService.loginCheck(username, password);
/**
* 获取指定用户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 {
result.put("state", "fail");
result.put("reason", 0);
}
return result;
}
Map<String, Object> updateAdminPasswdById(@RequestParam(value = "uid", defaultValue = "") String uid,
@RequestParam(value = "originalPasswd", defaultValue = "") String originalPasswd,
@RequestParam(value = "newPasswd", defaultValue = "") String newPasswd) throws Exception {
int updateCount = adminService.updatePasswdById(uid, originalPasswd, newPasswd);
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;
}
}
/**
* Description:
* Author: clw
* 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 (updateCount > 0) {
result.put("state", "success");
result.put("result", updateCount);
} else {
result.put("state", "fail");
result.put("reason", 0);
}
return result;
}
/**
* 获取当前登录用户
* @return Map 返回相关状态及信息
* @throws Exception 异常
*/
@RequestMapping(value = "getCurrentUser")
public @ResponseBody
Map<String, Object> getCurrentUser(HttpServletRequest request) throws Exception {
String userId = (String) request.getSession().getAttribute("userid");
User user = null;
if (userId != null && !"".equals(userId)) {
user = userService.getUserById(userId);
}
Map<String, Object> result = new HashMap<String, Object>();
if (user != null) {
result.put("state", "success");
result.put("result", user);
} else {
result.put("state", "fail");
result.put("reason", null);
}
return result;
}
}
/**
* Description: 用户控制器
* Author: clw
* Version: 1.0
*/
@Controller
@RequestMapping(value = "user/admin", method = {RequestMethod.POST})
public class AdminController {
@Autowired
AdminService adminService;
/**
* 登录Controller
* @param request HttpServletRequest 对象
* @param username 用户名
* @param password 密码
* @return Map 返回相关状态
* @throws Exception 异常
*/
@RequestMapping(value = "login")
public @ResponseBody
Map<String, String> login(HttpServletRequest request, @RequestParam(value = "username", defaultValue = "") String username,
@RequestParam(value = "password", defaultValue = "") String password) throws Exception {
Admin admin = adminService.loginCheck(username, password);
Map<String, String> resultMap =new HashMap<String, String>();
if (admin != null) {
request.getSession().setAttribute("userid", admin.getUid());
request.getSession().setAttribute("username", admin.getUsername());
request.getSession().setAttribute("identity", "admin");
resultMap.put("state", "success");
} else {
resultMap.put("state", "fail");
resultMap.put("reason", ErrorInfoUtil.getErrorInfo("user.login.check.null"));
}
return resultMap;
System.out.println("username: " + username + ", password: " + password);
User user = userService.loginCheck(username, password);
Map<String, String> resultMap =new HashMap<String, String>();
if (user != null) {
request.getSession().setAttribute("userid", user.getUid());
request.getSession().setAttribute("username", user.getUsername());
request.getSession().setAttribute("identity", "user");
resultMap.put("state", "success");
} else {
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 {
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);
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;
}
/**
* 根据用户ID更新用户密码
* @param uid 用户ID
* @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 异常
*/
@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");
public @ResponseBody
Map<String, Object> getLimitAdmin(@RequestParam(value = "offset") int offset,
@RequestParam(value = "limit") int limit) throws Exception {
List<Admin> adminList = adminService.getLimitAdmin(offset, limit);
Map<String, Object> result = new HashMap<String, Object>();
if (adminList.size() > 0) {
result.put("state", "success");
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>();
if (deleteNum > 0) {
* @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);
if (username != null && !"".equals(username.trim())) {
return true;
}
response.getWriter().print("redirect:login");
return false;
}
/**
* Description: 用户控制器
* Author: clw
* Version: 1.0
*/
@Controller
@RequestMapping(value = "user/user", method = {RequestMethod.POST})
public class UserController {
@Autowired
UserService userService;
/**
* 登录Controller
* @param request HttpServletRequest 对象
* @param username 用户名
* @param password 密码
* @return Map 返回相关状态
* @throws Exception 异常
*/
@RequestMapping(value = "login")
public @ResponseBody
Map<String, String> login(HttpServletRequest request, @RequestParam(value = "username", defaultValue = "") String username,
@RequestParam(value = "password", defaultValue = "") String password) throws Exception {
System.out.println("username: " + username + ", password: " + password);
User user = userService.loginCheck(username, password);
Map<String, String> resultMap =new HashMap<String, String>();
if (user != null) {
request.getSession().setAttribute("userid", user.getUid());
request.getSession().setAttribute("username", user.getUsername());
request.getSession().setAttribute("identity", "user");
resultMap.put("state", "success");
} else {
resultMap.put("state", "fail");
resultMap.put("reason", ErrorInfoUtil.getErrorInfo("user.login.check.null"));
}
return resultMap;
/**
* Description: 用户控制器
* Author: clw
* Version: 1.0
*/
@Controller
@RequestMapping(value = "user/admin", method = {RequestMethod.POST})
public class AdminController {
@Autowired
AdminService adminService;
/**
* 登录Controller
* @param request HttpServletRequest 对象
* @param username 用户名
* @param password 密码
* @return Map 返回相关状态
* @throws Exception 异常
*/
@RequestMapping(value = "login")
public @ResponseBody
Map<String, String> login(HttpServletRequest request, @RequestParam(value = "username", defaultValue = "") String username,
@RequestParam(value = "password", defaultValue = "") String password) throws Exception {
Admin admin = adminService.loginCheck(username, password);
Map<String, String> resultMap =new HashMap<String, String>();
if (admin != null) {
request.getSession().setAttribute("userid", admin.getUid());
request.getSession().setAttribute("username", admin.getUsername());
request.getSession().setAttribute("identity", "admin");
resultMap.put("state", "success");
} else {
resultMap.put("state", "fail");
resultMap.put("reason", ErrorInfoUtil.getErrorInfo("user.login.check.null"));
}
if (addCount > 0) {
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) {
/**
* 获取指定数量的药品类型信息
* @param offset 偏移量
* @param limit 返回限制条数
* @return Map 返回相关状态及信息
* @throws Exception 异常
*/
@RequestMapping(value = "getLimitMedicineType")
public @ResponseBody
Map<String, Object> getLimitMedicineType(@RequestParam(value = "offset") int offset,
@RequestParam(value = "limit") int limit) throws Exception {
List<MedicineType> medicineTypes = medicineTypeService.getLimitMedicineType(offset, limit);
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;
}
/**
* 根据药品类型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")