要在后端给实体类设置默认值,有两种行之有效且快速的方法:1
private String orderPrice=“0”;//定义类的属性时进行赋值
2.在get/set方法中进行判断并赋值
private String orderPrice;//定义类的属性
/*
* get set方法
* String.trim() 返回字符串的副本,忽略前导空白和尾部空白。
*/
public String getOrderPrice() {
if("".equals(orderPrice)||orderPrice==null){
return "0";//去除该属性的前后空格并进行非空非null判断
}
return orderPrice;
}
public void setOrderPrice(String orderPrice) {
this.orderPrice = orderPrice == null ? null : orderPrice.trim();
}