current position:Home>Java project: nursing home management system (java + springboot + thymeleaf + HTML + JS + MySQL)

Java project: nursing home management system (java + springboot + thymeleaf + HTML + JS + MySQL)

2022-04-29 13:48:08pastclouds

The source code for : Blog's front page " resources " Download !

Project introduction

be based on springboot Nursing home management system , This system is a background management system , Divided into three roles , They are super Administrators 、 Administrators 、 user .

Super administrator 、 The functions of the administrator are as follows :
Sign in 、 Change Password 、 Account management 、 Health record management 、 Case management 、 Drug Administration 、 Monthly catering management 、 Go out and report 、 Check in 、 Bedroom allocation 、 Accident records 、 Visitor's record 、 Charge management ; The super administrator can manage the administrator account ;

The functions of the user are as follows :
Sign in 、 Change Password 、 Personal information 、 Family situation 、 Monthly catering management 、 Go out and report 、 Check the charging standard

Environmental needs

1. Running environment : It is best to java jdk 1.8, We run on this platform . Other versions can, in theory .
2.IDE Environmental Science :IDEA,Eclipse,Myeclipse Fine . recommend IDEA;
3.tomcat Environmental Science :Tomcat 7.x,8.x,9.x All versions are available
4. Hardware environment :windows 7/8/10 1G Above memory ; perhaps Mac OS;
5. database :MySql 5.7 edition ;
6. whether Maven project : yes ; See if the source directory contains pom.xml;

If included , Then for maven project , Otherwise, it is not maven project

Technology stack

1. Back end :springboot+Mybatis

2. front end :HTML+thymeleaf+Javascript+css

Instructions

1. Use Navicat Or other tools , stay mysql Create a database with the corresponding name in , And import the sql file ;
2. Use IDEA/Eclipse/MyEclipse Import the project ,Eclipse/MyEclipse Import time , if maven Item, please select maven;
if maven project , After importing successfully, please execute maven clean;maven install command , To configure tomcat;
3. In the project application-dev.yml Change the database configuration in the configuration file to your own configuration
4. Run the project , Enter the address in the browser :http://localhost:8080/ Login account ;
Super administrator :root/123456
Administrators :admin/123456
user :user/123456

 

 

 

 

 

 

User management control layer :

//UserInfo Management control 
@Controller
@RequestMapping("/UserInfo")
public class UserInfoController extends BaseController {

    /* Business layer objects */
    @Resource UserInfoService userInfoService;

	@InitBinder("userInfo")
	public void initBinderUserInfo(WebDataBinder binder) {
		binder.setFieldDefaultPrefix("userInfo.");
	}
	/* Jump to add UserInfo View */
	@RequestMapping(value = "/add", method = RequestMethod.GET)
	public String add(Model model,HttpServletRequest request) throws Exception {
		model.addAttribute(new UserInfo());
		return "UserInfo_add";
	}

	/* client ajax Submit and add user information */
	@RequestMapping(value = "/add", method = RequestMethod.POST)
	public void add(@Validated UserInfo userInfo, BindingResult br,
			Model model, HttpServletRequest request,HttpServletResponse response) throws Exception {
		String message = "";
		boolean success = false;
		if (br.hasErrors()) {
			message = " The input information does not meet the requirements !";
			writeJsonResponse(response, success, message);
			return ;
		}
		if(userInfoService.getUserInfo(userInfo.getUser_name()) != null) {
			message = " The user name already exists !";
			writeJsonResponse(response, success, message);
			return ;
		}
		try {
			userInfo.setUserPhoto(this.handlePhotoUpload(request, "userPhotoFile"));
		} catch(UserException ex) {
			message = " The picture format is not correct !";
			writeJsonResponse(response, success, message);
			return ;
		}
        userInfoService.addUserInfo(userInfo);
        message = " User added successfully !";
        success = true;
        writeJsonResponse(response, success, message);
	}
	/*ajax Query information according to user paging conditions */
	@RequestMapping(value = { "/list" }, method = {RequestMethod.GET,RequestMethod.POST})
	public void list(String user_name,String name,String birthDate,String telephone,Integer page,Integer rows, Model model, HttpServletRequest request,HttpServletResponse response) throws Exception {
		if (page==null || page == 0) page = 1;
		if (user_name == null) user_name = "";
		if (name == null) name = "";
		if (birthDate == null) birthDate = "";
		if (telephone == null) telephone = "";
		if(rows != 0)userInfoService.setRows(rows);
		List<UserInfo> userInfoList = userInfoService.queryUserInfo(user_name, name, birthDate, telephone, page);
	    /* Calculate the total number of pages and records */
	    userInfoService.queryTotalPageAndRecordNumber(user_name, name, birthDate, telephone);
	    /* Gets the total number of page numbers */
	    int totalPage = userInfoService.getTotalPage();
	    /* The total number of records under the current query condition */
	    int recordNumber = userInfoService.getRecordNumber();
        response.setContentType("text/json;charset=UTF-8");
		PrintWriter out = response.getWriter();
		// The object to be returned to the client 
		JSONObject jsonObj=new JSONObject();
		jsonObj.accumulate("total", recordNumber);
		JSONArray jsonArray = new JSONArray();
		for(UserInfo userInfo:userInfoList) {
			JSONObject jsonUserInfo = userInfo.getJsonObject();
			jsonArray.put(jsonUserInfo);
		}
		jsonObj.accumulate("rows", jsonArray);
		out.println(jsonObj.toString());
		out.flush();
		out.close();
	}

