我注意到在生成的实体中-(这里称为模式,请参见下文),其中添加了一些返回实例的方法,例如:
public Pattern name(String name) {
this.name = name;
return this;
}
...
public Pattern numCandles(Integer numCandles) {
this.numCandles = numCandles;
return this;
}
以上这些功能是什么?
实体
@Entity
..
public class Pattern implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@NotNull
@Size(max = 20)
@Column(name = "name", length = 20, nullable = false, unique = true)
private String name;
@NotNull
@Column(name = "num_candles", nullable = false)
private Integer numCandles;
@Column(name = "jhi_desc")
private String desc;
...
}```
答案 0 :(得分:4)
返回实例使您可以像这样链接对象的方法:
Pattern p = new Pattern().name('x').numCandles(2);
这些被称为fluent methods
,主要用于提高源代码的可读性