一、用法
1.作用在成员变量上
2.作用在get方法上
在开发中,会遇到数据库中查询出来的数据在页面展示的时候格式不是想要的,使用2可以获取字段的格式化。例如:
@Transient
public Label getCurrentLabel() {
List<Label> labels = getLabels();
if(labels == null || labels.isEmpty()) {
return null;
}
Label current = null;
int seq = 0;
for(Label label : labels) {
if(label.getLabelSeq() > seq) {
current = label;
seq = label.getLabelSeq();
}
}
return current;
}
或者
private String price;
@Column(name = "price", length = 20)
public String getPrice() {
return this.price;
}
public void setPrice(String price) {
this.price = price;
}
@Transient
public String getPriceStr(){
return new
DecimalFormat("0.00").format(Double.parseDouble(this.getPrice()));
}
```