(博客目录)
SSM框架(spring+springmvc+mybatis)+layui+Mysql实现的医院在线预约挂号管理系统
本系统为了患者线下预约挂号难的问题,打通医院和患者之间的一个渠道,通过在线透明化的方式,让患者进行预约,同时医院端也提高了看病的效率,可以在线维护科室、医生,以及查看患者病历等。 完整源码点击头像查看个人签名
实现功能截图
用户注册 登录 预约挂号 病历列表 管理员首页 患者管理 患者信息维护 科室管理 医生列表 医生管理 公告管理 修改病历
系统功能
本系统实现了以下功能: 分普通用户和管理员 1、注册登录 2、在线挂号预约 3、修改病历 4、医生列表 5、公告 管理员端 5、患者管理 6、科室管理 7、医生管理 8、患者信息维护 9、公告管理 等
使用技术
数据库:mysql 开发工具:Idea(Myeclispe、Eclipse也可以) 知识点:SSM+layui
项目结构
代码
实体类 Doctor.java
package com.code2life.hospital.entity;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
public class Doctor {
private Integer doctor_id;
private String username;
private String password;
private String gender;
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date birthday;
private String phone;
private String email;
private String address;
private Integer roleId;
private String rank; //职称
private String photo_path;
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
private Integer depart_id;
private String realname;
private Depart depart;
public Depart getDepart() {
return depart;
}
public void setDepart(Depart depart) {
this.depart = depart;
}
public Integer getDoctor_id() {
return doctor_id;
}
public void setDoctor_id(Integer doctor_id) {
this.doctor_id = doctor_id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public Date getBirthday() {
return birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public Integer getRoleId() {
return roleId;
}
public void setRoleId(Integer roleId) {
this.roleId = roleId;
}
public String getRank() {
return rank;
}
public void setRank(String rank) {
this.rank = rank;
}
public String getPhoto_path() {
return photo_path;
}
public void setPhoto_path(String photo_path) {
this.photo_path = photo_path;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Integer getDepart_id() {
return depart_id;
}
public void setDepart_id(Integer depart_id) {
this.depart_id = depart_id;
}
public String getRealname() {
return realname;
}
public void setRealname(String realname) {
this.realname = realname;
}
}
患者实体类User.java
package com.code2life.hospital.entity;
import java.util.Date;
import org.springframework.format.annotation.DateTimeFormat;
public class User {
private int user_id;
private String username;
private String photo_path;
private String password;
private String gender;
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date birthday;
//@DateTimeFormat(pattern = "yyyy-MM-dd") 很重要 必须加上 不然jsp中
// 数据类型和这里绑定不了 ajax请求进入不了controller
private String phone;
private String email;
private String address;
private String note;
private int status;
private String realname;
private int levelId;
public Long getRoleId() {
return roleId;
}
public void setRoleId(Long roleId) {
this.roleId = roleId;
}
private Long roleId;
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
public String getRealname() {
return realname;
}
public void setRealname(String realname) {
this.realname = realname;
}
public int getUser_id() {
return user_id;
}
public void setUser_id(int user_id) {
this.user_id = user_id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public Date getBirthday() {
return birthday;
}
public String getPhoto_path() {
return photo_path;
}
public void setPhoto_path(String photo_path) {
this.photo_path = photo_path;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getNote() {
return note;
}
public void setNote(String note) {
this.note = note;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public int getLevelId() {
return levelId;
}
public void setLevelId(int levelId) {
this.levelId = levelId;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
}
Dao层 DoctorDao.java
package com.code2life.hospital.dao;
import com.code2life.hospital.entity.Doctor;
import com.code2life.hospital.entity.DoctorSearch;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface DoctorDao {
void insDoctor(Doctor doctor);
Doctor login(@Param("username")String username, @Param("password")String password);
Doctor getDoctorById(Integer doctor_id);
void updateDoctor(Doctor doctor);
Doctor getDoctorByUserName(String username);
List<Doctor> getAllDoctorList(DoctorSearch search);
void deleteDoctorById(int doctor_id);
List<Doctor> getDoctorByDepartId(Integer depart_id);
}
UserDao.java
package com.code2life.hospital.dao;
import com.code2life.hospital.entity.User;
import com.code2life.hospital.entity.UserSearch;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface UserDao {
void insUser(User user);
User login(@Param("username")String username, @Param("password")String password);
User getUserById(Integer user_id);
void updateUser(User user);
User getUserByUserName(String username);
List<User> getAllUserList(UserSearch search);
void updateUserStatusById(@Param("user_id")int user_id, @Param("status")int status);
void deleteUserById(int user_id);
}
service层 DoctorServiceImpl.java
在这里插入代码片package com.code2life.hospital.service;
import com.code2life.hospital.dao.MenuDao;
import com.code2life.hospital.dao.RoleMenuDao;
import com.code2life.hospital.entity.Doctor;
import com.code2life.hospital.entity.DoctorSearch;
import com.code2life.hospital.entity.Menu;
import com.code2life.hospital.entity.RoleMenu;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.code2life.hospital.dao.DoctorDao;
import com.code2life.hospital.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
@Service
public class DoctorServiceImpl implements DoctorService{
@Autowired
private DoctorDao doctorDao;
@Autowired
private RoleMenuDao roleMenuDao;
@Autowired
private MenuDao menuDao;
@Override
public void insDoctor(Doctor doctor) {
doctorDao.insDoctor(doctor);
}
@Override
public Doctor login(String username, String encrypt) {
return doctorDao.login(username,encrypt);
}
@Override
public Doctor getDoctorById(Integer doctor_id) {
return doctorDao.getDoctorById(doctor_id);
}
@Override
public List<Menu> getMenus(Doctor doctor1) {
List<Menu> menuList=new ArrayList<>();
Long roleId=(long)doctor1.getRoleId();
List<RoleMenu> roleMenus=roleMenuDao.selMenusByRoleId(roleId);
//rolemenu里面就是一个中间表 两个字段 roleId menuId 关联起来
if(roleMenus!=null&&roleMenus.size()>0)
{
List<Menu> noChildrenMenus=new ArrayList<>();
for(int i=0;i<roleMenus.size();i++)
{
Menu menu=menuDao.getMenuById(roleMenus.get(i).getMenuId()); //获取rolemenu中的menuId
noChildrenMenus.add(menu); //就是根据这个登陆者的roleid 所拥有的菜单取出来
}
for(int i=0;i<noChildrenMenus.size();i++)
{
if(noChildrenMenus.get(i).getParentId()==0)
//说明这个菜单是一级菜单 没有上一级菜单
//如果这里不为0 表示这个菜单是二级菜单 或者三级菜单 ParentId对应了属于哪个上级菜单
{
Menu menu=new Menu();
menu=noChildrenMenus.get(i); //把这个一级菜单取出来
List<Menu> menus=new ArrayList<>();
for(int j=0;j<noChildrenMenus.size();j++) //把所有菜单过一遍
{
//如果有菜单属于这个一级菜单
if(noChildrenMenus.get(j).getParentId()==noChildrenMenus.get(i).getMenuId())
{
Menu menu2=new Menu();
menu2=noChildrenMenus.get(j);//取出这个二级菜单
menus.add(menu2);
}
}
menu.setChildren(menus); //存放了属于这个一级菜单的所有二级菜单
menuList.add(menu);//存放了所有的一级菜单和其对应的所有二级菜单
}
}
}
//下面是根据menu的sorting进行排序 升序排列 这样左侧菜单就会按照升序排列
Collections.sort(menuList, new Comparator<Menu>() {
@Override
public int compare(Menu o1, Menu o2) {
return o1.getSorting().compareTo(o2.getSorting());
}
});
return menuList;
}
@Override
public ResultUtil updateDoctor(Doctor doctor) {
doctorDao.updateDoctor(doctor);
return ResultUtil.ok();
}
@Override
public Doctor getDoctorByUserName(String username) {
return doctorDao.getDoctorByUserName(username);
}
@Override
public ResultUtil getAllDoctorList(Integer page, Integer limit, DoctorSearch search) {
PageHelper.startPage(page,limit);
List<Doctor> doctors=doctorDao.getAllDoctorList(search);
PageInfo<Doctor> pageInfo=new PageInfo<>(doctors);
ResultUtil resultUtil=new ResultUtil();
resultUtil.setCode(0);
resultUtil.setCount(pageInfo.getTotal());
resultUtil.setData(pageInfo.getList());
return resultUtil;
}
@Override
public ResultUtil deleteDoctorById(int doctor_id) {
doctorDao.deleteDoctorById(doctor_id);
return ResultUtil.ok();
}
@Override
public List<Doctor> getDoctorByDepartId(Integer depart_id) {
return doctorDao.getDoctorByDepartId(depart_id);
}
}
UserServiceImpl.java
package com.code2life.hospital.service;
import com.code2life.hospital.dao.MenuDao;
import com.code2life.hospital.dao.RoleMenuDao;
import com.code2life.hospital.entity.Menu;
import com.code2life.hospital.entity.RoleMenu;
import com.code2life.hospital.entity.User;
import com.code2life.hospital.entity.UserSearch;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.code2life.hospital.dao.UserDao;
import com.code2life.hospital.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
@Service
@Transactional
public class UserServiceImpl implements UserService
{
@Autowired
private UserDao userDao;
@Autowired
private RoleMenuDao roleMenuDao;
@Autowired
private MenuDao menuDao;
@Override
public void insUser(User user) {
userDao.insUser(user);
}
@Override
public User login(String username, String password) {
return userDao.login(username,password);
}
@Override
public List<Menu> getMenus(User user1)
{
List<Menu> menuList=new ArrayList<>();
Long roleId=user1.getRoleId();
List<RoleMenu> roleMenus=roleMenuDao.selMenusByRoleId(roleId);
//rolemenu是一个中间表 两个字段 roleId menuId 关联起来
if(roleMenus!=null&&roleMenus.size()>0)
{
List<Menu> noChildrenMenus=new ArrayList<>();
for(int i=0;i<roleMenus.size();i++)
{
Menu menu=menuDao.getMenuById(roleMenus.get(i).getMenuId()); //获取rolemenu中的menuId
noChildrenMenus.add(menu); //根据登陆者的roleid 所拥有的菜单取出来
}
for(int i=0;i<noChildrenMenus.size();i++)
{
if(noChildrenMenus.get(i).getParentId()==0)
//说明这个菜单是一级菜单 没有上一级菜单
//如果这里不为0 表示这个菜单是二级菜单 或者三级菜单 ParentId对应了属于哪个上级菜单
{
Menu menu=new Menu();
menu=noChildrenMenus.get(i); //把这个一级菜单取出来
List<Menu> menus=new ArrayList<>();
for(int j=0;j<noChildrenMenus.size();j++) //把所有菜单过一遍
{
//如果有菜单属于这个一级菜单
if(noChildrenMenus.get(j).getParentId()==noChildrenMenus.get(i).getMenuId())
{
Menu menu2=new Menu();
menu2=noChildrenMenus.get(j);//取出这个二级菜单
menus.add(menu2);
}
}
menu.setChildren(menus); //存放了属于这个一级菜单的所有二级菜单
menuList.add(menu);//存放了所有的一级菜单和其对应的所有二级菜单
}
}
}
//下面是根据menu的sorting进行排序 升序排列 这样左侧菜单就会按照升序排列
Collections.sort(menuList, new Comparator<Menu>() {
@Override
public int compare(Menu o1, Menu o2) {
return o1.getSorting().compareTo(o2.getSorting());
}
});
return menuList;
}
@Override
public User getUserById(Integer user_id) {
return userDao.getUserById(user_id);
}
@Override
public ResultUtil updateUser(User user) {
userDao.updateUser(user);
return ResultUtil.ok();
}
@Override
public User getUsertByUserName(String username) {
return userDao.getUserByUserName(username);
}
@Override
public ResultUtil getAllUserList(Integer page, Integer limit, UserSearch search) {
PageHelper.startPage(page,limit);
List<User> users=userDao.getAllUserList(search);
PageInfo<User> pageInfo=new PageInfo<>(users);
ResultUtil resultUtil=new ResultUtil();
resultUtil.setCode(0);
resultUtil.setCount(pageInfo.getTotal());
resultUtil.setData(pageInfo.getList());
return resultUtil;
}
@Override
public ResultUtil updateUserStatusById(int user_id, int status) {
userDao.updateUserStatusById(user_id,status);
return ResultUtil.ok();
}
@Override
public ResultUtil deleteUserById(int user_id) {
userDao.deleteUserById(user_id);
return ResultUtil.ok();
}
}
Controller层 DoctorController.java
package com.code2life.hospital.web;
import com.code2life.hospital.entity.Admin;
import com.code2life.hospital.entity.Doctor;
import com.code2life.hospital.entity.Menu;
import com.code2life.hospital.service.DoctorService;
import com.code2life.hospital.util.EncryptUtil;
import com.code2life.hospital.util.ResultUtil;
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.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
@Controller
@RequestMapping("/doctor")
public class DoctorController {
@Autowired
private DoctorService doctorService;
@RequestMapping("/login")
@ResponseBody
public ResultUtil login(String username, String password, HttpServletRequest request, HttpSession session) {
Doctor doctor = doctorService.login(username, EncryptUtil.encrypt(password));
if (doctor != null) {
Integer depart_id = doctor.getDepart_id();
if (depart_id != 0) //说明已经分配科室 可以登录
{
Admin admin = new Admin();
session.setAttribute("user", admin); //拦截器中用 跳过拦截器
session.setAttribute("hospital_user", doctor);
session.setAttribute("usertype", 3);//代表医生登陆
session.setAttribute("hospital_user_id", doctor.getDoctor_id());
session.setAttribute("hospital_user_photo", doctor.getPhoto_path());//获得头像图片名
return ResultUtil.ok();
} else {
return ResultUtil.error("对不起,请先联系管理员分配科室");
}
} else {
return ResultUtil.error("用户名或者密码错误,请重新输入");
}
}
@RequestMapping("/info")
public String info(HttpSession session) {
//覆盖一下之前的hospital_user 不然显示的还是之前的hospital_user
Integer doctor_id = (Integer) session.getAttribute("hospital_user_id");
Doctor doctor = doctorService.getDoctorById(doctor_id);
session.setAttribute("hospital_user", doctor);
return "/jsp/doctor/editDoctor";
}
@RequestMapping("/updateDoctor")
@ResponseBody
public ResultUtil updateDoctor(Doctor doctor) throws ParseException {
return doctorService.updateDoctor(doctor);
}
@RequestMapping("/changePassword")
public String changePassword() {
return "/jsp/doctor/changePassword";
}
@RequestMapping("/changeDoctorPassword")
@ResponseBody
public ResultUtil changeDoctorPassword(String username, String oldPassword, String newPassword1) {
Doctor doctor = doctorService.getDoctorByUserName(username);
if (doctor != null) {
if (doctor.getPassword().equals(EncryptUtil.encrypt(oldPassword))) {
doctor.setPassword(EncryptUtil.encrypt(newPassword1));
doctorService.updateDoctor(doctor);
return ResultUtil.ok();
} else {
return ResultUtil.error("旧密码错误,请重新填写");
}
}
return ResultUtil.error("请求出错!!");
}
//医生注册
@RequestMapping("/newUser")
@ResponseBody
public ResultUtil newUser(Doctor doctor) {
try {
doctor.setRoleId(3); //角色里表示医生
doctor.setDepart_id(1);//新注册医生 未分配科室
doctor.setRank(String.valueOf(5)); //新注册的医生默认是实习
doctor.setPassword(EncryptUtil.encrypt(doctor.getPassword()));
Date date = new Date();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String nowTime = simpleDateFormat.format(date);
Date create_time = simpleDateFormat.parse(nowTime);
doctor.setCreateTime(create_time);
doctorService.insDoctor(doctor);
return ResultUtil.ok();
} catch (Exception e) {
e.printStackTrace();
return ResultUtil.error();
}
}
@RequestMapping("/getMenus")
@ResponseBody
public List<Menu> getMenus(HttpSession session) {
List<Menu> menus = null;
Doctor doctor = (Doctor) session.getAttribute("hospital_user");
Doctor doctor1 = doctorService.getDoctorById(doctor.getDoctor_id());
if (doctor1 != null) {
menus = doctorService.getMenus(doctor1);
}
return menus;
}
@RequestMapping("/logOut")
public ModelAndView logOut(ModelAndView modelAndView, HttpSession session) {
session.invalidate();
modelAndView.setViewName("redirect:/index.jsp");
return modelAndView;
}
}
UserController.java
package com.code2life.hospital.web;
import com.code2life.hospital.entity.Admin;
import com.code2life.hospital.entity.Depart;
import com.code2life.hospital.entity.Menu;
import com.code2life.hospital.entity.User;
import com.code2life.hospital.service.DepartService;
import com.code2life.hospital.service.DoctorService;
import com.code2life.hospital.service.UserService;
import com.code2life.hospital.util.EncryptUtil;
import com.code2life.hospital.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
@Controller
@RequestMapping("/user")
public class UserController
{
@Autowired
private UserService userService;
@Autowired
private DepartService departService;
@Autowired
private DoctorService doctorService;
@RequestMapping("/login")
@ResponseBody
public ResultUtil login(String username, String password, HttpServletRequest request, HttpSession session)
{
User user=userService.login(username, EncryptUtil.encrypt(password));
if(user!=null)
{
Integer status=user.getStatus();
if(status==0)
{
return ResultUtil.error("对不起,此用户被禁用,请联系超级管理员");
}
Admin admin=new Admin();
session.setAttribute("user",admin); //拦截器中用 跳过拦截器
session.setAttribute("hospital_user",user);
session.setAttribute("usertype",2);//代表患者登陆
session.setAttribute("hospital_user_id",user.getUser_id());
session.setAttribute("hospital_user_photo",user.getPhoto_path());//获得头像图片名
return ResultUtil.ok();
}
else
{
return ResultUtil.error("用户名或者密码错误,请重新输入");
}
}
@RequestMapping("/getMenus")
@ResponseBody
public List<Menu> getMenus(HttpSession session)
{
//System.out.println("学生获取菜单进来了");
List<Menu> menus=null;
User user= (User) session.getAttribute("hospital_user");
User user1=userService.getUserById(user.getUser_id());
if(user1!=null)
{
menus=userService.getMenus(user1);
}
return menus;
}
@RequestMapping("/logOut")
public ModelAndView logOut(ModelAndView modelAndView, HttpSession session)
{
session.invalidate();
modelAndView.setViewName("redirect:/index.jsp");
return modelAndView;
}
@RequestMapping("/info")
public String info(HttpSession session)
{
//覆盖一下之前的hospital_user 不然显示的还是之前的hospital_user
Integer user_id= (Integer) session.getAttribute("hospital_user_id");
User user=userService.getUserById(user_id);
session.setAttribute("hospital_user",user);
return "/jsp/user/editUser";
}
@RequestMapping("/updateUser")
@ResponseBody
public ResultUtil updateUser(User user)throws ParseException
{
return userService.updateUser(user);
}
@RequestMapping("/changePassword")
public String changePassword()
{
return "/jsp/user/changePassword";
}
@RequestMapping("/changeUserPassword")
@ResponseBody
public ResultUtil changeStudentPassword(String oldPassword,String newPassword1,String username)
{
User user=userService.getUsertByUserName(username);
if(user!=null)
{
if(user.getPassword().equals(EncryptUtil.encrypt(oldPassword)))
{
user.setPassword(EncryptUtil.encrypt(newPassword1));
userService.updateUser(user);
return ResultUtil.ok();
}
else
{
return ResultUtil.error("旧密码错误,请重新填写");
}
}
return ResultUtil.error("请求出错!!");
}
@RequestMapping("/newUser")
@ResponseBody
public ResultUtil newUser(User user)
{
try
{
user.setStatus(1); //1表示正常
user.setRoleId((long) 2); //角色里表示一般用户
user.setLevelId(1); //普通用户
user.setPassword(EncryptUtil.encrypt(user.getPassword()));
Date date=new Date();
SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String nowTime=simpleDateFormat.format(date);
Date create_time=simpleDateFormat.parse(nowTime);
user.setCreateTime(create_time);
userService.insUser(user);
return ResultUtil.ok();
}
catch (Exception e)
{
e.printStackTrace();
return ResultUtil.error();
}
}
//下面是用户注册的时候 上传的头像
@RequestMapping(value = "/image", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> image(@RequestParam(value = "file") MultipartFile file, HttpServletRequest request, HttpServletResponse response)
{
Map<String, Object> map2 = new HashMap<String, Object>();
Map<String, Object> map = new HashMap<String, Object>();
String filename = "";
String localPath = "D:\\IdeaWorkSpace\\hospital_img\\"; //存放我们上传的头像
try {
if (file != null) {
//生成uuid作为文件名称
String uuid = UUID.randomUUID().toString().replaceAll("-", "");
//获得文件类型(可以判断如果不是图片,禁止上传)
String contentType = file.getContentType();
//获得文件后缀名
String suffixName = contentType.substring(contentType.indexOf("/") + 1);
//得到 文件名(随机数+uuid+后缀)
filename = (int)((Math.random())*100000000)+uuid + "." + suffixName;
// 判断是否有这个文件夹,没有就创建
if (!new File(localPath).exists()) {
new File(localPath).mkdirs();
}
// 复制到当前文件夹
file.transferTo(new File(localPath + filename));
}
} catch (Exception e) {
map.put("code", 1);
map.put("msg", "");
map.put("data", map2);
map2.put("src", filename);
return map;
}
map.put("code", 0);
map.put("msg", "");
map.put("data", map2);
map2.put("src", filename);
return map;
}
@RequestMapping("/doctorList")
public String doctorList(HttpSession session)
{
List<Depart> departs=departService.getAllDeparts();
session.setAttribute("departs",departs);
return "/jsp/user/doctorList";
}
}
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Archetype Created Web Application</display-name>
<!--配置 Spring 容器-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring_root.xml</param-value>
</context-param>
<!--中文乱码处理过滤-->
<!-- 编码过滤器 -->
<filter>
<filter-name>characterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>characterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!--配置 Spring mvc 容器-->
<!--将所有请求,都交给Spring MVC 处理-->
<servlet>
<servlet-name>webs</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring_web.xml</param-value>
</init-param>
</servlet>
<!--将 请求 截取 转交给 webs -->
<servlet-mapping>
<servlet-name>webs</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
写在最后
完整源码点击头像查看个人签名
觉得有用,记得一键三连哦!
标签:return,String,管理,预约,hospital,挂号,user,import,public From: https://blog.51cto.com/u_15625185/5807553