標籤:問題 span track mic font pop port div spring註解
@RequestMapping請求路徑映射,假設標註在某個controller的類層級上,則表明訪問此類路徑下的方法都要加上其配置的路徑。最經常使用是標註在方法上。表明哪個詳細的方法來接受處理某次請求。
下面兩種方式都能夠從url中傳參數,可是另外一種方式的適用性更高一些,當參數中包括中文的時候,假設用第一種方式傳參數,常常會出現參數還沒到controller就已經經過編碼了(比如:經過utf-8編碼後,原本要傳的參數就會以%+ab...cd這種方式出現),然後controller接受到這種請求後,根本無法解析該請求應該走那個業務方法。然後就會出現常見的404問題。
。。
package com.test.jeofey.web;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.PathVariable;import org.springframework.web.bind.annotation.RequestMapping;@Controller@RequestMapping("/path")public class TestController {// 第一種傳參數的方式 訪問地址比如:http:網域名稱/path/method1/keyWord.html@RequestMapping("method1/{keyWord}")public String getZhiShiDetailData(@PathVariable("keyWord") String keyWord,HttpServletRequest request, HttpServletResponse response){System.out.println(keyWord);return "v1/detail";}// 另外一種傳參數的方式 訪問地址比如:http:網域名稱/path/method2.html?key=keyWord@RequestMapping("method2")public String getCommonData(HttpServletRequest request, HttpServletResponse response){String keyWord= request.getParameter("key");System.out.println(keyWord);return "v1/common";}}
Spring註解@RequestMapping請求路徑映射問題