@RequestMapping(value = "/user",method = RequestMethod.GET)
public String getAllUser()
{
System.out.println("获取全部用户信息");
return "target";
}
@RequestMapping(value = "/user/{id}",method = RequestMethod.GET)
public String getUserById()
{
System.out.println("根据ID获取用户信息");
return "target";
}
@RequestMapping(value = "/user",method = RequestMethod.POST)
public String addUser(String username,String password)
{
System.out.println(username+","+password);
return "target";
}
@RequestMapping(value = "/user",method = RequestMethod.PUT)
public String updateUser(String username,String password)
{
System.out.println("修改信息");
return "target";
}
<form th:action="@{/user}" method="post">
<input type="hidden" name="_method" value="PUT">
用户名<input name="username" type="text"><br>
密码<input type="password" name="password"> <br>
<input type="submit" value="修改">
</form>
注意添加这个后 </input type=“hidden” name=“_method” value=“PUT”>,这样请求方法才变成PUT
@RequestMapping(value = "/user/{id}",method = RequestMethod.DELETE)
public String deleteUser()
{
System.out.println("删除信息");
return "target";
}
<form th:action="@{/user/1}" method="post">
<input type="hidden" name="_method" value="DELETE">
用户名<input name="username" type="text"><br>
密码<input type="password" name="password"> <br>
<input type="submit" value="删除">
</form>
注意 </input type=“hidden” name=“_method” value=“DELETE”>,这样请求方法才变成DELETE