Controller的传参问题
Controller的映射
通過注解實現
@Controller
@RequestMapping(value = “/biz/assay/assay_order_audit_condition”)
請求的方法
也是通過注解實現
GET請求
@RequestMapping(value = {“create”},method = {RequestMethod.GET})
POST請求
@RequestMapping(value = {“create”},method = {RequestMethod.POST})
GET請求,或者POST請求
@RequestMapping(value = {“batch/delete”},method = {RequestMethod.GET, RequestMethod.POST})
Value,方法名稱
Method,請求的方式
參數的傳遞
直接寫類型,跟參數名
public String view(String Id) { }Request.getParameter方法
public String view() {request.getParameter("id"); }@RequestParam注解
public String updateRecordStatusBatch(@RequestParam(value = "ids", required = false) String[] ids) { }Value,參數名字
Required,是否必須,默認為true,表示請求中一定要有相應的參數
defaultValue,默認值,如果請求中沒有同名參數時的默認值
此時,fieldId這個參數必須傳遞,不傳遞就會報錯
必須傳遞
@RequestParam(value = “id”, required = true) String id
可以不用傳遞
@RequestParam(value = “id”, required = false) String id
@PathVariable注解
@RequestMapping(value = {"{id}/delete"},method = {RequestMethod.GET}) public String showDeleteForm(@PathVariable("id") String Id, Model model) { }綁定URI模板變量值
用來獲得請求url中的動態參數
用于將請求URL中的模板變量,映射到功能處理方法的參數上
需要配置url和方法的一個關系
@RequestMapping(value = {“{id}/delete”},method = {RequestMethod.GET})
總結
以上是生活随笔為你收集整理的Controller的传参问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Ajax的基本使用
- 下一篇: jQuery的noConflict()方