HelloWorldController.java 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package com.uas.eis.controller;
  2. import java.util.Map;
  3. import javax.servlet.http.HttpServletRequest;
  4. import javax.servlet.http.HttpServletResponse;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.ui.ModelMap;
  7. import org.springframework.web.bind.annotation.RequestMapping;
  8. import org.springframework.web.bind.annotation.RestController;
  9. import com.uas.eis.service.UserService;
  10. import com.uas.eis.utils.HttpUtil;
  11. import com.uas.eis.utils.HttpUtil.Response;
  12. @RestController
  13. public class HelloWorldController {
  14. @Autowired
  15. private UserService userService;
  16. @RequestMapping(value = "/hello", produces = "application/json;charset=utf-8")
  17. public String hello(){
  18. return "Hello,World!";
  19. }
  20. @RequestMapping("/getUser")
  21. public Map<String, Object> getUser(String username){
  22. return userService.getUser(username);
  23. }
  24. /**
  25. * 首次登陆请求token
  26. */
  27. @RequestMapping("/login")
  28. public String login(String username, String password){
  29. return "<pre style=\"width:50%;font-family: mic;white-space: pre-wrap;word-wrap: break-word;\">"+userService.login(username, password)+"</pre>";
  30. }
  31. /**
  32. * token 测试
  33. */
  34. @RequestMapping(value = "/test", produces = "application/json;charset=utf-8")
  35. public String test(String username){
  36. return "中文";
  37. }
  38. /**
  39. * http请求测试
  40. * @return
  41. */
  42. @RequestMapping(value = "/baidu", produces = "text/html;charset=utf-8")
  43. public String testHttpRequest() {
  44. try {
  45. return HttpUtil.sendGetRequest("https://www.baidu.com/", null).getResponseText();
  46. } catch (Exception e) {
  47. e.printStackTrace();
  48. }
  49. return null;
  50. }
  51. }