SpringCloud使用jpa之Rest方式

这个与上一篇的基本相同,需要修改的只有Dao层的文件:

TablesDao.java

package com.shinho.dao;

import org.springframework.data.jpa.repository.Query;
import  org.springframework.data.repository.CrudRepository;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;

import com.shinho.entity.Tables;

@RepositoryRestResource(collectionResourceRel = "people", path = "people")
public interface TablesDao extends CrudRepository<Tables, Integer> {
    
    @Query(value="select count(*) from props",nativeQuery=true)
    int getcount();
}

这里有个学问,就是访问的地址,是这样一个规则,比如现在看到的这个getcount的方法:

http://localhost:7088/people/search/getcount

蛋疼!

还有,这个东西是Spring Data JPA,一定要看官网,不要看网上的野文!

官网地址:http://projects.spring.io/spring-data-jpa/

原文地址:https://www.cnblogs.com/wpcnblog/p/8945280.html