SSM整合中错误:Data truncation: Data too long for column 'gender' at row 1
错误描述
### SQL: insert into t_customer(name,gender,phone,address) values (?,?,?,?)
### Cause: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'gender' at row 1
错误原因
可能是页面提交表单如下:value值为字符男或女,web.xml中又没有设置编码过滤器,导致提交的中文男或女产生了乱码,长度大于了数据库字段gender(类型可能为char)的长度
客户性别:
<input type="radio" name="gender" value="男">男
<input type="radio" name="gender" value="女">女<br/>
解决办法
在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>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>