标签:请求 springmvc attribute host 提交 chain err 实现 web
提交的域名称和处理方法的参数名一致
提交的域名称和处理方法的参数名不一致
@GetMapping("/t1")
public String test1(@RequestParam("name1") String name, Model model) {
//1.接收前端参数
System.out.println("接收到前端的参数为:" + name);
//2.将返回代结果传递给前端
model.addAttribute("msg",name);
//3.跳转视图
return "test";
}
提交的是一个对象
@GetMapping("/t2")
public String test2(User user) {
System.out.println(user);
return "test";
}
http://localhost:8080/springmvc_03_servlet_war_exploded/user/t2?id=1&name=q&age=1
Model、ModelMap、ModeAndView的区别
public class EncodingFilter implements Filter {
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
servletRequest.setCharacterEncoding("utf-8");
servletResponse.setCharacterEncoding("utf-8");
filterChain.doFilter(servletRequest,servletResponse);
}
@Override
public void destroy() {
}
}
<filter>
<filter-name>encoding</filter-name>
<filter-class>cn.imut.filter.EncodingFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>encoding</filter-name>
<!-- 过滤所有的请求-->
<url-pattern>/*</url-pattern>
</filter-mapping>
@Controller
public class EncodingController {
//过滤器解决乱码
@PostMapping("/e/t1")
public String test1(String name, Model model) {
model.addAttribute("msg",name);
return "test";
}
}
<!-- springMVC自带过滤器-->
<filter>
<filter-name>encoding</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>eccoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
标签:请求 springmvc attribute host 提交 chain err 实现 web
原文地址:https://www.cnblogs.com/yfyyy/p/12433557.html