基于javaweb的养老院综合服务系统(java+ssm+jsp+jquery+echarts+mysql)

基于javaweb的养老院综合服务系统(java+ssm+jsp+jquery+echarts+mysql)

运行环境

Java≥8、MySQL≥5.7、Tomcat≥8

开发工具

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

适用

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

功能说明

20220520141345

20220520141346

20220520141348

20220520141349

20220520141350

20220520141351

20220520141352

基于javaweb+ssm的养老院综合服务系统(java+SSM+JSP+jQuery+echarts+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.数据库:MySql 5.7版本; 6.是否Maven项目:否;

技术栈

  1. 后端:Spring+SpringMVC+Mybatis 2. 前端:JSP+CSS+JavaScript+jQuery+echarts

使用说明

  1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven; 若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中spring-mvc.xml配置文件中的数据库配置改为自己的配置; 4. 运行项目,浏览器中输入http://localhost:8080/ssm_yanglaoyuan_sys 登录 管理员账号/密码:admin/admin 护工账号/密码: hugong/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();

老人管理控制层:

//OldMan管理控制层

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

护工管理控制层:

//Nurse管理控制层

@Controller

@RequestMapping(“/Nurse”)

public class NurseController extends BaseController {

/业务层对象/

@Resource NurseService nurseService;

@InitBinder(“nurse”)

public void initBinderNurse(WebDataBinder binder) {

binder.setFieldDefaultPrefix(“nurse.”);

/跳转到添加Nurse视图/

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

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

model.addAttribute(new Nurse());

return “Nurse_add”;

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

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

public void add(@Validated Nurse nurse, BindingResult br,

Model model, HttpServletRequest request,HttpServletResponse response) throws Exception {

String message = “”;

boolean success = false;

if (br.hasErrors()) {

message = “输入信息不符合要求!”;

writeJsonResponse(response, success, message);

return ;

nurseService.addNurse(nurse);

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

success = true;

writeJsonResponse(response, success, message);

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

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

public void list(String nurseType,String title,String publishDate,Integer page,Integer rows, Model model, HttpServletRequest request,HttpServletResponse response) throws Exception {

if (page==null || page == 0) page = 1;

if (nurseType == null) nurseType = “”;

if (title == null) title = “”;

if (publishDate == null) publishDate = “”;

if(rows != 0)nurseService.setRows(rows);

List nurseList = nurseService.queryNurse(nurseType, title, publishDate, page);

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

nurseService.queryTotalPageAndRecordNumber(nurseType, title, publishDate);

/获取到总的页码数目/

int totalPage = nurseService.getTotalPage();

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

int recordNumber = nurseService.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(Nurse nurse:nurseList) {

JSONObject jsonNurse = nurse.getJsonObject();

jsonArray.put(jsonNurse);

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 nurseList = nurseService.queryAllNurse();

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

PrintWriter out = response.getWriter();

JSONArray jsonArray = new JSONArray();

for(Nurse nurse:nurseList) {

JSONObject jsonNurse = new JSONObject();

jsonNurse.accumulate(“nurseId”, nurse.getNurseId());

jsonNurse.accumulate(“title”, nurse.getTitle());

jsonArray.put(jsonNurse);

out.println(jsonArray.toString());

out.flush();

out.close();

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

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

public String frontlist(String nurseType,String title,String publishDate,Integer currentPage, Model model, HttpServletRequest request) throws Exception {

if (currentPage==null || currentPage == 0) currentPage = 1;

if (nurseType == null) nurseType = “”;

if (title == null) title = “”;

if (publishDate == null) publishDate = “”;

List nurseList = nurseService.queryNurse(nurseType, title, publishDate, currentPage);

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

nurseService.queryTotalPageAndRecordNumber(nurseType, title, publishDate);

/获取到总的页码数目/

int totalPage = nurseService.getTotalPage();

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

int recordNumber = nurseService.getRecordNumber();

request.setAttribute(“nurseList”, nurseList);

request.setAttribute(“totalPage”, totalPage);

request.setAttribute(“recordNumber”, recordNumber);

request.setAttribute(“currentPage”, currentPage);

request.setAttribute(“nurseType”, nurseType);

request.setAttribute(“title”, title);

request.setAttribute(“publishDate”, publishDate);

return “Nurse/nurse_frontquery_result”;

/前台查询Nurse信息/

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

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

/根据主键nurseId获取Nurse对象/

Nurse nurse = nurseService.getNurse(nurseId);

request.setAttribute(“nurse”, nurse);

return “Nurse/nurse_frontshow”;

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

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

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

/根据主键nurseId获取Nurse对象/

Nurse nurse = nurseService.getNurse(nurseId);

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

PrintWriter out = response.getWriter();

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

JSONObject jsonNurse = nurse.getJsonObject();

out.println(jsonNurse.toString());

out.flush();

out.close();

/ajax方式更新老人看护信息/

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

public void update(@Validated Nurse nurse, 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 {

nurseService.updateNurse(nurse);

message = “老人看护更新成功!”;

success = true;

writeJsonResponse(response, success, message);

} catch (Exception e) {

e.printStackTrace();

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

writeJsonResponse(response, success, message);

/删除老人看护信息/

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

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

try {

nurseService.deleteNurse(nurseId);

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 nurseIds,HttpServletRequest request,HttpServletResponse response) throws IOException, JSONException {

String message = “”;

boolean success = false;

try {

int count = nurseService.deleteNurses(nurseIds);

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 nurseType,String title,String publishDate, Model model, HttpServletRequest request,HttpServletResponse response) throws Exception {

if(nurseType == null) nurseType = “”;

if(title == null) title = “”;

if(publishDate == null) publishDate = “”;

List nurseList = nurseService.queryNurse(nurseType,title,publishDate);

ExportExcelUtil ex = new ExportExcelUtil();

String _title = “Nurse信息记录”;

String[] headers = { “记录id”,“信息类别”,“信息标题”,“发布时间”};

List<String[]> dataset = new ArrayList<String[]>();

for(int i=0;i<nurseList.size();i++) {

Nurse nurse = nurseList.get(i);

dataset.add(new String[]{nurse.getNurseId() + “”,nurse.getNurseType(),nurse.getTitle(),nurse.getPublishDate()});

/*

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=”+“Nurse.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();

开发者涨薪指南

48位大咖的思考法则、工作方式、逻辑体系


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值