• @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
  • 相关阅读:
    Codeforces E-Anton and Tree
    树的重心和直径-POJ1655
    Cisco packet tracer 实现两台计算机互ping
    codeforce 679A Bear and Prime 100 (交互题)
    codejam 2019 round 1C Robot Programming Strategy (构造)
    luogu P1086 花生采摘 (优先队列+模拟)
    ZOJ 4110 Strings in the Pocket (马拉车+回文串)
    HDOJ 6508 Problem I. Spell Boost (01背包/DP)
    L2-011 玩转二叉树 (25 分) (树)
    L2-004 这是二叉搜索树吗? (25 分) (树)
  • 原文地址:https://www.cnblogs.com/leehaitao/p/7411898.html
Copyright © 2020-2023  润新知