基于javaweb+mysql的springboot医院管理系统(java+springboot+layui+freemaker+maven+mysql)
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SpringBoot医院管理系统(java+springboot+layui+freemaker+maven+mysql)
项目介绍
医院管理系统,分为管理员、医生、病人三种角色;
管理员主要功能包括: 首页、系统管理:医生管理、患者管理、药品管理;预约管理;病史管理;住院信息管理;管理员用户管理; 医生主要功能包括:首页、就医/查看病史;
病人主要功能包括:首页、病史、住院信息、挂号;
环境需要
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版本;
技术栈
-
后端:SpringBoot
-
前端:Layui+Freemaker
使用说明
-
使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
-
使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;
若为maven项目,导入成功后请执行maven clean;maven install命令
- 将项目中application.yml配置文件中的数据库配置改为自己的配置,配置tomcat,然后运行; 4. 运行项目,输入http://localhost:8088 登录
String login1 = loginService.login(login);
JSONObject json=new JSONObject();
json.put("message",login1);
session.setAttribute("login",login);
return json;
}
@RequestMapping(value = "/regest",method = RequestMethod.POST)
@ResponseBody
public JSONObject regest(@RequestBody Login login){
JSONObject json=new JSONObject();
json.put("message",loginService.regist(login));
return json;
}
@RequestMapping("/hospital/patient/index")
public String patientIndex(){
return "/patient/index";
}
@RequestMapping("/hospital/doctor/index")
public String doctorIndex(){
return "/doctor/index";
}
@RequestMapping("/hospital/admin/index")
public String adminIndex(){
return "/admin/index";
}
}
@Controller
public class AppointmentController {
@Autowired
/**
*
*
*
*/
@Configuration
public class ShiroConfiguration {
private static final Logger S_LOGGER = LoggerFactory.getLogger(ShiroConfiguration.class);
/**
* Shiro的Web过滤器Factory 命名:shiroFilter<br />
*
* @param securityManager
* @return
*/
@Bean(name = "shiroFilter")
public ShiroFilterFactoryBean shiroFilterFactoryBean(SecurityManager securityManager) {
S_LOGGER.info("注入Shiro的Web过滤器-->shiroFilter", ShiroFilterFactoryBean.class);
ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
//Shiro的核心安全接口,这个属性是必须的
shiroFilterFactoryBean.setSecurityManager(securityManager);
//要求登录时的链接(可根据项目的URL进行替换),非必须的属性,默认会自动寻找Web工程根目录下的"/login.jsp"页面
shiroFilterFactoryBean.setLoginUrl("/hospital/login");
//登录成功后要跳转的连接,逻辑也可以自定义,例如返回上次请求的页面
shiroFilterFactoryBean.setSuccessUrl("/hospital/admin/index");
//用户访问未对其授权的资源时,所显示的连接
shiroFilterFactoryBean.setUnauthorizedUrl("/404.html");
/*定义shiro过滤器,例如实现自定义的FormAuthenticationFilter,需要继承FormAuthenticationFilter
**本例中暂不自定义实现,在下一节实现验证码的例子中体现
*/
/*定义shiro过滤链 Map结构
* Map中key(xml中是指value值)的第一个'/'代表的路径是相对于HttpServletRequest.getContextPath()的值来的
public JSONObject delPatient(@RequestBody Patient patient){
JSONObject json=new JSONObject();
json.put("message",patientService.addPatient(patient));
return json;
}
@RequestMapping(value = "/patient/medicalhistory")
public String medicalhistory(HttpSession session,HttpServletRequest request){
Login login=(Login)session.getAttribute("login");
Patient patient=patientService.findPatientByLoginId(login.getId());
request.setAttribute("medicalhistorys",medicalhistoryService.getMedicalhistoryByPatientId(patient.getId()));
return "patient/medicalhistory";
}
@RequestMapping(value = "/patient/hospitalization")
public String hospitalization(HttpSession session,HttpServletRequest request){
Login login=(Login)session.getAttribute("login");
Patient patient=patientService.findPatientByLoginId(login.getId());
request.setAttribute("theLast",hospitalizationService.findTheLastHospitalization(patient.getHospitalizationid()));
Hospitalization hospitalization=new Hospitalization();
hospitalization.setPatientid(patient.getId());
hospitalization.setId(patient.getHospitalizationid());
request.setAttribute("others",hospitalizationService.findOtherHospitalization(hospitalization));
return "patient/hospitalization";
}
@RequestMapping(value = "/patient/appointment")
public String appointmentInfo(HttpServletRequest request,HttpSession session){
Login login=(Login)session.getAttribute("login");
Patient patient=patientService.findPatientByLoginId(login.getId());
request.setAttribute("patientid",patient.getId());
request.setAttribute("doctors",doctorService.getAllDoctor());
return "patient/appointment";
}
@RequestMapping(value = "/patient/appointment",method = RequestMethod.POST)
@ResponseBody
public JSONObject appointment(@RequestBody Appointment appointment){
JSONObject json=new JSONObject();
Patient patient=new Patient();
String message=appointmentService.addAppointment(appointment);
patient.setAppointmentid(appointmentService.selectTheLastAppointment(appointment.getPatientid()));
patient.setId(appointment.getPatientid());
patientService.updateAppointMent(patient);
json.put("message",message);
return json;
}
@RequestMapping(value="/patient/search",method=RequestMethod.GET)
public String search(){
return "patient/search";
}
}
@Controller
public class MedicalhistoryController {
@Autowired
PatientService patientService;
@Autowired
MedicalhistoryService medicalhistoryService;
@RequestMapping("/admin/medicalhistoryManage")
public String medicalhistoryManage(HttpServletRequest request,@RequestParam(value = "doctorname",required = false)String doctorname,@RequestParam(value = "patientname",required = false)String patientname){
request.setAttribute("medicalhistorys",medicalhistoryService.getAllMedicalhistorys(doctorname,patientname));
return "admin/medicalhistoryManage";
}
@RequestMapping("/admin/medicalhistoryAdd")
public String medicalhistoryAddPage(HttpServletRequest request){
request.setAttribute("patients",patientService.getAllPatients());
return"admin/add/medicalhistoryadd";
}
@RequestMapping(value = "/admin/medicalhistory/{id}",method = RequestMethod.DELETE)
@ResponseBody
public JSONObject delmedicalhistory(@PathVariable Integer id){
JSONObject json=new JSONObject();
json.put("message",medicalhistoryService.delMedicalhistory(id));
return json;
}
@RequestMapping(value = "/admin/medicalhistory/{id}",method = RequestMethod.GET)
public String medicalhistoryInfo(@PathVariable Integer id,HttpServletRequest request){
request.setAttribute("patients",patientService.getAllPatients());
request.setAttribute("medicalhistory",medicalhistoryService.getMedicalhistory(id));
return "admin/info/medicalhistoryInfo";
}
@RequestMapping(value = "/admin/medicalhistory",method = RequestMethod.PUT)
@ResponseBody
public JSONObject medicalhistoryUpdate(@RequestBody Medicalhistory medicalhistory){
JSONObject json=new JSONObject();
json.put("message",medicalhistoryService.UpdateMedicalhistory(medicalhistory));
return json;
}
@RequestMapping(value = "/admin/medicalhistory",method = RequestMethod.POST)
@ResponseBody
public JSONObject medicalhistoryAdd(@RequestBody Medicalhistory medicalhistory){
System.out.println(medicalhistory);
JSONObject json=new JSONObject();
json.put("message",medicalhistoryService.addMedicalhistory(medicalhistory));
return json;
}
}
return "/admin/index";
}
}
@Controller
public class AppointmentController {
@Autowired
AppointmentService appointmentService;
@Autowired
DoctorService doctorService;
@Autowired
PatientService patientService;
@RequestMapping("/admin/appointmentManage")
public String appointmentManage(HttpServletRequest request,@RequestParam(value = "doctorname",required = false)String doctorname,@RequestParam(value = "patientname",required = false)String patientname){
List<Appointment> appointmentList=appointmentService.getAllAppointments(doctorname,patientname);
request.setAttribute("appointments" ,appointmentList);
return"admin/appointmentManage";
}
@RequestMapping("/admin/appointmentAdd")
public String appointmentAddPage(HttpServletRequest request){
request.setAttribute("patients",patientService.getAllPatients());
//request.setAttribute("doctors",doctorService.getAllDoctor());
return"admin/add/appointmentadd";
}
@RequestMapping(value = "/admin/appointment/{id}",method = RequestMethod.DELETE)
@ResponseBody
public JSONObject delAppointment(@PathVariable Integer id){
JSONObject json=new JSONObject();
json.put("message",appointmentService.delAppointment(id));
return json;
}
@RequestMapping(value = "/admin/appointment/{id}",method = RequestMethod.GET)
public String AppointmentInfo(@PathVariable Integer id,HttpServletRequest request){
request.setAttribute("patients",patientService.getAllPatients());
request.setAttribute("doctors",doctorService.getAllDoctor());
//浏览器下载excel
public static void buildExcelDocument(String filename, HSSFWorkbook workbook, HttpServletResponse response) throws Exception{
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment;filename="+ URLEncoder.encode(filename, "utf-8"));
OutputStream outputStream = response.getOutputStream();
workbook.write(outputStream);
outputStream.flush();
outputStream.close();
}
}
@Controller
public class DrugsController {
@Autowired
DrugsService drugsService;
@RequestMapping("admin/drugsManage")
public String drugsManage(HttpServletRequest request,@RequestParam(value="name",required = false) String name,@RequestParam(value="type",required = false) Integer type){
Drugs drugs=new Drugs();
drugs.setName(name);
drugs.setType(type);
request.setAttribute("drugs",drugsService.getAllDrugs(drugs));
return "/admin/drugsManage";
}
@RequestMapping(value = "/admin/drug/{id}",method = RequestMethod.DELETE)
@ResponseBody
public JSONObject delDrug(@PathVariable Integer id){
JSONObject json=new JSONObject();
json.put("message",drugsService.delDrug(id));
return json;
}
@RequestMapping(value = "/admin/drug",method = RequestMethod.POST)
json.put("doctors",doctorService.getDoctorByDepartment(department));
return json;
}
}
@Controller
public class LoginController {
@Autowired
LoginService loginService;
@RequestMapping(value = "/hospital/login")
public String loginAndregist(){
return "login®ist";
}
@RequestMapping("/admin/adminManage")
public String adminManage(HttpServletRequest request,@RequestParam(value = "username",required = false)String username){
request.setAttribute("admins",loginService.findAllAdmin(username));
return "/admin/adminManage";
}
@RequestMapping("/admin/admin/{id}")
public String adminInfo(HttpServletRequest request,@PathVariable Integer id){
request.setAttribute("admin",loginService.getAdmin(id));
return "/admin/info/admininfo";
}
@RequestMapping("/admin/adminAdd")
public String adminAddPage(){
return"admin/add/adminadd";
}
@RequestMapping(value = "/admin/admin",method = RequestMethod.POST)
@ResponseBody
public JSONObject adminAdd(@RequestBody Login login){
Map<String, String> filterChainDefinitionMap = new LinkedHashMap<String, String>();
// 配置退出过滤器,其中的具体的退出代码Shiro已经替我们实现了
filterChainDefinitionMap.put("/resources/**", "anon");
filterChainDefinitionMap.put("/static/**", "anon");
filterChainDefinitionMap.put("/logout", "logout");
// filterChainDefinitionMap.put("/", "anon");
// <!-- 过滤链定义,从上向下顺序执行,一般将 /**放在最为下边 -->:这是一个坑呢,一不小心代码就不好使了;
// <!-- authc:所有url都必须认证通过才可以访问; anon:所有url都都可以匿名访问-->
filterChainDefinitionMap.put("/hospital/**", "anon");
// filterChainDefinitionMap.put("/upload/upload", "anon");
filterChainDefinitionMap.put("/login/**", "anon");
// filterChainDefinitionMap.put("/manager/getCurrentManager", "anon");
//其余全部认证
filterChainDefinitionMap.put("/**", "authc");
shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);
return shiroFilterFactoryBean;
}
/**
* 不指定名字的话,自动创建一个方法名第一个字母小写的bean
* @Bean(name = "securityManager")
* @return
*/
@Bean
public SecurityManager securityManager() {
S_LOGGER.info("注入Shiro的Web过滤器-->securityManager", ShiroFilterFactoryBean.class);
DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
//securityManager.setRealm(userRealm());
securityManager.setSessionManager(sessionManager());
return securityManager;
}
/**
* 定义session管理
*/
@Bean
public SessionManager sessionManager() {
// Shiro 提供了三个默认实现 基于默认 基于Servlet环境 基于自身
MySessionManager sessionManager = new MySessionManager();
// 这里可以不设置。Shiro有默认的session管理。如果缓存为Redis则需改用Redis的管理
sessionManager.setSessionDAO(new MemorySessionDAO());
// 开启定期清除session
sessionManager.setGlobalSessionTimeout(3 * 60 * 60 * 1000);
// sessionManager.setGlobalSessionTimeout(10000);
sessionManager.setSessionValidationSchedulerEnabled(true);
return sessionManager;
}
@Bean
public AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor(){
AuthorizationAttributeSourceAdvisor authorizationAttributeSourceAdvisor = new AuthorizationAttributeSourceAdvisor();
authorizationAttributeSourceAdvisor.setSecurityManager(securityManager());
return authorizationAttributeSourceAdvisor;
}
}
@Controller
public class PatientController {
@Autowired
PatientService patientService;
@Autowired
DoctorService doctorService;
@Autowired
AppointmentService appointmentService;
@Autowired
HospitalizationService hospitalizationService;
@Autowired
MedicalhistoryService medicalhistoryService;
@RequestMapping("/admin/patientManage")
public String patientlist(HttpServletRequest request,@RequestParam(value="name",required = false) String name,@RequestParam(value="certId",required = false) String certId){
request.setAttribute("patients",patientService.getAllPatients(name,certId));
return "admin/patientManage";
}
@RequestMapping(value = "/admin/patient/{id}",method = RequestMethod.DELETE)
@ResponseBody
public JSONObject delPatient(@PathVariable Integer id){
JSONObject json=new JSONObject();
Doctor doctor=doctorService.getDoctorByLoginId(login.getId());
request.setAttribute("appointments" ,appointmentService.selectByDoctorId(doctor.getId(),patientname,time));
return "doctor/seekMedicalAdvice";
}
@RequestMapping("/doctor/seek/{id}")
public String seek(@PathVariable Integer id,HttpServletRequest request){
request.setAttribute("patient",patientService.getPatient(id));
request.setAttribute("drugs",drugsService.getAllDrugs());
return "doctor/seek";
}
@RequestMapping(value = "/doctor/drug",method = RequestMethod.PUT)
@ResponseBody
public JSONObject drug(@RequestBody Map map){
JSONObject json=new JSONObject();
Patient patient=new Patient();
System.out.println(map);
patient.setDrugsids(DrugsUtils.vaild(map));
patient.setId(Integer.parseInt((String)map.get("patientid")));
json.put("message",patientService.seek(patient));
return json;
}
@RequestMapping(value = "/doctor/zation",method = RequestMethod.POST)
@ResponseBody
public JSONObject zation(@RequestBody Hospitalization hospitalization){
JSONObject json=new JSONObject();
json.put("message",hospitalizationService.AddHospitalization(hospitalization));
return json;
}
@RequestMapping(value = "/doctor/medicalhistory/{id}")
public String medicalhistory(@PathVariable Integer id,HttpServletRequest request){
request.setAttribute("medicalhistorys",medicalhistoryService.getMedicalhistoryByPatientId(id));
return "doctor/medicalhistory";
}
@RequestMapping( value = "/doctor/{department}",method = RequestMethod.GET)
@ResponseBody
public JSONObject getDoctorByDepartment(@PathVariable String department){
JSONObject json=new JSONObject();
json.put("doctors",doctorService.getDoctorByDepartment(department));
return json;
}
}
@Controller
public class DoctorController {
@Autowired
DoctorService doctorService;
@Autowired
AppointmentService appointmentService;
@Autowired
PatientService patientService;
@Autowired
DrugsService drugsService;
@Autowired
HospitalizationService hospitalizationService;
@Autowired
MedicalhistoryService medicalhistoryService;
@RequestMapping("/admin/doctorManage")
public String doctorManage(HttpServletRequest request,@RequestParam(value="name",required = false) String name,@RequestParam(value="certId",required = false) String certId){
request.setAttribute("doctors",doctorService.getAllDoctor(name,certId));
return "admin/doctorManage";
}
@RequestMapping(value = "/admin/doctor/{id}",method = RequestMethod.DELETE)
@ResponseBody
public JSONObject delDoctor(@PathVariable Integer id){
JSONObject json=new JSONObject();
json.put("message",doctorService.delDoctor(id));
return json;
}
@RequestMapping(value = "/admin/doctor/{id}",method = RequestMethod.GET)
public String doctorInfo(@PathVariable Integer id,HttpServletRequest request){
request.setAttribute("doctor",doctorService.getDoctor(id));
return "admin/info/doctorinfo";
}
@RequestMapping(value = "/admin/doctor",method = RequestMethod.POST)
@ResponseBody
JSONObject json=new JSONObject();
Patient patient=new Patient();
String message=appointmentService.addAppointment(appointment);
patient.setAppointmentid(appointmentService.selectTheLastAppointment(appointment.getPatientid()));
patient.setId(appointment.getPatientid());
patientService.updateAppointMent(patient);
json.put("message",message);
return json;
}
@RequestMapping(value="/patient/search",method=RequestMethod.GET)
public String search(){
return "patient/search";
}
}
@Controller
public class HospitalizationController {
@Autowired
HospitalizationService hospitalizationService;
@Autowired
PatientService patientService;
@RequestMapping("/admin/hospitalizationManage")
public String hospitalizationManage(HttpServletRequest request,@RequestParam(value = "patientname",required = false)String patientname,@RequestParam(value = "intime",required = false)String intime){
request.setAttribute("hospitalizations",hospitalizationService.getAllHospitalizations(patientname,intime));
return "admin/hospitalizationManage";
}
@RequestMapping("/admin/hospitalizationAdd")
public String hospitalizationAddPage(HttpServletRequest request){
@Controller
public class DrugsController {
@Autowired
DrugsService drugsService;
@RequestMapping("admin/drugsManage")
public String drugsManage(HttpServletRequest request,@RequestParam(value="name",required = false) String name,@RequestParam(value="type",required = false) Integer type){
Drugs drugs=new Drugs();
drugs.setName(name);
drugs.setType(type);
request.setAttribute("drugs",drugsService.getAllDrugs(drugs));
return "/admin/drugsManage";
}
@RequestMapping(value = "/admin/drug/{id}",method = RequestMethod.DELETE)
@ResponseBody
public JSONObject delDrug(@PathVariable Integer id){
JSONObject json=new JSONObject();
json.put("message",drugsService.delDrug(id));
return json;
}
@RequestMapping(value = "/admin/drug",method = RequestMethod.POST)
@ResponseBody
public JSONObject addDrug(@RequestBody Drugs drugs){
JSONObject json=new JSONObject();
json.put("message",drugsService.addDrug(drugs));
return json;
}
@RequestMapping("/admin/drugAdd")
public String drugAddPage(){
return "/admin/add/drugadd";
}
@RequestMapping(value = "/admin/drug/{id}",method = RequestMethod.GET)
public String drugInfo(HttpServletRequest request,@PathVariable Integer id) {
request.setAttribute("drug",drugsService.getDrug(id));
return "/admin/info/drugsinfo";
}
@RequestMapping(value = "/admin/drug",method = RequestMethod.PUT)
@ResponseBody
public JSONObject updateDrug(@RequestBody Drugs drugs) {
JSONObject json=new JSONObject();
json.put("message",drugsService.updateDrug(drugs));
return json;
}
}
@ResponseBody
public JSONObject AppointmentAdd(@RequestBody Appointment appointment){
System.out.println(appointment);
JSONObject json=new JSONObject();
json.put("message",appointmentService.addAppointment(appointment));
return json;
}
}
@Controller
public class MedicalhistoryController {
@Autowired
PatientService patientService;
@Autowired
MedicalhistoryService medicalhistoryService;
@RequestMapping("/admin/medicalhistoryManage")
public String medicalhistoryManage(HttpServletRequest request,@RequestParam(value = "doctorname",required = false)String doctorname,@RequestParam(value = "patientname",required = false)String patientname){
request.setAttribute("medicalhistorys",medicalhistoryService.getAllMedicalhistorys(doctorname,patientname));
return "admin/medicalhistoryManage";
}
@RequestMapping("/admin/medicalhistoryAdd")
public String medicalhistoryAddPage(HttpServletRequest request){
request.setAttribute("patients",patientService.getAllPatients());
return"admin/add/medicalhistoryadd";
}
@RequestMapping(value = "/admin/medicalhistory/{id}",method = RequestMethod.DELETE)
@ResponseBody
public JSONObject delmedicalhistory(@PathVariable Integer id){
JSONObject json=new JSONObject();
json.put("message",medicalhistoryService.delMedicalhistory(id));
return json;
}
@RequestMapping(value = "/admin/medicalhistory/{id}",method = RequestMethod.GET)
public String medicalhistoryInfo(@PathVariable Integer id,HttpServletRequest request){
request.setAttribute("patients",patientService.getAllPatients());
request.setAttribute("medicalhistory",medicalhistoryService.getMedicalhistory(id));
return "admin/info/medicalhistoryInfo";
public String patientIndex(){
return "/patient/index";
}
@RequestMapping("/hospital/doctor/index")
public String doctorIndex(){
return "/doctor/index";
}
@RequestMapping("/hospital/admin/index")
public String adminIndex(){
return "/admin/index";
}
}
@Controller
public class AppointmentController {
@Autowired
AppointmentService appointmentService;
@Autowired
DoctorService doctorService;
@Autowired
PatientService patientService;
@RequestMapping("/admin/appointmentManage")
public String appointmentManage(HttpServletRequest request,@RequestParam(value = "doctorname",required = false)String doctorname,@RequestParam(value = "patientname",required = false)String patientname){
List<Appointment> appointmentList=appointmentService.getAllAppointments(doctorname,patientname);
request.setAttribute("appointments" ,appointmentList);
return"admin/appointmentManage";
}
@RequestMapping("/admin/appointmentAdd")
public String appointmentAddPage(HttpServletRequest request){
*
*
*/
@Configuration
public class ShiroConfiguration {
private static final Logger S_LOGGER = LoggerFactory.getLogger(ShiroConfiguration.class);
/**
* Shiro的Web过滤器Factory 命名:shiroFilter<br />
*
* @param securityManager
* @return
*/
@Bean(name = "shiroFilter")
public ShiroFilterFactoryBean shiroFilterFactoryBean(SecurityManager securityManager) {
S_LOGGER.info("注入Shiro的Web过滤器-->shiroFilter", ShiroFilterFactoryBean.class);
ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
//Shiro的核心安全接口,这个属性是必须的
shiroFilterFactoryBean.setSecurityManager(securityManager);
//要求登录时的链接(可根据项目的URL进行替换),非必须的属性,默认会自动寻找Web工程根目录下的"/login.jsp"页面
shiroFilterFactoryBean.setLoginUrl("/hospital/login");
//登录成功后要跳转的连接,逻辑也可以自定义,例如返回上次请求的页面
shiroFilterFactoryBean.setSuccessUrl("/hospital/admin/index");
//用户访问未对其授权的资源时,所显示的连接
shiroFilterFactoryBean.setUnauthorizedUrl("/404.html");
/*定义shiro过滤器,例如实现自定义的FormAuthenticationFilter,需要继承FormAuthenticationFilter
**本例中暂不自定义实现,在下一节实现验证码的例子中体现
*/
/*定义shiro过滤链 Map结构
* Map中key(xml中是指value值)的第一个'/'代表的路径是相对于HttpServletRequest.getContextPath()的值来的
* anon:它对应的过滤器里面是空的,什么都没做,这里.do和.jsp后面的*表示参数,比方说login.jsp?main这种
* authc:该过滤器下的页面必须验证后才能访问,它是Shiro内置的一个拦截器org.apache.shiro.web.filter.authc.FormAuthenticationFilter
*/
Map<String, String> filterChainDefinitionMap = new LinkedHashMap<String, String>();
// 配置退出过滤器,其中的具体的退出代码Shiro已经替我们实现了
filterChainDefinitionMap.put("/resources/**", "anon");
filterChainDefinitionMap.put("/static/**", "anon");
filterChainDefinitionMap.put("/logout", "logout");
// filterChainDefinitionMap.put("/", "anon");
// <!-- 过滤链定义,从上向下顺序执行,一般将 /**放在最为下边 -->:这是一个坑呢,一不小心代码就不好使了;
// <!-- authc:所有url都必须认证通过才可以访问; anon:所有url都都可以匿名访问-->
filterChainDefinitionMap.put("/hospital/**", "anon");
// filterChainDefinitionMap.put("/upload/upload", "anon");
filterChainDefinitionMap.put("/login/**", "anon");
// filterChainDefinitionMap.put("/manager/getCurrentManager", "anon");
//其余全部认证
filterChainDefinitionMap.put("/**", "authc");
shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);
return shiroFilterFactoryBean;
return "patient/hospitalization";
}
@RequestMapping(value = "/patient/appointment")
public String appointmentInfo(HttpServletRequest request,HttpSession session){
Login login=(Login)session.getAttribute("login");
Patient patient=patientService.findPatientByLoginId(login.getId());
request.setAttribute("patientid",patient.getId());
request.setAttribute("doctors",doctorService.getAllDoctor());
return "patient/appointment";
}
@RequestMapping(value = "/patient/appointment",method = RequestMethod.POST)
@ResponseBody
public JSONObject appointment(@RequestBody Appointment appointment){
JSONObject json=new JSONObject();
Patient patient=new Patient();
String message=appointmentService.addAppointment(appointment);
patient.setAppointmentid(appointmentService.selectTheLastAppointment(appointment.getPatientid()));
patient.setId(appointment.getPatientid());
patientService.updateAppointMent(patient);
json.put("message",message);
return json;
}
@RequestMapping(value="/patient/search",method=RequestMethod.GET)
public String search(){
return "patient/search";
}
}