zoukankan      html  css  js  c++  java
  • @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";
    	}
    

      

    - 未来可能遥远,但不轻易放弃 The future may be far away, but it is not easy to give up
  • 相关阅读:
    andorid自己定义ViewPager之——子ViewPager滑到边缘后直接滑动父ViewPager
    MTK Camera驱动移植
    云计算VDI相关职位招聘
    Android内存泄露之开篇
    关于ping以及TTL的分析
    STL之关联容器的映射底层
    STL非变易算法
    自己主动更新 -- 版本比較(2)
    activiti自己定义流程之Spring整合activiti-modeler5.16实例(四):部署流程定义
    合并多个文本文件方法
  • 原文地址:https://www.cnblogs.com/leehaitao/p/7411898.html
Copyright © 2011-2022 走看看