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