Spring数据设置权限

时间:2016-11-08 17:20:16

标签: java spring spring-boot spring-data spring-rest

我试图使用Spring数据休息来构建我的实体。 这是我的依赖,

compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-rest', version: '1.4.1.RELEASE'
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '1.4.1.RELEASE'
    compile group: 'com.h2database', name: 'h2', version: '1.4.193'
    testCompile group: 'junit', name: 'junit', version: '4.11'

这是我对实体的定义,

@Entity
public class User extends BaseEntity{
    private String yguid;
    private String name;
    private String email;
    @OneToMany(mappedBy = "user", cascade = CascadeType.ALL)
    private List<Message> messages;

    protected User(){
        super();
        messages = new ArrayList<>();
    }

    public User(String yguid, String name, String email) {
        this();
        this.yguid = yguid;
        this.name = name;
        this.email = email;
    }
}

另一个,

@Entity
public class Message extends BaseEntity{

    private String senderId;
    private String receiverId;
    private String mediaId;
    @ManyToOne
    private User user;

    protected Message(){
        super();
    }

    public Message(String senderId, String receiverId, String mediaId) {
        this();
        this.senderId = senderId;
        this.receiverId = receiverId;
        this.mediaId = mediaId;
    }
}

这些是我的存储库,

public interface UserRepository extends CrudRepository<User, Long> {
}

public interface MessageRepository extends CrudRepository<Message, Long>{

}

这是我的切入点。

@SpringBootApplication
public class App {
    public static void main(String[] args) {
        SpringApplication.run(App.class, args);
    }
}

当我启动服务器时,转到localhost:8080 / 这就是我得到的,

{
_links: {
profile: {
href: "http://localhost:8080/profile"
}
}
}

我希望看到这些实体,就像Spring教程一样。我在这里做错了什么?

2 个答案:

答案 0 :(得分:1)

您是否尝试使用@RepositoryRestResource注释您的存储库?这肯定会有效。

答案 1 :(得分:0)

我认为您的代码没有任何问题。你试过吗

  

http://localhost:8080/users

  

http://localhost:8080/messages