	/*ajax Query information according to user paging conditions */
	@RequestMapping(value = { "/listAll" }, method = {RequestMethod.GET,RequestMethod.POST})
	public void listAll(HttpServletResponse response) throws Exception {
		List<UserInfo> userInfoList = userInfoService.queryAllUserInfo();
        response.setContentType("text/json;charset=UTF-8"); 
		PrintWriter out = response.getWriter();
		JSONArray jsonArray = new JSONArray();
		for(UserInfo userInfo:userInfoList) {
			JSONObject jsonUserInfo = new JSONObject();
			jsonUserInfo.accumulate("user_name", userInfo.getUser_name());
			jsonUserInfo.accumulate("name", userInfo.getName());
			jsonArray.put(jsonUserInfo);
		}
		out.println(jsonArray.toString());
		out.flush();
		out.close();
	}

	/* The foreground queries the user information in pages according to the query conditions */
	@RequestMapping(value = { "/frontlist" }, method = {RequestMethod.GET,RequestMethod.POST})
	public String frontlist(String user_name,String name,String birthDate,String telephone,Integer currentPage, Model model, HttpServletRequest request) throws Exception  {
		if (currentPage==null || currentPage == 0) currentPage = 1;
		if (user_name == null) user_name = "";
		if (name == null) name = "";
		if (birthDate == null) birthDate = "";
		if (telephone == null) telephone = "";
		List<UserInfo> userInfoList = userInfoService.queryUserInfo(user_name, name, birthDate, telephone, currentPage);
	    /* Calculate the total number of pages and records */
	    userInfoService.queryTotalPageAndRecordNumber(user_name, name, birthDate, telephone);
	    /* Gets the total number of page numbers */
	    int totalPage = userInfoService.getTotalPage();
	    /* The total number of records under the current query condition */
	    int recordNumber = userInfoService.getRecordNumber();
	    request.setAttribute("userInfoList",  userInfoList);
	    request.setAttribute("totalPage", totalPage);
	    request.setAttribute("recordNumber", recordNumber);
	    request.setAttribute("currentPage", currentPage);
	    request.setAttribute("user_name", user_name);
	    request.setAttribute("name", name);
	    request.setAttribute("birthDate", birthDate);
	    request.setAttribute("telephone", telephone);
		return "UserInfo/userInfo_frontquery_result"; 
	}

     /* Front desk query UserInfo Information */
	@RequestMapping(value="/{user_name}/frontshow",method=RequestMethod.GET)
	public String frontshow(@PathVariable String user_name,Model model,HttpServletRequest request) throws Exception {
		/* According to primary key user_name obtain UserInfo object */
        UserInfo userInfo = userInfoService.getUserInfo(user_name);

        request.setAttribute("userInfo",  userInfo);
        return "UserInfo/userInfo_frontshow";
	}

	/*ajax Display user modification in jsp View page */
	@RequestMapping(value="/{user_name}/update",method=RequestMethod.GET)
	public void update(@PathVariable String user_name,Model model,HttpServletRequest request,HttpServletResponse response) throws Exception {
        /* According to primary key user_name obtain UserInfo object */
        UserInfo userInfo = userInfoService.getUserInfo(user_name);

        response.setContentType("text/json;charset=UTF-8");
        PrintWriter out = response.getWriter();
		// The object to be returned to the client  
		JSONObject jsonUserInfo = userInfo.getJsonObject();
		out.println(jsonUserInfo.toString());
		out.flush();
		out.close();
	}

