基于javaweb的养老院管理系统(java+springboot+thymeleaf+html+js+mysql)

news2024/12/24 2:18:24

基于javaweb的养老院管理系统(java+springboot+thymeleaf+html+js+mysql)

运行环境

Java≥8、MySQL≥5.7

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

20220519002336

20220519002337

20220519002338

20220519002339

20220519002340

20220519002342

基于javaweb+SpringBoot的养老院管理系统(java+SpringBoot+thymeleaf+HTML+Js+mysql)

项目介绍

基于springboot的养老院管理系统,本系统为后台管理系统,分为三个角色,分别是超级管理员、管理员、用户。 超级管理员、管理员的功能如下: 登录、修改密码、账号管理、健康档案管理、病例管理、药品管理、每月餐饮管理、外出报备、入住登记、寝室分配、事故记录、访客记录、收费管理; 其中超级管理员可进行管理员账号管理; 用户的功能如下: 登录、修改密码、个人信息、家人情况、每月餐饮管理、外出报备、查看收费标准

环境需要

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.数据库:MySql 5.7版本; 6.是否Maven项目: 是;查看源码目录中是否包含pom.xml;

若包含,则为maven项目,否则为非maven项目

技术栈

1.后端:springboot+Mybatis

2.前端:HTML+thymeleaf+Javascriipt+css

使用说明

  1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven; 若为maven项目,导入成功后请执行maven clean;maven install命令,配置tomcat; 3. 将项目中application-dev.yml配置文件中的数据库配置改为自己的配置 4. 运行项目,在浏览器中输入地址:http://localhost:8080/ 登录账号; 超级管理员:root/123456 管理员:admin/123456 用户:user/123456

用户管理控制层:

//UserInfo管理控制层

@Controller

@RequestMapping(“/UserInfo”)

