ACTION: action的部分,已先做了一個抽象類別 ex:如下
public abstract class BaseAction<VO> extends ActionSupport implements ServletRequestAware, SessionAware, ServletContextAware,ServletResponseAware {
內容就當然是定義一些共用資料及共用方法,值得一提的是VO的部分要自訂:
//自訂VO
protected VO vo;
/**
* @return the vo
*/
public VO getVo() {
return vo;
}
/**
* @param vo the vo to set
*/
public abstract void setVo(VO vo);
VO(value object): 也算一種model 用來接前端所組好的Json資料、剛開始做我會把他和entity搞混
總之vo層用來接前端傳至action的值,然後再把值塞進entity內做新、刪、修
BO(business object): BO層就專門處理資料的新、刪、修、查詢,也就是資料庫的connetion
由於實做這層就會掛一層interface而interface裡的function會定義上@Transactional(readOnly = true/false)
這用意代表transactional只在這bo內做連線,出了bo就commit了,所以這邊也還有個好處就是不用再寫rollback機制,一出錯就幫你rollback非常好用
DAO(data access object):DAO層則是純粹負責資料庫端與程式端的溝通ex: dao.insert 、dao.update 、dao.select 、dao.delete等
ENTITY: 也就是在Hibernate來說必要的一種物件model ex:如下
@Entity
@Table(name = "XXXXX_XXX_XXXX_PRODUCT")
public class XXXXXXXXXXXXProduct implements java.io.Serializable {
private int XXXXXXXXXXXId;
private XXXXXlate XXXXXXlate;
private String productName;
private String productSize;
private Integer productPrice;
private Integer productXXXXXXXX1;
private Integer prodcutXXXXXXXXX2;
private Integer prodcutXXXXXXXXX3;
private Integer prodcutXXXXXXXXX4;
private String status;
private Integer createdUser;
private Integer createdDate;
private Integer createdTime;
private Integer updatedUser;
private Integer updatedDate;
private Integer updatedTime;
private Set<SaleAAAA> saleBBBB = new HashSet<SaleAAAA>(0);
public XXXXXXXXXXXXProduct() {
}
public XXXXXXXXXXXXProduct(int XXXXXXXXXXXId, XXXXXXlate XXXXXXlate) {
this.XXXXXXXXXXXId= XXXXXXXXXXXId;
this.XXXXXXlate= XXXXXXlate;
}
public XXXXXXXXXXXXProduct(int XXXXXXXXXXXId,
XXXXXXlate XXXXXXlate, String productName, String productSize,
Integer productPrice, Integer productXXXXXXXX1,
Integer productXXXXXXXX2, Integer productXXXXXXXX3,
String status, Integer createdUser, Integer createdDate,
Integer createdTime, Integer updatedUser, Integer updatedDate,
Integer updatedTime) {
this.orderFormTemplateProductId = orderFormTemplateProductId;
this.orderFormTemplate = orderFormTemplate;
this.productName = productName;
this.productSize = productSize;
this.productPrice = productPrice;
this.productXXXXXXXX1= productXXXXXXXX1;
this.productXXXXXXXX2= productXXXXXXXX2;
this.productXXXXXXXX3= productXXXXXXXX3;
this.status = status;
this.createdUser = createdUser;
this.createdDate = createdDate;
this.createdTime = createdTime;
this.updatedUser = updatedUser;
this.updatedDate = updatedDate;
this.updatedTime = updatedTime;
}
@Id
@Column(name = "XXXXX_XXX_XXXX_PRODUCT_ID", unique = true, nullable = false)
@GeneratedValue(strategy=GenerationType.IDENTITY)
public int getXXXXXXXXXXXId() {
return this.XXXXXXXXXXXId;
}
public void setXXXXXXXXXXXId(int XXXXXXXXXXXId) {
this.XXXXXXXXXXXId= XXXXXXXXXXXId;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "XXXXX_XXXX_XXXXX_ID", nullable = false)
public XXXXXXlate getXXXXXXlate() {
return XXXXXXlate;
}