	/*ajax To update user information */
	@RequestMapping(value = "/{user_name}/update", method = RequestMethod.POST)
	public void update(@Validated UserInfo userInfo, BindingResult br,
			Model model, HttpServletRequest request,HttpServletResponse response) throws Exception {
		String message = "";
    	boolean success = false;
		if (br.hasErrors()) { 
			message = " There is an error in the information entered !";
			writeJsonResponse(response, success, message);
			return;
		}
		String userPhotoFileName = this.handlePhotoUpload(request, "userPhotoFile");
		if(!userPhotoFileName.equals("upload/NoImage.jpg"))userInfo.setUserPhoto(userPhotoFileName); 


		try {
			userInfoService.updateUserInfo(userInfo);
			message = " User update successful !";
			success = true;
			writeJsonResponse(response, success, message);
		} catch (Exception e) {
			e.printStackTrace();
			message = " User update failed !";
			writeJsonResponse(response, success, message); 
		}
	}
    /* Delete user information */
	@RequestMapping(value="/{user_name}/delete",method=RequestMethod.GET)
	public String delete(@PathVariable String user_name,HttpServletRequest request) throws UnsupportedEncodingException {
		  try {
			  userInfoService.deleteUserInfo(user_name);
	            request.setAttribute("message", " User delete successful !");
	            return "message";
	        } catch (Exception e) { 
	            e.printStackTrace();
	            request.setAttribute("error", " User deletion failed !");
				return "error";

	        }

	}

	/*ajax To delete multiple user records */
	@RequestMapping(value="/deletes",method=RequestMethod.POST)
	public void delete(String user_names,HttpServletRequest request,HttpServletResponse response) throws IOException, JSONException {
		String message = "";
    	boolean success = false;
        try { 
        	int count = userInfoService.deleteUserInfos(user_names);
        	success = true;
        	message = count + " Records deleted successfully ";
        	writeJsonResponse(response, success, message);
        } catch (Exception e) { 
            //e.printStackTrace();
            message = " There are records of foreign key constraints , Delete failed ";
            writeJsonResponse(response, success, message);
        }
	}

	/* Export user information to according to query criteria Excel*/
	@RequestMapping(value = { "/OutToExcel" }, method = {RequestMethod.GET,RequestMethod.POST})
	public void OutToExcel(String user_name,String name,String birthDate,String telephone, Model model, HttpServletRequest request,HttpServletResponse response) throws Exception {
        if(user_name == null) user_name = "";
        if(name == null) name = "";
        if(birthDate == null) birthDate = "";
        if(telephone == null) telephone = "";
        List<UserInfo> userInfoList = userInfoService.queryUserInfo(user_name,name,birthDate,telephone);
        ExportExcelUtil ex = new ExportExcelUtil();
        String _title = "UserInfo Information records "; 
        String[] headers = { " user name "," full name "," Gender "," Date of birth "," User photos "," contact number "," mailbox "," Registration time "};
        List<String[]> dataset = new ArrayList<String[]>(); 
        for(int i=0;i<userInfoList.size();i++) {
        	UserInfo userInfo = userInfoList.get(i); 
        	dataset.add(new String[]{userInfo.getUser_name(),userInfo.getName(),userInfo.getGender(),userInfo.getBirthDate(),userInfo.getUserPhoto(),userInfo.getTelephone(),userInfo.getEmail(),userInfo.getRegTime()});
        }
        /*
        OutputStream out = null;
		try {
			out = new FileOutputStream("C://output.xls");
			ex.exportExcel(title,headers, dataset, out);
		    out.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		*/
		OutputStream out = null;// Create an output stream object  
		try { 
			out = response.getOutputStream();//
			response.setHeader("Content-disposition","attachment; filename="+"UserInfo.xls");//filename It's downloaded xls The name of , It is suggested to use English  
			response.setContentType("application/msexcel;charset=UTF-8");// Set type  
			response.setHeader("Pragma","No-cache");// Set head  
			response.setHeader("Cache-Control","no-cache");// Set head  
			response.setDateHeader("Expires", 0);// Set date header   
			String rootPath = request.getSession().getServletContext().getRealPath("/");
			ex.exportExcel(rootPath,_title,headers, dataset, out);
			out.flush();
		} catch (IOException e) { 
			e.printStackTrace(); 
		}finally{
			try{
				if(out!=null){ 
					out.close(); 
				}
			}catch(IOException e){ 
				e.printStackTrace(); 
			} 
		}
    }
}

Room management control layer :

@Controller
@RequestMapping("/Room")
public class RoomController extends BaseController {

    /* Business layer objects */
    @Resource RoomService roomService;

