【发布时间】:2015-05-18 14:40:40
【问题描述】:
实体
@Data
@Accessors(chain = true, fluent = true)
@Entity
@Table(name = "T_NOTE")
@Access(AccessType.FIELD)
public class Note implements Serializable
{
@Id
@GeneratedValue
private Long id;
private Date date;
@Column(length = 2000)
private String content;
private String title;
private String weather;
}
存储库
@RepositoryRestResource(collectionResourceRel = "note", path = "note")
public interface NoteRepository extends AbstractRepository<Note, Long>
{
}
获取http://localhost:8080/note/2
{
"_links": {
"self": {
"href": "http://localhost:8080/note/2"
}
}
}
没有实体字段数据,为什么?
EIDT
添加标准 setter/getter 后,现在一切正常。
public Long getId()
{
return id;
}
public void setId(Long id)
{
this.id = id;
}
public Date getDate()
{
return date;
}
public void setDate(Date date)
{
this.date = date;
}
public String getContent()
{
return content;
}
public void setContent(String content)
{
this.content = content;
}
public String getTitle()
{
return title;
}
public void setTitle(String title)
{
this.title = title;
}
public String getWeather()
{
return weather;
}
public void setWeather(String weather)
{
this.weather = weather;
}
这是由 jackson mapper 造成的吗?我该如何使用 fluent API?为什么不直接使用反射来生成 JSON?
编辑
我需要的是这个配置
@Configuration
@Import(RepositoryRestMvcConfiguration.class)
public class ShoweaRestMvcConfiguration extends RepositoryRestMvcConfiguration
{
@Override
protected void configureJacksonObjectMapper(ObjectMapper mapper)
{
mapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE);
mapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
}
}
由this引起
【问题讨论】:
-
如果你删除
@Accessors,有什么不同吗?
标签: spring spring-mvc jpa spring-data spring-data-rest