Controller的传参问题
Controller的映射
通過(guò)注解實(shí)現(xiàn)
@Controller
@RequestMapping(value = “/biz/assay/assay_order_audit_condition”)
請(qǐng)求的方法
也是通過(guò)注解實(shí)現(xiàn)
GET請(qǐng)求
@RequestMapping(value = {“create”},method = {RequestMethod.GET})
POST請(qǐng)求
@RequestMapping(value = {“create”},method = {RequestMethod.POST})
GET請(qǐng)求,或者POST請(qǐng)求
@RequestMapping(value = {“batch/delete”},method = {RequestMethod.GET, RequestMethod.POST})
Value,方法名稱
Method,請(qǐng)求的方式
參數(shù)的傳遞
直接寫類型,跟參數(shù)名
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,參數(shù)名字
Required,是否必須,默認(rèn)為true,表示請(qǐng)求中一定要有相應(yīng)的參數(shù)
defaultValue,默認(rèn)值,如果請(qǐng)求中沒有同名參數(shù)時(shí)的默認(rèn)值
此時(shí),fieldId這個(gè)參數(shù)必須傳遞,不傳遞就會(huì)報(bào)錯(cuò)
必須傳遞
@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模板變量值
用來(lái)獲得請(qǐng)求url中的動(dòng)態(tài)參數(shù)
用于將請(qǐng)求URL中的模板變量,映射到功能處理方法的參數(shù)上
需要配置url和方法的一個(gè)關(guān)系
@RequestMapping(value = {“{id}/delete”},method = {RequestMethod.GET})
總結(jié)
以上是生活随笔為你收集整理的Controller的传参问题的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Ajax的基本使用
- 下一篇: jQuery的noConflict()方