    @Resource RoomTypeService roomTypeService;
	@InitBinder("roomTypeObj")
	public void initBinderroomTypeObj(WebDataBinder binder) {
		binder.setFieldDefaultPrefix("roomTypeObj.");
	}
	@InitBinder("room")
	public void initBinderRoom(WebDataBinder binder) {
		binder.setFieldDefaultPrefix("room.");
	}
	/* Jump to add Room View */
	@RequestMapping(value = "/add", method = RequestMethod.GET)
	public String add(Model model,HttpServletRequest request) throws Exception {
		model.addAttribute(new Room());
		/* Query all RoomType Information */
		List<RoomType> roomTypeList = roomTypeService.queryAllRoomType();
		request.setAttribute("roomTypeList", roomTypeList);
		return "Room_add";
	}

	/* client ajax Submit and add room information */
	@RequestMapping(value = "/add", method = RequestMethod.POST)
	public void add(@Validated Room room, BindingResult br,
			Model model, HttpServletRequest request,HttpServletResponse response) throws Exception {
		String message = "";
		boolean success = false;
		if (br.hasErrors()) {
			message = " The input information does not meet the requirements !";
			writeJsonResponse(response, success, message);
			return ;
		}
		if(roomService.getRoom(room.getRoomNo()) != null) {
			message = " Room number already exists !";
			writeJsonResponse(response, success, message);
			return ;
		}
		try {
			room.setMainPhoto(this.handlePhotoUpload(request, "mainPhotoFile"));
		} catch(UserException ex) {
			message = " The picture format is not correct !";
			writeJsonResponse(response, success, message);
			return ;
		}
        roomService.addRoom(room);
        message = " Room added successfully !";
        success = true;
        writeJsonResponse(response, success, message);
	}
	/*ajax Method: query room information in pages according to query criteria */
	@RequestMapping(value = { "/list" }, method = {RequestMethod.GET,RequestMethod.POST})
	public void list(String roomNo,@ModelAttribute("roomTypeObj") RoomType roomTypeObj,String roomName,String roomState,Integer page,Integer rows, Model model, HttpServletRequest request,HttpServletResponse response) throws Exception {
		if (page==null || page == 0) page = 1;
		if (roomNo == null) roomNo = "";
		if (roomName == null) roomName = "";
		if (roomState == null) roomState = "";
		if(rows != 0)roomService.setRows(rows);
		List<Room> roomList = roomService.queryRoom(roomNo, roomTypeObj, roomName, roomState, page);
	    /* Calculate the total number of pages and records */
	    roomService.queryTotalPageAndRecordNumber(roomNo, roomTypeObj, roomName, roomState);
	    /* Gets the total number of page numbers */
	    int totalPage = roomService.getTotalPage();
	    /* The total number of records under the current query condition */
	    int recordNumber = roomService.getRecordNumber();
        response.setContentType("text/json;charset=UTF-8");
		PrintWriter out = response.getWriter();
		// The object to be returned to the client 
		JSONObject jsonObj=new JSONObject();
		jsonObj.accumulate("total", recordNumber);
		JSONArray jsonArray = new JSONArray();
		for(Room room:roomList) {
			JSONObject jsonRoom = room.getJsonObject();
			jsonArray.put(jsonRoom);
		}
		jsonObj.accumulate("rows", jsonArray);
		out.println(jsonObj.toString());
		out.flush();
		out.close();
	}

	/*ajax Method: query room information in pages according to query criteria */
	@RequestMapping(value = { "/listAll" }, method = {RequestMethod.GET,RequestMethod.POST})
	public void listAll(HttpServletResponse response) throws Exception {
		List<Room> roomList = roomService.queryAllRoom();
        response.setContentType("text/json;charset=UTF-8"); 
		PrintWriter out = response.getWriter();
		JSONArray jsonArray = new JSONArray();
		for(Room room:roomList) {
			JSONObject jsonRoom = new JSONObject();
			jsonRoom.accumulate("roomNo", room.getRoomNo());
			jsonRoom.accumulate("roomName", room.getRoomName());
			jsonArray.put(jsonRoom);
		}
		out.println(jsonArray.toString());
		out.flush();
		out.close();
	}

