HttpServletRequest
SpringMVCHandler.java
/**
* REST PUT
*/
@RequestMapping(value="/order",method=RequestMethod.PUT)
public String testRestPUT() {
System.out.println("REST PUT");
return "success";
}
/**
* REST POST
*/
@RequestMapping(value="/order",method=RequestMethod.POST)
public String testRestPOST() {
System.out.println("REST POST");
return "success";
}
/**
* REST DELETE
*/
@RequestMapping(value="/order/{id}",method=RequestMethod.DELETE)
public String testRestDELETE(@PathVariable("id")Integer id ) {
System.out.println("REST DELETE: " + id );
return "success";
}
/**
* REST GET
*/
@RequestMapping(value="/order/{id}",method=RequestMethod.GET)
public String testRestGET(@PathVariable("id")Integer id ) {
System.out.println("REST GET: " + id );
return "success";
}
index.jsp
<!-- 修改一個訂單 -->
<form action="order" method="post">
<input type="hidden" name="_method" value="PUT"/>
<input type="submit" value="REST PUT"/>
</form>
<br/>
<!-- 添加一個新的訂單 -->
<form action="order" method="post">
<input type="submit" value="REST POST"/>
</form>
<br/>
<!-- 刪除id爲1001的訂單 -->
<form action="order/1001" method="post">
<!-- 隱藏域,不會被用戶看到 -->
<input type="hidden" name="_method" value="DELETE"/>
<input type="submit" value="REST DELETE"/>
</form>
<br/>
<!-- 查詢id爲1001的訂單 -->
<a href="order/1001">REST GET</a>
<br/>
<a href="testMapAndHead?username=tom&age=13">Maping&&Head</a>
<a href="RequestMapping">MethodTest</a>
<br>
結果
小朋友,你是否有很多問號??心態被這玩意兒整崩潰了,然後又被我同學告知,這個用的不是很多,OHHHHH,Shit
詳情見https://llngu.blog.csdn.net/article/details/105158202