Exercise 02: Column Mappings - jkneal/spring-angular-train GitHub Wiki
Goals
Try using Project Lombok to remove some of the boilerplate code we had to add in the previous exercise and see how to use the @Column annotation to customize the way data is stored in different columns in the database.
Instructions
-
In
Store,Product, andOrder, add the@Dataannotation. This will allow you to take off any previous getters and setters you have added. -
Add the following class fields with the specified column mapping.
| Class | Field | Type | Column Name | Nullable? |
|---|---|---|---|---|
| edu.train.product.Product | name | String | NAME | false |
| edu.train.product.Product | quantity | int | QTY | false |
| edu.train.store.Store | website | String | WEBSITE | true |
| edu.train.store.Order | total | BigDecimal (scale=2, precision=19) | TOTAL | true |
| edu.train.store.Order | createDate | java.util.Date (temporal=Timestamp) | CREATE_DT | false |
-
In
Order, add a field namedquantityof typeint. This field should not be persisted. -
In
Order, add a field namedversionof typeint. Indicate this field should be used for optimistic locking. -
In
Store, create an Enum namedStoreStatuswith valuesOPENandCLOSED. Now create a field namedopenwith typeStoreStatus. Specify that the Enum String value should be persisted.
VERIFICATION
-
Start the training application and go to the app home page
-
Click on the link 'Exercise Two Get Product'. Verify the resulting JSON contains:
"name" : "Basketball", "quantity" : 5,
-
Click on the link 'Exercise Two Get Order'. Verify the resulting JSON contains:
"total" : 19.99, "createDate" : "2012-09-17T22:47:52.690+0000", "quantity" : 0, "version" : 1,
-
Click on the link 'Exercise Two Get Store'. Verify the resulting JSON contains:
"name":"Joe's Sports Store","owner":"Joe","website":"joesports.com","open":"OPEN"