	/* The front desk inquires the room information in different pages according to the query conditions */
	@RequestMapping(value = { "/frontlist" }, method = {RequestMethod.GET,RequestMethod.POST})
	public String frontlist(String roomNo,@ModelAttribute("roomTypeObj") RoomType roomTypeObj,String roomName,String roomState,Integer currentPage, Model model, HttpServletRequest request) throws Exception  {
		if (currentPage==null || currentPage == 0) currentPage = 1;
		if (roomNo == null) roomNo = "";
		if (roomName == null) roomName = "";
		if (roomState == null) roomState = "";
		List<Room> roomList = roomService.queryRoom(roomNo, roomTypeObj, roomName, roomState, currentPage);
	    /* Calculate the total number of pages and records */
	    roomService.queryTotalPageAndRecordNumber(roomNo, roomTypeObj, roomName, roomState);
	    /* Gets the total number of page numbers */
	    int totalPage = roomService.getTotalPage();
	    /* The total number of records under the current query condition */
	    int recordNumber = roomService.getRecordNumber();
	    request.setAttribute("roomList",  roomList);
	    request.setAttribute("totalPage", totalPage);
	    request.setAttribute("recordNumber", recordNumber);
	    request.setAttribute("currentPage", currentPage);
	    request.setAttribute("roomNo", roomNo);
	    request.setAttribute("roomTypeObj", roomTypeObj);
	    request.setAttribute("roomName", roomName);
	    request.setAttribute("roomState", roomState);
	    List<RoomType> roomTypeList = roomTypeService.queryAllRoomType();
	    request.setAttribute("roomTypeList", roomTypeList);
		return "Room/room_frontquery_result"; 
	}

     /* Front desk query Room Information */
	@RequestMapping(value="/{roomNo}/frontshow",method=RequestMethod.GET)
	public String frontshow(@PathVariable String roomNo,Model model,HttpServletRequest request) throws Exception {
		/* According to primary key roomNo obtain Room object */
        Room room = roomService.getRoom(roomNo);

        List<RoomType> roomTypeList = roomTypeService.queryAllRoomType();
        request.setAttribute("roomTypeList", roomTypeList);
        request.setAttribute("room",  room);
        return "Room/room_frontshow";
	}

	/*ajax Display room changes in the way jsp View page */
	@RequestMapping(value="/{roomNo}/update",method=RequestMethod.GET)
	public void update(@PathVariable String roomNo,Model model,HttpServletRequest request,HttpServletResponse response) throws Exception {
        /* According to primary key roomNo obtain Room object */
        Room room = roomService.getRoom(roomNo);

        response.setContentType("text/json;charset=UTF-8");
        PrintWriter out = response.getWriter();
		// The object to be returned to the client  
		JSONObject jsonRoom = room.getJsonObject();
		out.println(jsonRoom.toString());
		out.flush();
		out.close();
	}

	/*ajax How to update room information */
	@RequestMapping(value = "/{roomNo}/update", method = RequestMethod.POST)
	public void update(@Validated Room room, BindingResult br,
			Model model, HttpServletRequest request,HttpServletResponse response) throws Exception {
		String message = "";
    	boolean success = false;
		if (br.hasErrors()) { 
			message = " There is an error in the information entered !";
			writeJsonResponse(response, success, message);
			return;
		}
		String mainPhotoFileName = this.handlePhotoUpload(request, "mainPhotoFile");
		if(!mainPhotoFileName.equals("upload/NoImage.jpg"))room.setMainPhoto(mainPhotoFileName); 


		try {
			roomService.updateRoom(room);
			message = " Room updated successfully !";
			success = true;
			writeJsonResponse(response, success, message);
		} catch (Exception e) {
			e.printStackTrace();
			message = " Room update failed !";
			writeJsonResponse(response, success, message); 
		}
	}
    /* Delete room information */
	@RequestMapping(value="/{roomNo}/delete",method=RequestMethod.GET)
	public String delete(@PathVariable String roomNo,HttpServletRequest request) throws UnsupportedEncodingException {
		  try {
			  roomService.deleteRoom(roomNo);
	            request.setAttribute("message", " Room deleted successfully !");
	            return "message";
	        } catch (Exception e) { 
	            e.printStackTrace();
	            request.setAttribute("error", " Room deletion failed !");
				return "error";

	        }

	}

	/*ajax To delete multiple room records */
	@RequestMapping(value="/deletes",method=RequestMethod.POST)
	public void delete(String roomNos,HttpServletRequest request,HttpServletResponse response) throws IOException, JSONException {
		String message = "";
    	boolean success = false;
        try { 
        	int count = roomService.deleteRooms(roomNos);
        	success = true;
        	message = count + " Records deleted successfully ";
        	writeJsonResponse(response, success, message);
        } catch (Exception e) { 
            //e.printStackTrace();
            message = " There are records of foreign key constraints , Delete failed ";
            writeJsonResponse(response, success, message);
        }
	}

