@RequestMapping(value = "/addgoods.jspx", method = RequestMethod.POST)
public String stockin(GoodsInfo goods) {
boolean flag = miShopService.addgoods(goods);
return null;
}
将页面数据封装到GoodsInfo实体,然后插入数据库
INSERT INTO mishop.goods (NAME,CODE) VALUES (?,?)
报错:
HTTP Status 500 - Request processing failed; nested exception is org.springframework.dao.DataIntegrityViolationException: PreparedStatementCallback; SQL [INSERT INTO mishop.goods (NAME,CODE) VALUES (?,?)]; Data truncation: Data too long for column 'code' at row 1; nested exception is com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'code' at row 1
数据库code字段的为varchar(100),页面接收的是数据是"0001",明显没有超长。GoodsInfo实体中code的类型也是String
页面编码格式为:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
数据库和数据库表的编码格式都是UTF-8 utf8_general_ci,引擎为InnoDB.
没碰到过这种问题,提供下我的思路参考吧
1、System.out.println(goods.getCode())看看接参到底有没有问题
2、拿sql去数据库里执行看看有没有问题
3、再看看编码问题,是不是都统一编码了
4、以上都不行再来求助
我getCode()的时候,选择提示的方法,选错了,弄成getClass()了