【发布时间】:2020-11-27 23:44:07
【问题描述】:
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;
}
控制器添加模型属性
@GetMapping("/customers/{id}")
public String getCustomer(@PathVariable Integer id,Model model) throws RecordNotFoundException {
Customer customer = rewardsService.getCustomerById(id);
model.addAttribute("customer", customer);
return "profile";
}
百里香
<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>
它有时会为 getRewardPoints 抛出 null 错误,它适用于电子邮件和 approvamount。并且 url 没有得到计算。存在获取器和设置器。这种方法有什么问题?
【问题讨论】:
-
你到底想在
href上穿什么。应该怎么样?
标签: spring-boot thymeleaf rest