Ease Your Effort of Putting Data into History Table
1. Ease Your Effort of Putting
Data into History Table
ALBERT KUO
ALBERT_KUO@CHT.COM.TW
2. Scenario
2
違章事實代碼檔維護
違章事實代碼資料
NIG015W NIG015W
違章事實代 新增/刪除/修
碼檔維護 改/查詢/列印
As user maintains violation fact code,
system should keep its modification history.
NIG015P 1.違章事實代碼檔[NIGT038]
違章事實代碼 2.違章事實代碼異動記錄檔[NIGU038]
對照表
4. TO-BE
4
Spring Nig005Controller Nig005Service
1 request
Dispatcher
Servlet 2 Nig010Controller Nig010Service
3
Nig015Controller Nig015Service
6
7 Nig020Controller Nig020Service
response
View
NigXXXController NigxxxService
Apache Tiles
4
Nigt038Dao Nigu038Dao Nigt039Dao Nigu039Dao
5
NigtxxxDao NiguxxxDao
1. Service class can simply focus on business logic and more clean.
2. Service class does not need to care about if it should write data into history table or not.
5. How to do it?
5
1. Open Nigt038DaoImpl
2. Autowired Nigu038Dao
3. Overwrite create method
4. Overwrite delete method
5. Overwrite update method
6. Overwrite create method
6
Copy entity
attributes to
Nigu038
Set PK values
to Nigu038PK
Set
Nigu038PK to
Nigu038’s id
attribute
Create data to
Nigu038 via
Nigu038Dao
Create data to
Nigt038
7. Overwrite delete method
7
Retrieve
existing data
Copy values to
Nigu038
Set PK values
to Nigu038PK
Set
Nigu038PK to
Nigu038’s id
attribute
Create data to
Nigu038 via
Nigu038Dao
Create data to
Nigt038
8. Overwrite update method
8
Retrieve
existing data
Copy values to
Nigu038
Set PK values
to Nigu038PK
Set
Nigu038PK to
Nigu038’s id
attribute
Create data to
Nigu038 via
Nigu038Dao
Create data to
Nigt038