public class UserInfoController extends BaseController {

/业务层对象/

@Resource UserInfoService userInfoService;

@InitBinder(“userInfo”)

public void initBinderUserInfo(WebDataBinder binder) {

binder.setFieldDefaultPrefix(“userInfo.”);

/跳转到添加UserInfo视图/

@RequestMapping(value = “/add”, method = RequestMethod.GET)

public String add(Model model,HttpServletRequest request) throws Exception {

model.addAttribute(new UserInfo());

return “UserInfo_add”;

/客户端ajax方式提交添加用户信息/

@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 = “输入信息不符合要求!”;

writeJsonResponse(response, success, message);

return ;

if(userInfoService.getUserInfo(userInfo.getUser_name()) != null) {

message = “用户名已经存在!”;

writeJsonResponse(response, success, message);

return ;

try {

userInfo.setUserPhoto(this.handlePhotoUpload(request, “userPhotoFile”));

} catch(UserException ex) {

message = “图片格式不正确!”;

writeJsonResponse(response, success, message);

return ;

userInfoService.addUserInfo(userInfo);

message = “用户添加成功!”;

success = true;

writeJsonResponse(response, success, message);

/ajax方式按照查询条件分页查询用户信息/

@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 userInfoList = userInfoService.queryUserInfo(user_name, name, birthDate, telephone, page);

/计算总的页数和总的记录数/

userInfoService.queryTotalPageAndRecordNumber(user_name, name, birthDate, telephone);

/获取到总的页码数目/

int totalPage = userInfoService.getTotalPage();

/当前查询条件下总记录数/

int recordNumber = userInfoService.getRecordNumber();

response.setContentType(“text/json;charset=UTF-8”);

PrintWriter out = response.getWriter();

//将要被返回到客户端的对象

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方式按照查询条件分页查询用户信息/

@RequestMapping(value = { “/listAll” }, method = {RequestMethod.GET,RequestMethod.POST})

public void listAll(HttpServletResponse response) throws Exception {

List 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();

/前台按照查询条件分页查询用户信息/

@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 userInfoList = userInfoService.queryUserInfo(user_name, name, birthDate, telephone, currentPage);

/计算总的页数和总的记录数/

userInfoService.queryTotalPageAndRecordNumber(user_name, name, birthDate, telephone);

/获取到总的页码数目/

int totalPage = userInfoService.getTotalPage();

/当前查询条件下总记录数/

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”;

/前台查询UserInfo信息/

@RequestMapping(value=“/{user_name}/frontshow”,method=RequestMethod.GET)

public String frontshow(@PathVariable String user_name,Model model,HttpServletRequest request) throws Exception {

/根据主键user_name获取UserInfo对象/

UserInfo userInfo = userInfoService.getUserInfo(user_name);

request.setAttribute(“userInfo”, userInfo);

return “UserInfo/userInfo_frontshow”;

/ajax方式显示用户修改jsp视图页/

@RequestMapping(value=“/{user_name}/update”,method=RequestMethod.GET)

public void update(@PathVariable String user_name,Model model,HttpServletRequest request,HttpServletResponse response) throws Exception {

/根据主键user_name获取UserInfo对象/

UserInfo userInfo = userInfoService.getUserInfo(user_name);

response.setContentType(“text/json;charset=UTF-8”);

PrintWriter out = response.getWriter();

//将要被返回到客户端的对象

JSONObject jsonUserInfo = userInfo.getJsonObject();

out.println(jsonUserInfo.toString());

out.flush();

out.close();

/ajax方式更新用户信息/

@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 = “输入的信息有错误!”;

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 = “用户更新成功!”;

success = true;

writeJsonResponse(response, success, message);

} catch (Exception e) {

e.printStackTrace();

message = “用户更新失败!”;

writeJsonResponse(response, success, message);

/删除用户信息/

@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”, “用户删除成功!”);

return “message”;

} catch (Exception e) {

e.printStackTrace();

request.setAttribute(“error”, “用户删除失败!”);

return “error”;

/ajax方式删除多条用户记录/

@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 + “条记录删除成功”;

writeJsonResponse(response, success, message);

} catch (Exception e) {

//e.printStackTrace();

message = “有记录存在外键约束,删除失败”;

writeJsonResponse(response, success, message);

/按照查询条件导出用户信息到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 userInfoList = userInfoService.queryUserInfo(user_name,name,birthDate,telephone);

ExportExcelUtil ex = new ExportExcelUtil();

String _title = “UserInfo信息记录”;

String[] headers = { “用户名”,“姓名”,“性别”,“出生日期”,“用户照片”,“联系电话”,“邮箱”,“注册时间”};

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;//创建一个输出流对象

try {

out = response.getOutputStream();//

response.setHeader(“Content-disposition”,“attachment; filename=”+“UserInfo.xls”);//filename是下载的xls的名,建议最好用英文

response.setContentType(“application/msexcel;charset=UTF-8”);//设置类型

response.setHeader(“Pragma”,“No-cache”);//设置头

response.setHeader(“Cache-Control”,“no-cache”);//设置头

response.setDateHeader(“Expires”, 0);//设置日期头

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();

房间管理控制层:

@Controller

@RequestMapping(“/Room”)

public class RoomController extends BaseController {

/业务层对象/

@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.”);

/跳转到添加Room视图/

@RequestMapping(value = “/add”, method = RequestMethod.GET)

public String add(Model model,HttpServletRequest request) throws Exception {

model.addAttribute(new Room());

/查询所有的RoomType信息/

List roomTypeList = roomTypeService.queryAllRoomType();

request.setAttribute(“roomTypeList”, roomTypeList);

return “Room_add”;

/客户端ajax方式提交添加房间信息/

@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 = “输入信息不符合要求!”;

writeJsonResponse(response, success, message);

return ;

if(roomService.getRoom(room.getRoomNo()) != null) {

message = “房间编号已经存在!”;

writeJsonResponse(response, success, message);

return ;

try {

room.setMainPhoto(this.handlePhotoUpload(request, “mainPhotoFile”));

} catch(UserException ex) {

message = “图片格式不正确!”;

writeJsonResponse(response, success, message);

return ;

roomService.addRoom(room);

message = “房间添加成功!”;

success = true;

writeJsonResponse(response, success, message);

/ajax方式按照查询条件分页查询房间信息/

@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 roomList = roomService.queryRoom(roomNo, roomTypeObj, roomName, roomState, page);

/计算总的页数和总的记录数/

roomService.queryTotalPageAndRecordNumber(roomNo, roomTypeObj, roomName, roomState);

/获取到总的页码数目/

int totalPage = roomService.getTotalPage();

/当前查询条件下总记录数/

int recordNumber = roomService.getRecordNumber();

response.setContentType(“text/json;charset=UTF-8”);

PrintWriter out = response.getWriter();

//将要被返回到客户端的对象

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方式按照查询条件分页查询房间信息/

@RequestMapping(value = { “/listAll” }, method = {RequestMethod.GET,RequestMethod.POST})

public void listAll(HttpServletResponse response) throws Exception {

List 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();

/前台按照查询条件分页查询房间信息/

@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 roomList = roomService.queryRoom(roomNo, roomTypeObj, roomName, roomState, currentPage);

/计算总的页数和总的记录数/

roomService.queryTotalPageAndRecordNumber(roomNo, roomTypeObj, roomName, roomState);

/获取到总的页码数目/

int totalPage = roomService.getTotalPage();

/当前查询条件下总记录数/

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 roomTypeList = roomTypeService.queryAllRoomType();

request.setAttribute(“roomTypeList”, roomTypeList);

return “Room/room_frontquery_result”;

/前台查询Room信息/

@RequestMapping(value=“/{roomNo}/frontshow”,method=RequestMethod.GET)

public String frontshow(@PathVariable String roomNo,Model model,HttpServletRequest request) throws Exception {

/根据主键roomNo获取Room对象/

Room room = roomService.getRoom(roomNo);

List roomTypeList = roomTypeService.queryAllRoomType();

request.setAttribute(“roomTypeList”, roomTypeList);

request.setAttribute(“room”, room);

return “Room/room_frontshow”;

/ajax方式显示房间修改jsp视图页/

@RequestMapping(value=“/{roomNo}/update”,method=RequestMethod.GET)

public void update(@PathVariable String roomNo,Model model,HttpServletRequest request,HttpServletResponse response) throws Exception {

/根据主键roomNo获取Room对象/

Room room = roomService.getRoom(roomNo);

response.setContentType(“text/json;charset=UTF-8”);

PrintWriter out = response.getWriter();

//将要被返回到客户端的对象

JSONObject jsonRoom = room.getJsonObject();

out.println(jsonRoom.toString());

out.flush();

out.close();

/ajax方式更新房间信息/

@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 = “输入的信息有错误!”;

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 = “房间更新成功!”;

success = true;

writeJsonResponse(response, success, message);

} catch (Exception e) {

e.printStackTrace();

message = “房间更新失败!”;

writeJsonResponse(response, success, message);

/删除房间信息/

@RequestMapping(value=“/{roomNo}/delete”,method=RequestMethod.GET)

public String delete(@PathVariable String roomNo,HttpServletRequest request) throws UnsupportedEncodingException {

try {

roomService.deleteRoom(roomNo);

request.setAttribute(“message”, “房间删除成功!”);

return “message”;

} catch (Exception e) {

e.printStackTrace();

request.setAttribute(“error”, “房间删除失败!”);

return “error”;

/ajax方式删除多条房间记录/

@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 + “条记录删除成功”;

writeJsonResponse(response, success, message);

} catch (Exception e) {

//e.printStackTrace();

message = “有记录存在外键约束,删除失败”;

writeJsonResponse(response, success, message);

/按照查询条件导出房间信息到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 roomList = roomService.queryRoom(roomNo,roomTypeObj,roomName,roomState);

ExportExcelUtil ex = new ExportExcelUtil();

String _title = “Room信息记录”;

String[] headers = { “房间编号”,“房间类型”,“房间名称”,“房间主图”,“房间价格”,“房间状态”};

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;//创建一个输出流对象

try {

out = response.getOutputStream();//

response.setHeader(“Content-disposition”,“attachment; filename=”+“Room.xls”);//filename是下载的xls的名,建议最好用英文

response.setContentType(“application/msexcel;charset=UTF-8”);//设置类型

response.setHeader(“Pragma”,“No-cache”);//设置头

response.setHeader(“Cache-Control”,“no-cache”);//设置头

response.setDateHeader(“Expires”, 0);//设置日期头

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();

老人管理控制层:

@Controller

@RequestMapping(“/OldMan”)

public class OldManController extends BaseController {

/业务层对象/

@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.”);

/跳转到添加OldMan视图/

@RequestMapping(value = “/add”, method = RequestMethod.GET)

public String add(Model model,HttpServletRequest request) throws Exception {

model.addAttribute(new OldMan());

/查询所有的UserInfo信息/

List userInfoList = userInfoService.queryAllUserInfo();

request.setAttribute(“userInfoList”, userInfoList);

return “OldMan_add”;

/客户端ajax方式提交添加老人信息/

@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 = “输入信息不符合要求!”;

writeJsonResponse(response, success, message);

return ;

try {

oldMan.setManPhoto(this.handlePhotoUpload(request, “manPhotoFile”));

} catch(UserException ex) {

message = “图片格式不正确!”;

writeJsonResponse(response, success, message);

return ;

oldManService.addOldMan(oldMan);

message = “老人添加成功!”;

success = true;

writeJsonResponse(response, success, message);

/ajax方式按照查询条件分页查询老人信息/

@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 oldManList = oldManService.queryOldMan(name, userObj, addTime, page);

/计算总的页数和总的记录数/

oldManService.queryTotalPageAndRecordNumber(name, userObj, addTime);

/获取到总的页码数目/

int totalPage = oldManService.getTotalPage();

/当前查询条件下总记录数/

int recordNumber = oldManService.getRecordNumber();

response.setContentType(“text/json;charset=UTF-8”);

PrintWriter out = response.getWriter();

//将要被返回到客户端的对象

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方式按照查询条件分页查询老人信息/

@RequestMapping(value = { “/listAll” }, method = {RequestMethod.GET,RequestMethod.POST})

public void listAll(HttpServletResponse response) throws Exception {

List 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();

/前台按照查询条件分页查询老人信息/

@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 oldManList = oldManService.queryOldMan(name, userObj, addTime, currentPage);

/计算总的页数和总的记录数/

oldManService.queryTotalPageAndRecordNumber(name, userObj, addTime);

/获取到总的页码数目/

int totalPage = oldManService.getTotalPage();

/当前查询条件下总记录数/

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 userInfoList = userInfoService.queryAllUserInfo();

request.setAttribute(“userInfoList”, userInfoList);

return “OldMan/oldMan_frontquery_result”;

/前台查询OldMan信息/

@RequestMapping(value=“/{oldManId}/frontshow”,method=RequestMethod.GET)

public String frontshow(@PathVariable Integer oldManId,Model model,HttpServletRequest request) throws Exception {

/根据主键oldManId获取OldMan对象/

OldMan oldMan = oldManService.getOldMan(oldManId);

List userInfoList = userInfoService.queryAllUserInfo();

request.setAttribute(“userInfoList”, userInfoList);

request.setAttribute(“oldMan”, oldMan);

return “OldMan/oldMan_frontshow”;

/ajax方式显示老人修改jsp视图页/

@RequestMapping(value=“/{oldManId}/update”,method=RequestMethod.GET)

public void update(@PathVariable Integer oldManId,Model model,HttpServletRequest request,HttpServletResponse response) throws Exception {

/根据主键oldManId获取OldMan对象/

OldMan oldMan = oldManService.getOldMan(oldManId);

response.setContentType(“text/json;charset=UTF-8”);

PrintWriter out = response.getWriter();

//将要被返回到客户端的对象

JSONObject jsonOldMan = oldMan.getJsonObject();

out.println(jsonOldMan.toString());

out.flush();

out.close();

/ajax方式更新老人信息/

@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 = “输入的信息有错误!”;

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 = “老人更新成功!”;

success = true;

writeJsonResponse(response, success, message);

} catch (Exception e) {

e.printStackTrace();

message = “老人更新失败!”;

writeJsonResponse(response, success, message);

/删除老人信息/

@RequestMapping(value=“/{oldManId}/delete”,method=RequestMethod.GET)

public String delete(@PathVariable Integer oldManId,HttpServletRequest request) throws UnsupportedEncodingException {

try {

oldManService.deleteOldMan(oldManId);

request.setAttribute(“message”, “老人删除成功!”);

return “message”;

} catch (Exception e) {

e.printStackTrace();

request.setAttribute(“error”, “老人删除失败!”);

return “error”;

/ajax方式删除多条老人记录/

@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 + “条记录删除成功”;

writeJsonResponse(response, success, message);

} catch (Exception e) {

//e.printStackTrace();

message = “有记录存在外键约束,删除失败”;

writeJsonResponse(response, success, message);

/按照查询条件导出老人信息到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 oldManList = oldManService.queryOldMan(name,userObj,addTime);

ExportExcelUtil ex = new ExportExcelUtil();

String _title = “OldMan信息记录”;

String[] headers = { “老人编号”,“姓名”,“性别”,“年龄”,“老人照片”,“登记用户”,“登记时间”};

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;//创建一个输出流对象

try {

out = response.getOutputStream();//

response.setHeader(“Content-disposition”,“attachment; filename=”+“OldMan.xls”);//filename是下载的xls的名,建议最好用英文

response.setContentType(“application/msexcel;charset=UTF-8”);//设置类型

response.setHeader(“Pragma”,“No-cache”);//设置头

response.setHeader(“Cache-Control”,“no-cache”);//设置头

response.setDateHeader(“Expires”, 0);//设置日期头

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();


本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1141.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

synchronized到底锁的是谁、何时生效

一、synchronized锁的几种形式 synchronized修饰普通方法synchronized修饰静态方法synchronized修饰代码块 1、synchronized修饰普通方法 简单示例 public class Test{private String age;private String name;public synchronized void print(String arg1, String arg2) {…

零代码,让业务人员实现应用创造自由

摘要&#xff1a;以汽车营销场景为例&#xff0c;从AppCube零代码和业务大屏入手&#xff0c;帮助开发者更好地理解AppCube低代码和零代码异同点&#xff0c;在实际使用时能更快选取更合适的工具能力&#xff0c;实现应用构建效率最大化。本文分享自华为云社区《DTT第8期直播回…

超级详细的Vue安装与配置教程

Vue web前端三大主流框架之一,是一套用于构建用户界面的渐进式框架,下面这篇文章主要给大家介绍了关于Vue安装与配置教程的相关资料,文中通过图文介绍的非常详细,需要的朋友可以参考下 − 目录 一、下载和安装Vue二、创建全局安装目录和缓存日志目录三、配置环境变量 1. 环境…

【k哥爬虫普法】简历大数据公司被查封,个人隐私是红线!

我国目前并未出台专门针对网络爬虫技术的法律规范&#xff0c;但在司法实践中&#xff0c;相关判决已屡见不鲜&#xff0c;K 哥特设了“K哥爬虫普法”专栏&#xff0c;本栏目通过对真实案例的分析&#xff0c;旨在提高广大爬虫工程师的法律意识&#xff0c;知晓如何合法合规利用…

mysql忘记密码怎么办(附免密登录和修改密码)

前言 博主个人社区&#xff1a;开发与算法学习社区 博主个人主页&#xff1a;Killing Vibe的博客 欢迎大家加入&#xff0c;一起交流学习~~ 一、打开MySQL&#xff08;能打开请跳过此步&#xff09; 第一种&#xff1a;安装完MySQL之后&#xff0c;MySQL提供大家的客户端程序 …

DASCTF X GFCTF 2022十月挑战赛-hade_waibo

这是一个非预期解&#xff0c;但是得到出题人的赞许&#xff0c;莫名开心&#xff0c;哈哈&#xff1a; cancan need处存在任意文件读取 <!DOCTYPE html> <html lang"en" class"no-js"> <head> <meta charset"UTF-8" />…

引爆记忆广告语盘点

在数字化、流量红利见顶、营销环境巨变的进程中&#xff0c;品牌传播的节奏从快到稳。品牌出圈更需要产品、渠道、内容、文化等方面的共振影响&#xff0c;其中广告语作为品牌定位和价值主张的核心载体&#xff0c;是连接消费者心智的重要品牌资产。 根据益普索Ipsos《引爆记忆…

uni-app、小程序项目分包经验之谈与天坑异常:RangeError: Maximum call stack size exceeded

小程序分包经验之谈与天坑异常&#xff1a;RangeError: Maximum call stack size exceeded小程序分包概述分包配置参数&#xff1a;subPackages分包预载配置参数&#xff1a;preloadRule如何使用实际小程序项目分包项目结构配置分包配置分包预载天坑异常场景分析猜想尝试解决解…

springboot配置多个数据源

一.多数据源的典型使用场景 在实际开发中,经常可能遇到在一个应用中可能要访问多个数据库多的情况,以下是两种典型场景 1.业务复杂 数据分布在不同的数据库中,数据库拆了,应用没拆.一个公司多个子项目,各用各的数据库,设计数据共享 2.读写分离 为了解决数据库的性能瓶颈(读…

C++内存管理和模板

目录 内存管理 new T[N] new和delete关键字的总结&#xff1a; 定位new表达式(placement-new)&#xff1a; 作用&#xff1a; 使用格式&#xff1a; 使用场景&#xff1a; 实例&#xff1a; 调用析构函数的两个方法&#xff1a; 池化技术&#xff1a; 面试题&#xff1…

Unity 分享 功能 用Unity Native Share Plugin 实现链接、图片、视频等文件的分享+ 安卓 Ios 都可以,代码图文详解

Unity 分享 功能 用Unity Native Share Plugin 实现链接、图片、视频等文件的分享 安卓 Ios 都可以&#xff0c;代码图文详解前言环境效果一、Unity Native Share Plugin导入1.下载2.导入二、案例1.分享文字1.脚本2.发包注意2.分享视频1.完善下刚才的脚本2.给复制按钮添加点击事…

【Linux】Linux环境搭建

​&#x1f320; 作者&#xff1a;阿亮joy. &#x1f386;专栏&#xff1a;《学会Linux》 &#x1f387; 座右铭&#xff1a;每个优秀的人都有一段沉默的时光&#xff0c;那段时光是付出了很多努力却得不到结果的日子&#xff0c;我们把它叫做扎根 目录&#x1f449;Linux的介…

【QT 自研上位机 与 STM32F103下位机联调>>>通信测试-基础样例-联合文章】

【QT 自研上位机 与 STM32F103下位机联调>>>通信测试-基础样例-联合文章】1、概述2、实验环境3、联合文章&#xff08;1&#xff09;对于上位机&#xff0c;可以参照如下例子&#xff08;2&#xff09;对于下位机&#xff0c;可以参照如下例子4、QT上位机部分第一步&a…

python中os库的使用

目录介绍1 listdir(path: str)2 path.isdir(path: str)3 path.isfile(path: str)4 path.join(path: str, file: str)5 path.getsize(path: str)介绍 本博客记录python中os库的一些函数使用。 1 listdir(path: str) listdir()函数输入一个目录&#xff0c;返回该目录下的所有…

web前端 html+css+javascript游戏网页设计实例 (网页制作课作业)

&#x1f389;精彩专栏推荐&#x1f447;&#x1f3fb;&#x1f447;&#x1f3fb;&#x1f447;&#x1f3fb; ✍️ 作者简介: 一个热爱把逻辑思维转变为代码的技术博主 &#x1f482; 作者主页: 【主页——&#x1f680;获取更多优质源码】 &#x1f393; web前端期末大作业…

数字化浪潮下,低代码能否加速企业的数字化转型

随着加快建设数字中国的目标明确下来&#xff0c;市场上与数字化相关的企业都得到了极大鼓舞&#xff0c;这不仅意味着后续数字领域的加速发展&#xff0c;更是代表着数字化已经完全可以向各行各业拓展&#xff0c;大力推进数字化建设。数字中国也说明了数字化并不能只是限制在…

FastTunnel Win10内网穿透实现远程桌面

目录 一、需求 二、购买公网服务器 三、远程公网服务器 四、FastTunnel 的使用 1.下载 FastTunnel 2.启动服务器端 3.启动客户端 五、测试 六、安装服务 结束 一、需求 FastTunnel 简介 高性能跨平台内网穿透工具&#xff0c;使用它可以实现将内网服务暴露到公网供…

【数据结构与算法】时间复杂度和空间复杂度

✨ 个人主页&#xff1a;bit me ✨ 当前专栏&#xff1a;数据结构 &#x1f31f;每日一语&#xff1a;窗外有风景 笔下有前途 低头是题海 抬头是鹏程 时间复杂度和空间复杂度的认知&#x1f30e; 一. 如何衡量一个算法的好坏&#x1f319; 二. 算法效率&#x1fa90; 三. 时间…

Word处理控件Aspose.Words功能演示:在 Python 中将 TXT 文件转换为 PDF

各种人使用记事本以TXT格式记下重点或快速创建笔记。此外&#xff0c;TXT 文件用于在各种应用程序中存储纯文本。但是&#xff0c;由于记事本不提供高级功能&#xff0c;因此 TXT 文件通常会转换为PDF。为了以编程方式自动将 TXT 转换为 PDF&#xff0c;本文介绍了如何在 Pytho…

WEB API 接口签名sign验证入门与实战

目录参考什么是加解密加密方式分类对称加密技术非对称加密技术&#xff08;RSA加密算法&#xff09;&#xff08;数字证书&#xff09;场景1&#xff1a;公钥加密&#xff0c;私钥解密场景2&#xff1a;秘钥加密&#xff1a;数字签名&#xff0c;公钥解密&#xff1a;验证签名M…