基于javaweb+mysql的ssm养老院管理系统(java+ssm+jsp+easyui+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SSM养老院管理系统(java+ssm+jsp+easyui+mysql)
运行环境:
JDK1.8、tomcat8、eclipse、mysql5.6、Navicat
功能实现:
用户: 用户名,登录密码,姓名,性别,出生日期,用户照片,联系电话,邮箱,家庭地址,注册时间 老人: 老人编号,姓名,性别,年龄,老人照片,老人介绍,登记用户,登记时间 房间类型: 房间类型id,房间类型名称 房间: 房间编号,房间类型,房间名称,房间主图,房间价格,房间详情,房间状态 订单: 订单编号,入住房间,入住老人,入住日期,入住时间,订单总金额,订单状态,订单费用明细,订单时间 老人看护: 记录id,信息类别,信息标题,信息内容,发布时间 接待: 接待记录id,接待类别,接待主题,接待内容,接待日期 部门: 部门编号,部门名称,成立日期,负责人 员工: 用户名,登录密码,所在部门,姓名,性别,出生日期,员工照片,联系电话,家庭地址 工资: 工资id,员工,工资年份,工资月份,工资金额,发放日期,工资备注
} catch (Exception e) {
e.printStackTrace();
message = "接待更新失败!";
writeJsonResponse(response, success, message);
}
}
/*删除接待信息*/
@RequestMapping(value="/{receptionId}/delete",method=RequestMethod.GET)
public String delete(@PathVariable Integer receptionId,HttpServletRequest request) throws UnsupportedEncodingException {
try {
receptionService.deleteReception(receptionId);
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 receptionIds,HttpServletRequest request,HttpServletResponse response) throws IOException, JSONException {
String message = "";
boolean success = false;
try {
int count = receptionService.deleteReceptions(receptionIds);
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 receptType,String title,String receptDate, Model model, HttpServletRequest request,HttpServletResponse response) throws Exception {
if(receptType == null) receptType = "";
if(title == null) title = "";
if(receptDate == null) receptDate = "";
List<Reception> receptionList = receptionService.queryReception(receptType,title,receptDate);
ExportExcelUtil ex = new ExportExcelUtil();
String _title = "Reception信息记录";
String[] headers = { "接待记录id","接待类别","接待主题","接待日期"};
List<String[]> dataset = new ArrayList<String[]>();
for(int i=0;i<receptionList.size();i++) {
throw new UserException("数据格式输入不正确!");
}
}
setValue(value);
}
});
}
/**
* 处理图片文件上传,返回保存的文件名路径
* fileKeyName: 图片上传表单key
* @throws IOException
* @throws IllegalStateException
*/
public String handlePhotoUpload(HttpServletRequest request,String fileKeyName) throws IllegalStateException, IOException {
String fileName = "upload/NoImage.jpg";
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
/**构建图片保存的目录**/
String photoBookPathDir = "/upload";
/**得到图片保存目录的真实路径**/
String photoBookRealPathDir = request.getSession().getServletContext().getRealPath(photoBookPathDir);
/**根据真实路径创建目录**/
File photoBookSaveFile = new File(photoBookRealPathDir);
if(!photoBookSaveFile.exists())
photoBookSaveFile.mkdirs();
/**页面控件的文件流**/
MultipartFile multipartFile_photoBook = multipartRequest.getFile(fileKeyName);
if(!multipartFile_photoBook.isEmpty()) {
/**获取文件的后缀**/
String suffix = multipartFile_photoBook.getOriginalFilename().substring
(multipartFile_photoBook.getOriginalFilename().lastIndexOf("."));
String smallSuffix = suffix.toLowerCase();
if(!smallSuffix.equals(".jpg") && !smallSuffix.equals(".gif") && !smallSuffix.equals(".png") )
throw new UserException("图片格式不正确!");
/**使用UUID生成文件名称**/
String photoBookFileName = UUID.randomUUID().toString()+ suffix;//构建文件名称
//String logImageName = multipartFile.getOriginalFilename();
/**拼成完整的文件保存路径加文件**/
String photoBookFilePath = photoBookRealPathDir + File.separator + photoBookFileName;
File photoBookFile = new File(photoBookFilePath);
multipartFile_photoBook.transferTo(photoBookFile);
fileName = "upload/" + photoBookFileName;
}
return fileName;
}
/**
* 处理图片文件上传,返回保存的文件名路径
e.printStackTrace();
}finally{
try{
if(out!=null){
out.close();
}
}catch(IOException e){
e.printStackTrace();
}
}
}
}
/*ajax方式更新工资信息*/
@RequestMapping(value = "/{salaryId}/update", method = RequestMethod.POST)
public void update(@Validated Salary salary, 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 {
salaryService.updateSalary(salary);
message = "工资更新成功!";
success = true;
writeJsonResponse(response, success, message);
} catch (Exception e) {
e.printStackTrace();
message = "工资更新失败!";
writeJsonResponse(response, success, message);
}
}
/*删除工资信息*/
@RequestMapping(value="/{salaryId}/delete",method=RequestMethod.GET)
public String delete(@PathVariable Integer salaryId,HttpServletRequest request) throws UnsupportedEncodingException {
try {
salaryService.deleteSalary(salaryId);
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 salaryIds,HttpServletRequest request,HttpServletResponse response) throws IOException, JSONException {
String message = "";
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="+"RoomOrder.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();
}
}
}
}
} catch(Exception ex) {
throw new UserException("数据格式输入不正确!");
}
}
setValue(value);
}
});
//binder.registerCustomEditor(Integer.class, null,new CustomNumberEditor(Integer.class, null, true));
binder.registerCustomEditor(Float.class, new PropertyEditorSupport() {
@Override
public String getAsText() {
return (getValue() == null)? "" : getValue().toString();
}
@Override
public void setAsText(String text) {
Float value = null;
if (null != text && !text.equals("")) {
try {
value = Float.valueOf(text);
} catch (Exception e) {
throw new UserException("数据格式输入不正确!");
}
}
setValue(value);
}
});
}
/**
* 处理图片文件上传,返回保存的文件名路径
* fileKeyName: 图片上传表单key
* @throws IOException
* @throws IllegalStateException
*/
public String handlePhotoUpload(HttpServletRequest request,String fileKeyName) throws IllegalStateException, IOException {
String fileName = "upload/NoImage.jpg";
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
/**构建图片保存的目录**/
String photoBookPathDir = "/upload";
/**得到图片保存目录的真实路径**/
String photoBookRealPathDir = request.getSession().getServletContext().getRealPath(photoBookPathDir);
/**根据真实路径创建目录**/
File photoBookSaveFile = new File(photoBookRealPathDir);
if(!photoBookSaveFile.exists())
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();
}
}
}
}
return "Salary/salary_frontshow";
}
/*ajax方式显示工资修改jsp视图页*/
@RequestMapping(value="/{salaryId}/update",method=RequestMethod.GET)
public void update(@PathVariable Integer salaryId,Model model,HttpServletRequest request,HttpServletResponse response) throws Exception {
/*根据主键salaryId获取Salary对象*/
Salary salary = salaryService.getSalary(salaryId);
response.setContentType("text/json;charset=UTF-8");
PrintWriter out = response.getWriter();
//将要被返回到客户端的对象
JSONObject jsonSalary = salary.getJsonObject();
out.println(jsonSalary.toString());
out.flush();
out.close();
}
/*ajax方式更新工资信息*/
@RequestMapping(value = "/{salaryId}/update", method = RequestMethod.POST)
public void update(@Validated Salary salary, 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 {
salaryService.updateSalary(salary);
message = "工资更新成功!";
success = true;
writeJsonResponse(response, success, message);
} catch (Exception e) {
e.printStackTrace();
message = "工资更新失败!";
writeJsonResponse(response, success, message);
}
}
/*删除工资信息*/
@RequestMapping(value="/{salaryId}/delete",method=RequestMethod.GET)
public String delete(@PathVariable Integer salaryId,HttpServletRequest request) throws UnsupportedEncodingException {
try {
salaryService.deleteSalary(salaryId);
request.setAttribute("message", "工资删除成功!");
}
/*前台查询Employee信息*/
@RequestMapping(value="/{employeeNo}/frontshow",method=RequestMethod.GET)
public String frontshow(@PathVariable String employeeNo,Model model,HttpServletRequest request) throws Exception {
/*根据主键employeeNo获取Employee对象*/
Employee employee = employeeService.getEmployee(employeeNo);
List<Department> departmentList = departmentService.queryAllDepartment();
request.setAttribute("departmentList", departmentList);
request.setAttribute("employee", employee);
return "Employee/employee_frontshow";
}
/*ajax方式显示员工修改jsp视图页*/
@RequestMapping(value="/{employeeNo}/update",method=RequestMethod.GET)
public void update(@PathVariable String employeeNo,Model model,HttpServletRequest request,HttpServletResponse response) throws Exception {
/*根据主键employeeNo获取Employee对象*/
Employee employee = employeeService.getEmployee(employeeNo);
response.setContentType("text/json;charset=UTF-8");
PrintWriter out = response.getWriter();
//将要被返回到客户端的对象
JSONObject jsonEmployee = employee.getJsonObject();
out.println(jsonEmployee.toString());
out.flush();
out.close();
}
/*ajax方式更新员工信息*/
@RequestMapping(value = "/{employeeNo}/update", method = RequestMethod.POST)
public void update(@Validated Employee employee, 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 employeePhotoFileName = this.handlePhotoUpload(request, "employeePhotoFile");
if(!employeePhotoFileName.equals("upload/NoImage.jpg"))employee.setEmployeePhoto(employeePhotoFileName);
try {
employeeService.updateEmployee(employee);
message = "员工更新成功!";
success = true;
writeJsonResponse(response, success, message);
} catch (Exception e) {
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();
}
}
}
}
@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 {
binder.registerCustomEditor(Date.class, new CustomDateEditor(
new SimpleDateFormat("yyyy-MM-dd"), false));
binder.registerCustomEditor(Integer.class, new PropertyEditorSupport() {
@Override
public String getAsText() {
return (getValue() == null) ? "" : getValue().toString();
}
@Override
public void setAsText(String text) {
Integer value = null;
if (null != text && !text.equals("")) {
try {
value = Integer.valueOf(text);
} catch(Exception ex) {
throw new UserException("数据格式输入不正确!");
}
}
setValue(value);
}
});
//binder.registerCustomEditor(Integer.class, null,new CustomNumberEditor(Integer.class, null, true));
binder.registerCustomEditor(Float.class, new PropertyEditorSupport() {
@Override
public String getAsText() {
return (getValue() == null)? "" : getValue().toString();
}
@Override
public void setAsText(String text) {
Float value = null;
if (null != text && !text.equals("")) {
try {
value = Float.valueOf(text);
} catch (Exception e) {
throw new UserException("数据格式输入不正确!");
}
}
setValue(value);
}
});
}
/**
* 处理图片文件上传,返回保存的文件名路径
* fileKeyName: 图片上传表单key
* @throws IOException
jsonReception.accumulate("title", reception.getTitle());
jsonArray.put(jsonReception);
}
out.println(jsonArray.toString());
out.flush();
out.close();
}
/*前台按照查询条件分页查询接待信息*/
@RequestMapping(value = { "/frontlist" }, method = {RequestMethod.GET,RequestMethod.POST})
public String frontlist(String receptType,String title,String receptDate,Integer currentPage, Model model, HttpServletRequest request) throws Exception {
if (currentPage==null || currentPage == 0) currentPage = 1;
if (receptType == null) receptType = "";
if (title == null) title = "";
if (receptDate == null) receptDate = "";
List<Reception> receptionList = receptionService.queryReception(receptType, title, receptDate, currentPage);
/*计算总的页数和总的记录数*/
receptionService.queryTotalPageAndRecordNumber(receptType, title, receptDate);
/*获取到总的页码数目*/
int totalPage = receptionService.getTotalPage();
/*当前查询条件下总记录数*/
int recordNumber = receptionService.getRecordNumber();
request.setAttribute("receptionList", receptionList);
request.setAttribute("totalPage", totalPage);
request.setAttribute("recordNumber", recordNumber);
request.setAttribute("currentPage", currentPage);
request.setAttribute("receptType", receptType);
request.setAttribute("title", title);
request.setAttribute("receptDate", receptDate);
return "Reception/reception_frontquery_result";
}
/*前台查询Reception信息*/
@RequestMapping(value="/{receptionId}/frontshow",method=RequestMethod.GET)
public String frontshow(@PathVariable Integer receptionId,Model model,HttpServletRequest request) throws Exception {
/*根据主键receptionId获取Reception对象*/
Reception reception = receptionService.getReception(receptionId);
request.setAttribute("reception", reception);
return "Reception/reception_frontshow";
}
if (currentPage==null || currentPage == 0) currentPage = 1;
if (name == null) name = "";
if (addTime == null) addTime = "";
List<OldMan> 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<UserInfo> 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<UserInfo> 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();
} catch (Exception e) {
//e.printStackTrace();
message = "有记录存在外键约束,删除失败";
writeJsonResponse(response, success, message);
}
}
/*按照查询条件导出工资信息到Excel*/
@RequestMapping(value = { "/OutToExcel" }, method = {RequestMethod.GET,RequestMethod.POST})
public void OutToExcel(@ModelAttribute("employeeObj") Employee employeeObj,String giveDate, Model model, HttpServletRequest request,HttpServletResponse response) throws Exception {
if(giveDate == null) giveDate = "";
List<Salary> salaryList = salaryService.querySalary(employeeObj,giveDate);
ExportExcelUtil ex = new ExportExcelUtil();
String _title = "Salary信息记录";
String[] headers = { "工资id","员工","工资年份","工资月份","工资金额","发放日期"};
List<String[]> dataset = new ArrayList<String[]>();
for(int i=0;i<salaryList.size();i++) {
Salary salary = salaryList.get(i);
dataset.add(new String[]{salary.getSalaryId() + "",salary.getEmployeeObj().getName(),salary.getYear() + "",salary.getMonth() + "",salary.getSalaryMoney() + "",salary.getGiveDate()});
}
/*
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="+"Salary.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();
e.printStackTrace();
}
}
}
}
//OldMan管理控制层
@Controller
@RequestMapping("/OldMan")
public class OldManController extends BaseController {
/*业务层对象*/
@Resource OldManService oldManService;
@Resource UserInfoService userInfoService;
@InitBinder("userObj")
List<Employee> employeeList = employeeService.queryAllEmployee();
request.setAttribute("employeeList", employeeList);
return "Salary_add";
}
/*客户端ajax方式提交添加工资信息*/
@RequestMapping(value = "/add", method = RequestMethod.POST)
public void add(@Validated Salary salary, BindingResult br,
Model model, HttpServletRequest request,HttpServletResponse response) throws Exception {
String message = "";
boolean success = false;
if (br.hasErrors()) {
message = "输入信息不符合要求!";
writeJsonResponse(response, success, message);
return ;
}
salaryService.addSalary(salary);
message = "工资添加成功!";
success = true;
writeJsonResponse(response, success, message);
}
/*ajax方式按照查询条件分页查询工资信息*/
@RequestMapping(value = { "/list" }, method = {RequestMethod.GET,RequestMethod.POST})
public void list(@ModelAttribute("employeeObj") Employee employeeObj,String giveDate,Integer page,Integer rows, Model model, HttpServletRequest request,HttpServletResponse response) throws Exception {
if (page==null || page == 0) page = 1;
if (giveDate == null) giveDate = "";
if(rows != 0)salaryService.setRows(rows);
List<Salary> salaryList = salaryService.querySalary(employeeObj, giveDate, page);
/*计算总的页数和总的记录数*/
salaryService.queryTotalPageAndRecordNumber(employeeObj, giveDate);
/*获取到总的页码数目*/
int totalPage = salaryService.getTotalPage();
/*当前查询条件下总记录数*/
int recordNumber = salaryService.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(Salary salary:salaryList) {
JSONObject jsonSalary = salary.getJsonObject();
jsonArray.put(jsonSalary);
}
jsonObj.accumulate("rows", jsonArray);
out.println(jsonObj.toString());
out.flush();
out.close();
@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方式删除多条房间记录*/