	/* Export room information to according to query criteria Excel*/
	@RequestMapping(value = { "/OutToExcel" }, method = {RequestMethod.GET,RequestMethod.POST})
	public void OutToExcel(String roomNo,@ModelAttribute("roomTypeObj") RoomType roomTypeObj,String roomName,String roomState, Model model, HttpServletRequest request,HttpServletResponse response) throws Exception {
        if(roomNo == null) roomNo = "";
        if(roomName == null) roomName = "";
        if(roomState == null) roomState = "";
        List<Room> roomList = roomService.queryRoom(roomNo,roomTypeObj,roomName,roomState);
        ExportExcelUtil ex = new ExportExcelUtil();
        String _title = "Room Information records "; 
        String[] headers = { " Room number "," Room type "," Room name "," Main drawing of the room "," Room price "," Room status "};
        List<String[]> dataset = new ArrayList<String[]>(); 
        for(int i=0;i<roomList.size();i++) {
        	Room room = roomList.get(i); 
        	dataset.add(new String[]{room.getRoomNo(),room.getRoomTypeObj().getTypeName(),room.getRoomName(),room.getMainPhoto(),room.getPrice() + "",room.getRoomState()});
        }
        /*
        OutputStream out = null;
		try {
			out = new FileOutputStream("C://output.xls");
			ex.exportExcel(title,headers, dataset, out);
		    out.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		*/
		OutputStream out = null;// Create an output stream object  
		try { 
			out = response.getOutputStream();//
			response.setHeader("Content-disposition","attachment; filename="+"Room.xls");//filename It's downloaded xls The name of , It is suggested to use English  
			response.setContentType("application/msexcel;charset=UTF-8");// Set type  
			response.setHeader("Pragma","No-cache");// Set head  
			response.setHeader("Cache-Control","no-cache");// Set head  
			response.setDateHeader("Expires", 0);// Set date header   
			String rootPath = request.getSession().getServletContext().getRealPath("/");
			ex.exportExcel(rootPath,_title,headers, dataset, out);
			out.flush();
		} catch (IOException e) { 
			e.printStackTrace(); 
		}finally{
			try{
				if(out!=null){ 
					out.close(); 
				}
			}catch(IOException e){ 
				e.printStackTrace(); 
			} 
		}
    }
}

Senior management control : 

@Controller
@RequestMapping("/OldMan")
public class OldManController extends BaseController {

    /* Business layer objects */
    @Resource OldManService oldManService;

    @Resource UserInfoService userInfoService;
	@InitBinder("userObj")
	public void initBinderuserObj(WebDataBinder binder) {
		binder.setFieldDefaultPrefix("userObj.");
	}
	@InitBinder("oldMan")
	public void initBinderOldMan(WebDataBinder binder) {
		binder.setFieldDefaultPrefix("oldMan.");
	}
	/* Jump to add OldMan View */
	@RequestMapping(value = "/add", method = RequestMethod.GET)
	public String add(Model model,HttpServletRequest request) throws Exception {
		model.addAttribute(new OldMan());
		/* Query all UserInfo Information */
		List<UserInfo> userInfoList = userInfoService.queryAllUserInfo();
		request.setAttribute("userInfoList", userInfoList);
		return "OldMan_add";
	}

	/* client ajax Submit and add elderly information */
	@RequestMapping(value = "/add", method = RequestMethod.POST)
	public void add(@Validated OldMan oldMan, BindingResult br,
			Model model, HttpServletRequest request,HttpServletResponse response) throws Exception {
		String message = "";
		boolean success = false;
		if (br.hasErrors()) {
			message = " The input information does not meet the requirements !";
			writeJsonResponse(response, success, message);
			return ;
		}
		try {
			oldMan.setManPhoto(this.handlePhotoUpload(request, "manPhotoFile"));
		} catch(UserException ex) {
			message = " The picture format is not correct !";
			writeJsonResponse(response, success, message);
			return ;
		}
        oldManService.addOldMan(oldMan);
        message = " Old man added successfully !";
        success = true;
        writeJsonResponse(response, success, message);
	}
	/*ajax Method: query the elderly information in pages according to the query criteria */
	@RequestMapping(value = { "/list" }, method = {RequestMethod.GET,RequestMethod.POST})
	public void list(String name,@ModelAttribute("userObj") UserInfo userObj,String addTime,Integer page,Integer rows, Model model, HttpServletRequest request,HttpServletResponse response) throws Exception {
		if (page==null || page == 0) page = 1;
		if (name == null) name = "";
		if (addTime == null) addTime = "";
		if(rows != 0)oldManService.setRows(rows);
		List<OldMan> oldManList = oldManService.queryOldMan(name, userObj, addTime, page);
	    /* Calculate the total number of pages and records */
	    oldManService.queryTotalPageAndRecordNumber(name, userObj, addTime);
	    /* Gets the total number of page numbers */
	    int totalPage = oldManService.getTotalPage();
	    /* The total number of records under the current query condition */
	    int recordNumber = oldManService.getRecordNumber();
        response.setContentType("text/json;charset=UTF-8");
		PrintWriter out = response.getWriter();
		// The object to be returned to the client 
		JSONObject jsonObj=new JSONObject();
		jsonObj.accumulate("total", recordNumber);
		JSONArray jsonArray = new JSONArray();
		for(OldMan oldMan:oldManList) {
			JSONObject jsonOldMan = oldMan.getJsonObject();
			jsonArray.put(jsonOldMan);
		}
		jsonObj.accumulate("rows", jsonArray);
		out.println(jsonObj.toString());
		out.flush();
		out.close();
	}

