Springboot uses DataRest to directly access the database

Spring-boot-data-rest

Directly map database resources to Rest resources

illustrate

  • Spring Data REST is based on Spring Data's repository, which can automatically output the repository as a REST resource.
  • Currently, repositories that support Spring Data JPA, Spring Data MongoDB, Spring Data Neo4j, Spring Data GemFire, and Spring Data Cassandra are automatically converted to REST services. Note that it is automatic.
  • To put it simply, Spring Data REST automates the large number of REST template interfaces we need to write
  • Generally used to directly expose the content of the database to the front end

add dependencies

<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>

DAO class

@RepositoryRestResource(path = "users")
public interface SysUserRepository extends JpaRepository<SysUser, Long> {
    
    

    @RestResource(path="name")
    public List<SysUser> findByName(@Param("name") String name);

    @RestResource(path="nameStartsWith",rel="nameStartsWith")
    public List<SysUser> findByNameStartsWith(@Param("name") String name);
}

Guess you like

Origin blog.csdn.net/QingChunBuSanChang/article/details/132425730