0a3cea53896229977bef1f1eb916a45d9fcfe682.svn-base 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. package com.synyi.edc.controller;
  2. import java.io.IOException;
  3. import java.io.PrintWriter;
  4. import java.util.ArrayList;
  5. import java.util.HashMap;
  6. import java.util.List;
  7. import java.util.Map;
  8. import javax.annotation.Resource;
  9. import javax.servlet.http.HttpServletRequest;
  10. import javax.servlet.http.HttpServletResponse;
  11. import org.springframework.stereotype.Controller;
  12. import org.springframework.ui.Model;
  13. import org.springframework.util.StringUtils;
  14. import org.springframework.web.bind.annotation.RequestMapping;
  15. import com.alibaba.fastjson.JSONObject;
  16. import com.synyi.edc.pojo.Parameter;
  17. import com.synyi.edc.pojo.User;
  18. import com.synyi.edc.service.IUserService;
  19. import com.synyi.edc.util.XmlUtils;
  20. @Controller
  21. @RequestMapping("/user")
  22. public class UserController {
  23. @Resource
  24. private IUserService userService;
  25. @RequestMapping("/showUser")
  26. public String toIndex(HttpServletRequest request,Model model){
  27. int userId = Integer.parseInt(request.getParameter("id"));
  28. User user = this.userService.getUserById(userId);
  29. model.addAttribute("user", user);
  30. System.out.println(XmlUtils.getMapString("orgCode.oneOrg"));
  31. return "showUser";
  32. }
  33. @RequestMapping("/toIndex")
  34. public String toJ(HttpServletRequest request,Model model){
  35. int userId = Integer.parseInt(request.getParameter("id"));
  36. User user = this.userService.getUserById(userId);
  37. model.addAttribute("user", user);
  38. return "index";
  39. }
  40. @RequestMapping("/getAllOrg")
  41. public String getAllOrg(HttpServletRequest request,Model model,HttpServletResponse res){
  42. Map map1 = new HashMap();
  43. map1.put("id", "488099744");
  44. map1.put("name", "福州一院");
  45. Map map2 = new HashMap();
  46. map2.put("id", "48809974x");
  47. map2.put("name", "福州儿院");
  48. Map map3 = new HashMap();
  49. map3.put("id", "488099743");
  50. map3.put("name", "福州中医院");
  51. Map map4 = new HashMap();
  52. map4.put("id", "488099757");
  53. map4.put("name", "福州传染病医院");
  54. List list = new ArrayList();
  55. list.add(map1);
  56. list.add(map2);
  57. list.add(map3);
  58. list.add(map4);
  59. String jsonString = JSONObject.toJSON(list).toString();
  60. res.setContentType("text/plain");
  61. res.setCharacterEncoding("utf-8");
  62. System.out.println(res);
  63. PrintWriter pw = null;
  64. try {
  65. pw = res.getWriter();
  66. pw.write(jsonString);
  67. } catch (IOException e) {
  68. e.printStackTrace();
  69. }finally{
  70. pw.flush();
  71. pw.close();
  72. }
  73. return null;
  74. }
  75. public void printJson(HttpServletResponse res,List list){
  76. String jsonString = JSONObject.toJSON(list).toString();
  77. res.setContentType("text/plain");
  78. res.setCharacterEncoding("utf-8");
  79. System.out.println(res);
  80. PrintWriter pw = null;
  81. try {
  82. pw = res.getWriter();
  83. pw.write(jsonString);
  84. } catch (IOException e) {
  85. e.printStackTrace();
  86. }finally{
  87. pw.flush();
  88. pw.close();
  89. }
  90. }
  91. }