HelloController.java

    1. @RestController
    2. @RequestMapping(value = "/hello", method = {
    3. // RequestMethod.POST,
    4. // RequestMethod.GET
    5. })
    6. public class HelloController {
    7. /**
    8. * http://127.0.0.1/hello
    9. */
    10. @RequestMapping
    11. public String hello() {
    12. return "hello, springboot";
    13. }
    14. /**
    15. * http://127.0.0.1/hello/index
    16. */
    17. @RequestMapping(value = "/index", method = {
    18. RequestMethod.POST,
    19. RequestMethod.GET
    20. })
    21. public String index() {
    22. return "index";
    23. }
    24. /**
    25. * http://127.0.0.1/hello/test
    26. * http://127.0.0.1/hello/test1
    27. * http://127.0.0.1/hello/test2
    28. * http://127.0.0.1/hello/test3
    29. */
    30. @RequestMapping(value = {
    31. "/test",
    32. "/test1",
    33. "/test2",
    34. "/test3",
    35. })
    36. public String test() {
    37. return "多URL映射测试";
    38. }
    39. /**
    40. * http://127.0.0.1/hello/get
    41. */
    42. @RequestMapping(value = "/get", method = RequestMethod.GET)
    43. public String get() {
    44. return "只允许 get";
    45. }
    46. /**
    47. * http://127.0.0.1/hello/post
    48. */
    49. @RequestMapping(value = "/post", method = RequestMethod.POST)
    50. public String post() {
    51. return "只允许 post";
    52. }
    53. }