Spring Boot Bootcamp – Workbooks and Challenges

Workbook 2.11

Screen Shot 2022-08-15 at 11.21.51 PM.png

Task 1

Create a POJO class for Record objects. The class will have three fields:

private String item; private double revenue; private double cost;

Add the usual constructor, getters, and setters.

Task 2

Before returning the view, add the following objects to the model:

List<Record> records = Arrays.asList( new Record("Chair", 20.99, 5.99), new Record("Table", 40.99, 8.99), new Record("Couch", 100.99, 105.99), new Record("Fridge", 200.99, 59.99), new Record("Bed", 150.99, 205.99) );

Task 3

Under the header in records.html, create a table similar to the following:


Task 4

Using a Thymeleaf loop, your table must generate as many rows as there are objects in the records list.

Screen Shot 2022-05-22 at 6.18.40 PM.png

Hint: For the Profit rows, Thymeleaf allows you to subtract using the - operator.

Task 5

double is not suitable for storing currency because it has a certain precision. BigDecimal is an exact way of representing numbers.

1 Update your POJO class accordingly.

private String item; private BigDecimal revenue; private BigDecimal cost;

2 Use this List instead.

List<Record> records = Arrays.asList( new Record("Chair", new BigDecimal("20.99"), new BigDecimal("5.99")), new Record("Table", new BigDecimal("40.99"), new BigDecimal("8.99")), new Record("Couch", new BigDecimal("100.99"), new BigDecimal("105.99")), new Record("Fridge", new BigDecimal("200.99"), new BigDecimal("59.99")), new Record("Bed", new BigDecimal("150.99"), new BigDecimal("205.99")) );

Expected Output:

Screen Shot 2022-05-22 at 6.57.54 PM.png

Task 6

Common types from which Thymeleaf can leverage utility methods are:

  • #dates
  • #strings
  • #arrays
  • #lists
  • #numbers

Inside Thymeleaf Repo, the Numbers class has a utility method that can format the model attribute into a currency.

Screen Shot 2022-08-16 at 12.50.38 AM.png

Using this information, try to achieve the following output: Screen Shot 2022-05-22 at 7.04.00 PM.png

Task 7

You can use th:style to format an HTML element.

  • th:style must equal background: green if profit is greater than or equal to 0.
  • Otherwise, it must equal background: red.

Screen Shot 2022-05-22 at 7.14.33 PM.png

Good Luck!

Feedback Summary
4 students





Written Reviews
There are no written reviews yet.