我在设置前端传来的数值时,更新商品资料,其它字段串都可以为空,能进入数据库,但是,就是一个价格,不行。
我是用的String 接收的,在下面用了Integer转换。不知道是怎么回事,为空,就报了异常呢
//接收的
String price = request.getParameter("price").trim(); //价格
//设置的,但是,里面先整数化了一下 就这里报错了
goods.setPrice(Integer.parseInt(price));
后来我用了下这个
if (price != null && !price.equals("")) {
goods.setPrice(Integer.parseInt(price));
}
但是不知道会有什么问题不。就是,好像空字符串,不能用做 .equals吧?。。