@Controller
@RequestMapping("/owners/{ownerId}")
public class TestController {
/* 默認方法 */
/*ModelMap
* org.springframework.ui.ModelMap 將請求對應的 屬性對象保存在request的屬性列表中,
*供jsp頁面通關過EL表達式${MapUrl}或者request.getAttribute("MapUrl")來訪問
*/
@RequestMapping
public String showPage(ModelMap model){
List<WarnMapJoin> list=alertMapService.getAlertMapList();
List<WarnSMessageJoin> listws=alertMapService.getWarnSMessageList();
model.addAttribute("County",list);
model.addAttribute("warnS",listws);
model.addAttribute("MapUrl",mapurlDao.url().getMapurl());
return "alertpub/alertMapList";
}
/*帶參數的方法*/
@RequestMapping(params="action=getHeadP")
public String getHeadP(String adcd,String warngradeid,String warnstatusid,ModelMap model){
model.addAttribute("headp",alertMapService.getHeadP(adcd, warngradeid, warnstatusid));
return "alertpub/alertMapHeadPForm";
}
/**
* 這個方法使用URL通配符的方式,遵守REST風格傳遞了多個參數
* @param ownerId
* @param petId
* @param model
*/
@RequestMapping("/pets/{petId}")
public void findPet(@PathVariable String ownerId,@PathVariable String petId,Model model){
//do something
}
/**
* 請求參數按照名稱匹配的方式綁定到方法參數中,方法返回的字符串代表邏輯視圖
* @param userName
* @param passworld
* @param realName
* @return
*/
@RequestMapping("/handle1")
public String handle1(@RequestParam("userName") String userName,
@RequestParam("passworld") String passworld,
@RequestParam("realName") String realName
){
return "success";
}
/**
* 取出cookie中的值和請求報頭中的值綁定到方法參數中
* @param sessionId
* @param accpetLanguage
* @return
*/
@RequestMapping("/handle2")
public ModelAndView handle2(
@CookieValue("JSESSIONID") String sessionId,
@RequestHeader("Accept-Language") String accpetLanguage
){
ModelAndView mav = new ModelAndView();
mav.setViewName("/success");
mav.addObject("user",new User());
return null;
}
/**
* 請求參數按照名稱匹配綁定到user的屬性中.
* @param user
* @return
*/
@RequestMapping("/handle3")
public String handle3(User user){
//do something
return "success";
}
/**
* 直接把request對象傳入到方法參數中,由此我們可以獲取請求中許多東西
* @param request
* @return
*/
@RequestMapping("/handle4")
public String handle4(HttpServletRequest request){
//do something
return "success";
}
}
