SpringMVC其他说明(六)
2020-12-13 14:45
标签:问题 通过 nbsp ppi ice -- XML work lse 1. 编码问题 在web.xml中配置过滤器: 2. Controller的返回类型 (1) ModelAndView controller方法中定义ModelAndView对象并返回,对象中可添加model数据、指定view。 (2) Map 在jsp页面中可直通过${key1}获得到值, map.put()相当于request.setAttribute方法。 (3) View 可以返回pdf excel等。 (4) String (4.1) 逻辑视图名: (4.2) 直接将返回值输出到页面(添加@ResponseBody注解): (4.3) redirect重定向: (4.4) forward转发: (4.5) void: 如果返回值为空,则响应的视图页面对应为访问地址 对应的逻辑视图名为"index"。 SpringMVC其他说明(六) 标签:问题 通过 nbsp ppi ice -- XML work lse 原文地址:https://www.cnblogs.com/myitnews/p/11569149.html
filter>
filter-name>encodingFilterfilter-name>
filter-class>org.springframework.web.filter.CharacterEncodingFilterfilter-class>
init-param>
param-name>encodingparam-name>
param-value>UTF-8param-value>
init-param>
init-param>
param-name>forceEncodingparam-name>
param-value>trueparam-value>
init-param>
filter>
filter-mapping>
filter-name>encodingFilterfilter-name>
url-pattern>/*url-pattern>
filter-mapping>
@RequestMapping("/test")
public ModelAndView test(){
//通过ModelAndView构造方法可以指定返回的页面名称,也可以通过setViewName()方法跳转到指定的页面
ModelAndView mav=new ModelAndView("hello");
mav.addObject("time", new Date());
mav.getModel().put("name", "caoyc");
return mav;
}
@RequestMapping("/demo2/show")
public Map
@RequestMapping(value="/showdog")
public String hello1(){
return "hello";
}
@RequestMapping(value="/print")
@ResponseBody
public String print(){
String message = "Hello World, Spring MVC!";
return message;
}
@RequestMapping(value="/updateitem.action")
public String updateItem(Items item, Model model) {
ItemService.updateItem(item);
//修改item后跳转到列表页面
return "redirect:/item/itemlist.action";
}
@RequestMapping(value="/updateitem.action")
public String updateItem(Items item, Model model) {
ItemService.updateItem(item);
//修改item后跳转到列表页面
return "forward:/item/itemlist.action";
}
@RequestMapping("/index")
public void index() {
return;
}
上一篇:115 进程和线程的区别
下一篇:python基础之九九乘法表