1. 在用springmvc 添加到 数据库中时,中文乱码,解决办法为 在web.xml文件中,添加如下(可以试着添加到web.xml的最上面)
<filter> <filter-name>CharacterEncodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>utf-8</param-value> </init-param> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>CharacterEncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
然后在数据库中,建立表时,用utf8编码存储。
2. form标签,在用springmvc时,必须用springmvc提供的标签才能完成封装bean,使用springmvc的标签后,仍然可以使用bootstrap的class样式
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
3.再用bootstrap时,button添加href跳转,直接用a标签,包围button即可。
<a href="${pageContext.request.contextPath }/addRolePage"><button type="button" class="btn btn-primary" style="margin-bottom: 8px; float: right" >新增</button></a>
4.用redirect跳转后,有时不更新页面,但用forward跳转,可以更新。后来测试,用redirect;/getRoles也可以更新。
@RequestMapping("/addRole") public String addRole(Role role) { roleService.addRole(role); // return "forward:/getRoles";
return "redirect:/getRoles"; }
添加业务时,字符集乱码,form标签库,button的href 问题,添加后页面不更新
原文:https://www.cnblogs.com/sdgtxuyong/p/12022585.html