	/*ajax Method: query the elderly information in pages according to the query criteria */
	@RequestMapping(value = { "/listAll" }, method = {RequestMethod.GET,RequestMethod.POST})
	public void listAll(HttpServletResponse response) throws Exception {
		List<OldMan> oldManList = oldManService.queryAllOldMan();
        response.setContentType("text/json;charset=UTF-8"); 
		PrintWriter out = response.getWriter();
		JSONArray jsonArray = new JSONArray();
		for(OldMan oldMan:oldManList) {
			JSONObject jsonOldMan = new JSONObject();
			jsonOldMan.accumulate("oldManId", oldMan.getOldManId());
			jsonOldMan.accumulate("name", oldMan.getName());
			jsonArray.put(jsonOldMan);
		}
		out.println(jsonArray.toString());
		out.flush();
		out.close();
	}

	/* The front desk inquires the information of the elderly in pages according to the query conditions */
	@RequestMapping(value = { "/frontlist" }, method = {RequestMethod.GET,RequestMethod.POST})
	public String frontlist(String name,@ModelAttribute("userObj") UserInfo userObj,String addTime,Integer currentPage, Model model, HttpServletRequest request) throws Exception  {
		if (currentPage==null || currentPage == 0) currentPage = 1;
		if (name == null) name = "";
		if (addTime == null) addTime = "";
		List<OldMan> oldManList = oldManService.queryOldMan(name, userObj, addTime, currentPage);
	    /* Calculate the total number of pages and records */
	    oldManService.queryTotalPageAndRecordNumber(name, userObj, addTime);
	    /* Gets the total number of page numbers */
	    int totalPage = oldManService.getTotalPage();
	    /* The total number of records under the current query condition */
	    int recordNumber = oldManService.getRecordNumber();
	    request.setAttribute("oldManList",  oldManList);
	    request.setAttribute("totalPage", totalPage);
	    request.setAttribute("recordNumber", recordNumber);
	    request.setAttribute("currentPage", currentPage);
	    request.setAttribute("name", name);
	    request.setAttribute("userObj", userObj);
	    request.setAttribute("addTime", addTime);
	    List<UserInfo> userInfoList = userInfoService.queryAllUserInfo();
	    request.setAttribute("userInfoList", userInfoList);
		return "OldMan/oldMan_frontquery_result"; 
	}

     /* Front desk query OldMan Information */
	@RequestMapping(value="/{oldManId}/frontshow",method=RequestMethod.GET)
	public String frontshow(@PathVariable Integer oldManId,Model model,HttpServletRequest request) throws Exception {
		/* According to primary key oldManId obtain OldMan object */
        OldMan oldMan = oldManService.getOldMan(oldManId);

        List<UserInfo> userInfoList = userInfoService.queryAllUserInfo();
        request.setAttribute("userInfoList", userInfoList);
        request.setAttribute("oldMan",  oldMan);
        return "OldMan/oldMan_frontshow";
	}

	/*ajax Display the old man's modification mode jsp View page */
	@RequestMapping(value="/{oldManId}/update",method=RequestMethod.GET)
	public void update(@PathVariable Integer oldManId,Model model,HttpServletRequest request,HttpServletResponse response) throws Exception {
        /* According to primary key oldManId obtain OldMan object */
        OldMan oldMan = oldManService.getOldMan(oldManId);

        response.setContentType("text/json;charset=UTF-8");
        PrintWriter out = response.getWriter();
		// The object to be returned to the client  
		JSONObject jsonOldMan = oldMan.getJsonObject();
		out.println(jsonOldMan.toString());
		out.flush();
		out.close();
	}

