写一些spring mvc controller控制层的一些格式
/**
*
*
* @RequestMapping(这里)
* 格式:xxx = xxx or xxx.xxx
* value 绝对路径Controller名(类似Action名)
* method 提交方式,调用RequestMethod
* consumes 指定处理请求的提交内容类型(Content-Type),例如application/json, text/html;
* headers 指定返回的内容类型,仅当request请求头中的(Accept)类型中包含该指定类型才返回;
* params 指定request中必须包含某些参数值是,才让该方法处理。
* produces 指定request中必须包含某些指定的header值,才能让该方法处理请求。
*
*
* spring mvc处理方法支持如下的返回方式:ModelAndView, Model, ModelMap, Map,View, String, void
*
*
* testController(这里),如下
* 格式:@xxx 类型 命名
* A、处理requet uri 部分(这里指uri template中variable,不含queryString部分)的注解: @PathVariable;
* B、处理request header部分的注解: @RequestHeader, @CookieValue;
* C、处理request body部分的注解: @RequestParam, @RequestBody;
* D、处理attribute类型是注解: @SessionAttributes, @ModelAttribute;
*
*/
@Resource(name="aclUserService") private AclUserService aclUserService;
@RequestMapping(value = "/testController", method = RequestMethod.POST)
public ModelAndView testController() {
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("viewName");
modelAndView.addObject("需要放到model中的属性名称", "对应的属性值,它是一个对象");
return modelAndView;
}
@RequestMapping(value = "/testControllerByRequestParam", method = RequestMethod.POST)
public ModelAndView testController(@RequestParam String name) {
system.out.println(name);//接受前台参数
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("viewName");
modelAndView.addObject("需要放到model中的属性名称", "对应的属性值,它是一个对象");
return modelAndView;
}