初识SpringBoot——Spring Data Rest的简单使用

引言

初识SpringBoot——Spring Data Rest的简单使用_第1张图片

使用

  1. 引入jar包
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
  1. 利用jpa生成相关实体类(省略,可以看我上一篇博客:利用JPA自动生成实体类)

  2. 定义Repository,并实现JpaRepository。并使用注解@RepositoryRestResource

@RepositoryRestResource(path = "users")
public interface UserRepositoty extends JpaRepository<VipUserEntity, Integer> {
}

齐活! 没错,都不用我们自己写Controller了

访问localhost:8080,我们会神奇的看到返回的数据像这样:

初识SpringBoot——Spring Data Rest的简单使用_第2张图片
然后我们访问localhost:8080/users,就可以拿到相关数据了~

你可能感兴趣的:(程序人生)