@PathVariable详解
生活随笔
收集整理的這篇文章主要介紹了
@PathVariable详解
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
@PathVariable
當使用@RequestMapping URI template 樣式映射時, 即 someUrl/{paramId}, 這時的paramId可通過 @Pathvariable注解綁定它傳過來的值到方法的參數上。
?
?
@Controller @RequestMapping("/owners/{ownerId}") public class RelativePathUriTemplateController { @RequestMapping("/pets/{petId}") public void findPet(@PathVariable String ownerId,@PathVariable String petId, Model model) { // implementation omitted } }@Controller @RequestMapping("/owners/{ownerId}") public class RelativePathUriTemplateController { @RequestMapping("/pets/{petId}") public void findPet(@PathVariable String ownerId, @PathVariable String petId, Model model) { // implementation omitted } }
上面代碼把URI template 中變量 ownerId的值和petId的值,綁定到方法的參數上。若方法參數名稱和需要綁定的uri template中變量名稱不一致,需要在@PathVariable("name")指定uri template中的名稱。如果一樣,則可以省略。
@RequestMapping(value = "/forwardEdit/{id}.do")public String forwardEdit(HttpServletRequest request, @PathVariable("id") int id, String pf) throws Exception {// 采購方編碼TJzny_plan fmodel = jzny_planService.find(id);AjaxMsg message = fmodel == null ? new AjaxMsg(false, "修改的計劃單不存在!") : new AjaxMsg(true, "");LogonInfo userInfo = this.getUserInfo(request);TDepartment department = departmentService.find(Integer.parseInt(fmodel.getBusinessDep()));String businessDepId_value = "";if (department != null) {businessDepId_value = department.getDeptName();}request.setAttribute("businessDepId_value", businessDepId_value);request.setAttribute("userInfo", userInfo);request.setAttribute("fmodel", fmodel);// 將結果返回給前臺,前臺可以通過EL表達式來獲取數據request.setAttribute("AjaxMsg", message);request.setAttribute("pf", pf);request.setAttribute("url", "planmanage/forwardGrid.do");request.setAttribute("purchaseTypes", StringUtils.isNotBlank(userInfo.getUserInfo().getDvSpecifyPurchaseTypes()) ? userInfo.getUserInfo().getDvSpecifyPurchaseTypes() : "0");// 判斷是否需要判斷物資編碼String ishasWzCode = "否";List<TDictionarydata> dictionarydatas = DictorySearchService.find("WzCodeControl", userInfo.getPurchaserNo());if (dictionarydatas != null && dictionarydatas.size() > 0) {ishasWzCode = dictionarydatas.get(0) != null ? dictionarydatas.get(0).getDicValue() : "否";}request.setAttribute("ishasWzCode", ishasWzCode);return "jh/bid_planmanage/edit";}
轉載于:https://www.cnblogs.com/leehaitao/p/7411898.html
總結
以上是生活随笔為你收集整理的@PathVariable详解的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 乌鲁木齐保利堂悦楼盘地址在哪里?
- 下一篇: 欧普灯M+52寸家用北欧北欧吊扇灯风扇灯