	/*ajax How to update the information of the elderly */
	@RequestMapping(value = "/{oldManId}/update", method = RequestMethod.POST)
	public void update(@Validated OldMan oldMan, BindingResult br,
			Model model, HttpServletRequest request,HttpServletResponse response) throws Exception {
		String message = "";
    	boolean success = false;
		if (br.hasErrors()) { 
			message = " There is an error in the information entered !";
			writeJsonResponse(response, success, message);
			return;
		}
		String manPhotoFileName = this.handlePhotoUpload(request, "manPhotoFile");
		if(!manPhotoFileName.equals("upload/NoImage.jpg"))oldMan.setManPhoto(manPhotoFileName); 


		try {
			oldManService.updateOldMan(oldMan);
			message = " The old man updated successfully !";
			success = true;
			writeJsonResponse(response, success, message);
		} catch (Exception e) {
			e.printStackTrace();
			message = " Old man update failed !";
			writeJsonResponse(response, success, message); 
		}
	}
    /* Delete old people's information */
	@RequestMapping(value="/{oldManId}/delete",method=RequestMethod.GET)
	public String delete(@PathVariable Integer oldManId,HttpServletRequest request) throws UnsupportedEncodingException {
		  try {
			  oldManService.deleteOldMan(oldManId);
	            request.setAttribute("message", " The old man was deleted successfully !");
	            return "message";
	        } catch (Exception e) { 
	            e.printStackTrace();
	            request.setAttribute("error", " Old man deletion failed !");
				return "error";

	        }

	}

	/*ajax To delete multiple elderly records */
	@RequestMapping(value="/deletes",method=RequestMethod.POST)
	public void delete(String oldManIds,HttpServletRequest request,HttpServletResponse response) throws IOException, JSONException {
		String message = "";
    	boolean success = false;
        try { 
        	int count = oldManService.deleteOldMans(oldManIds);
        	success = true;
        	message = count + " Records deleted successfully ";
        	writeJsonResponse(response, success, message);
        } catch (Exception e) { 
            //e.printStackTrace();
            message = " There are records of foreign key constraints , Delete failed ";
            writeJsonResponse(response, success, message);
        }
	}

	/* Export the elderly information to according to the query criteria Excel*/
	@RequestMapping(value = { "/OutToExcel" }, method = {RequestMethod.GET,RequestMethod.POST})
	public void OutToExcel(String name,@ModelAttribute("userObj") UserInfo userObj,String addTime, Model model, HttpServletRequest request,HttpServletResponse response) throws Exception {
        if(name == null) name = "";
        if(addTime == null) addTime = "";
        List<OldMan> oldManList = oldManService.queryOldMan(name,userObj,addTime);
        ExportExcelUtil ex = new ExportExcelUtil();
        String _title = "OldMan Information records "; 
        String[] headers = { " Elderly number "," full name "," Gender "," Age "," Photos of the old man "," Register users "," Registration time "};
        List<String[]> dataset = new ArrayList<String[]>(); 
        for(int i=0;i<oldManList.size();i++) {
        	OldMan oldMan = oldManList.get(i); 
        	dataset.add(new String[]{oldMan.getOldManId() + "",oldMan.getName(),oldMan.getSex(),oldMan.getAge() + "",oldMan.getManPhoto(),oldMan.getUserObj().getName(),oldMan.getAddTime()});
        }
        /*
        OutputStream out = null;
		try {
			out = new FileOutputStream("C://output.xls");
			ex.exportExcel(title,headers, dataset, out);
		    out.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		*/
		OutputStream out = null;// Create an output stream object  
		try { 
			out = response.getOutputStream();//
			response.setHeader("Content-disposition","attachment; filename="+"OldMan.xls");//filename It's downloaded xls The name of , It is suggested to use English  
			response.setContentType("application/msexcel;charset=UTF-8");// Set type  
			response.setHeader("Pragma","No-cache");// Set head  
			response.setHeader("Cache-Control","no-cache");// Set head  
			response.setDateHeader("Expires", 0);// Set date header   
			String rootPath = request.getSession().getServletContext().getRealPath("/");
			ex.exportExcel(rootPath,_title,headers, dataset, out);
			out.flush();
		} catch (IOException e) { 
			e.printStackTrace(); 
		}finally{
			try{
				if(out!=null){ 
					out.close(); 
				}
			}catch(IOException e){ 
				e.printStackTrace(); 
			} 
		}
    }
}

 

The source code for : Blog's front page " resources " Download ! 

copyright notice
author[pastclouds],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2022/119/202204291209051801.html

Random recommended