1.代码中经常会出现一个实体类中含有很多set方法进行赋值,比如一个实体类中包含20个参数就可能会有个20行的参数
2.一般人会将这么多的set方法放在所在类中令为一个私有的方法
我的方法比较简单而且比较实用
首先这边将你觉得比较常用的几个字段令为实体类,同时进行new 所需的对象(注:当这样构造器的时候,必须常见初始的构造器,不然new 构造器的时候会报错)
public Comment(Long userId, Long shopId, Long goodsId, Long productId, String orderNo){
this.userId = userId;
this.shopId==shopIdl
this.goodsId=goodsId;
this.productId=productId;
this.orderNo=orderNo;
}
public static Comment create(Long userId, Long shopId, Long goodsId, Long productId, String orderNo){
return new Comment(userId,shopId,goodsId,productId,orderNo);
}