在web.xml
中加以下代碼:java
<!-- 將post請求轉爲put或delete請求 --> <filter> <filter-name>HiddenHttpMethodFilter</filter-name> <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class> </filter> <filter-mapping> <filter-name>HiddenHttpMethodFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter> <filter-name>HttpPutFormContentFilter</filter-name> <filter-class>org.springframework.web.filter.HttpPutFormContentFilter</filter-class> </filter> <filter-mapping> <filter-name>HttpPutFormContentFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
<!-- 將post請求轉爲put或delete請求 --> <filter> <filter-name>FormContentFilter</filter-name> <filter-class>org.springframework.web.filter.FormContentFilter</filter-class> </filter> <filter-mapping> <filter-name>FormContentFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
功能 | 請求路徑 | 請求方法 |
---|---|---|
列表顯示 | /emps | GET |
添加頁面 | /emp | GET |
添加操做 | /emp | POST |
修改頁面 | /emp/{id} | GET |
修改操做 | /emp/{id} | PUT |
刪除操做 | /emp/{ids} | DELETE |
校驗姓名 | /checkName | GET |
在org.yun.ssm.model
包下,建立Msg.java。 目的:封裝 json 返回的參數。 代碼:web
public class Msg { //狀態碼。100:成功;200:失敗 private int code; //返回的消息 private String msg; //Map封裝返回頁面的數據 private Map<String, Object> data = new HashMap<>(); public static Msg success() { Msg result = new Msg(); result.setCode(100); result.setMsg("處理成功"); return result; } public static Msg fail() { Msg result = new Msg(); result.setCode(200); result.setMsg("處理失敗"); return result; } public Msg add(String key, Object value) { this.data.put(key, value); return this; } // getter and setter }