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

  1. In Store, Product, and Order, add the @Data annotation. This will allow you to take off any previous getters and setters you have added.

  2. 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
  1. In Order, add a field named quantity of type int. This field should not be persisted.

  2. In Order, add a field named version of type int. Indicate this field should be used for optimistic locking.

  3. In Store, create an Enum named StoreStatus with values OPEN and CLOSED. Now create a field named open with type StoreStatus. Specify that the Enum String value should be persisted.

VERIFICATION

  1. Start the training application and go to the app home page

  2. Click on the link 'Exercise Two Get Product'. Verify the resulting JSON contains:

    "name" : "Basketball", "quantity" : 5,

  3. 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,

  4. 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"