public class Customer { @Id @GeneratedValue private Integer id; private String email; private Long Apprvamount; @JsonIgnore @OneToMany(mappedBy="customer", fetch = FetchType.LAZY, cascade = CascadeType.ALL) private Set<MyTransaction> transactions; @Transient private Long rewardPoints; public Long getRewardPoints() { function to calculate rewardPoints; } Contoller adding model attribute
@GetMapping("/customers/{id}") public String getCustomer(@PathVariable Integer id,Model model) throws RecordNotFoundException { Customer customer = rewardsService.getCustomerById(id); model.addAttribute("customer", customer); return "profile"; } Thymeleaf
<body> <div class="card-body"> <h2 th:text="${customer.getEmail()}"></h2> <p th:text="${customer.getApprvamount()}"></p> <p th:text="${customer.getRewardPoints()}"></p> <p class="my-5"> <a href="/{id}(id=${customer.getId()})/emi" class="btn btn-primary"> <i> All</i></a> </p> Its sometime throwing null error for getRewardPoints its working for email and approvamount.And url is not getting calculated.Getters and setters are present.What is wrong with the approach?
href. How it should be ?