84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
求助,想在项目中使用spring-boot-data-jpa做数据访问,构建实体User,然后UserRepository extends JpaRepository这种方式没有问题,现在想着对于数据库中有些表中数据我仅仅需要查询一个字段,不想为此构建一个实体类和定义一个访问接口,有没有相应的做法可以实现,执行一条sql语句然后返回一个对象(可以是Map,List等等..),类似的做法也行,初试jpa还望各位多多指点.
public interface UserRepository extends JpaRepository<User, Long> { @Query(value = "SELECT * FROM USERS WHERE EMAIL_ADDRESS = ?1", nativeQuery = true) User findByEmailAddress(String emailAddress); } 见http://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.query-methods.at-query 如果不想单独建一个repo,可以使用spring-jdbc