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
  • 相关阅读:
    .net framework v4.5.2
    sql数据库不允许保存更改和保存失败解决方法
    如何查看笔记本电脑型号
    Premiere 5.0/5 .5菜单详解
    Python编辑器英文菜单的中文翻译及解释
    SqlServer--常用数据查询
    pycharm上方菜单栏不见了如何恢复
    笔记本电脑的f1到f12怎么按
    C#的访问权限
    封装,继承和多态知识点汇总
  • 原文地址:https://www.cnblogs.com/leehaitao/p/7411898.html
Copyright © 2011-2022 走看看