@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";
	}

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM