Sprint Date Rest 成功,但没有数据

Sprint Date Rest successful, but no data

实体

@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造成的吗?我怎样才能使用流利的 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 可能会越过 @Data 注释,并且使用 fluent = true 它会生成与字段同名的 getters,例如 id()date() (@Accessor documentation)。这就是 Spring 看不到任何字段的原因。

我认为您可以安全地删除 @Accessors@Access,因为 @Accessid 中获取默认值(如果您对该字段进行注释,它将是 FIELD,如果您注释 getter,它将是 PROPERTY)。