0
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?

1
  • what exactly are you trying to put on href. How it should be ? Commented Aug 7, 2020 at 15:59

1 Answer 1

1

You may have misspelt customer:

model.addAttribute("costumer", customer); 
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks now the email part is working but url and rewardPoints is not working
In your description, you still have spelled "custumer" instead of "customer".
Url is complete disaster. Please refer to Thymeleaf reference for Link URLs. It should looks similar to: <a href="@{/{id}/emi(id=${customer.id})}" class="btn btn-primary"><i>All</i></a>
Thank you very much.It was the syntax error like you mentioned.Now url is working.But still rewardPoints is throwing error .What is the right approach?
The rewardPoints is Long and may be it set to null. In this case you would need something like this: Using Thymeleaf when the value is null

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.