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 Answers1

1

You may have misspelt customer:

model.addAttribute("costumer", customer);
Tom Spencer
  • 34
  • 1
  • 4
  • Thanks now the email part is working but url and rewardPoints is not working – ankit dubey Aug 07 '20 at 18:07
  • In your description, you still have spelled "custumer" instead of "customer". – Slava Ivanov Aug 07 '20 at 20:07
  • 1
    Url is complete disaster. Please refer to Thymeleaf reference for Link URLs. It should looks similar to: `All` – Slava Ivanov Aug 07 '20 at 20:15
  • 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? – ankit dubey Aug 08 '20 at 05:15
  • 1
    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](https://stackoverflow.com/questions/20636456/using-thymeleaf-when-the-value-is-null) – Slava Ivanov Aug 08 '20 at 16:40