springMVC restFul实现
作者:互联网
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>
标签:String,RequestMethod,springMVC,System,实现,user,restFul,public,out 来源: https://www.cnblogs.com/cciscc/p/16667781.html