1.get
@RequestMapping(value = "/user",method = RequestMethod.GET) public String user(){ System.out.println("查询所有用户信息"); return "success"; } @RequestMapping(value = "/user/{id}",method = RequestMethod.GET) public String getUserById(){ System.out.println("查询单个用户信息"); return "success"; }
<a th:href="@{/user}" >查询所有用户</a> <a th:href="@{/user/1}">查询单个用户</a>
2 post
@RequestMapping(value = "/user",method = RequestMethod.POST) public String addUser(){ System.out.println("添加单个用户信息"); return "success"; }
<form th:action="@{/user}" method="post"> 用户名:<input type="text" name="username"> 年龄:<input type="text" name="age"> <input type="submit" value="添加单个用户"> </form>
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/288198.html