1.maven添加
复制代码
1
2
3
4
5
6<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency>
2.接口继承
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33import com.xinyartech.modules.proxy.domain.ProxyUser; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.query.Param; /** * @program: eladmin * @description: 代理商 * @author: bright * @create: 2020-06-02 13:45 **/ public interface UserDao extends CrudRepository<User,Long> { /** * 查询团队数(jpa查询) * @param id * @return */ Integer countById(@Param("id") Long id); /** * 获取用户名称(实体查询) * @param id * @return */ @Query(value = "select username from User where id = :id") String findName(@Param("id") Long id); /** * 根据ID查询名称(sql查询) * @param id ID * @return / */ @Query(value = "select name from user where id = ?1",nativeQuery = true) String findNameById(@Param("id") Long id); }
最后
以上就是沉静小蜜蜂最近收集整理的关于接口继承CrudRepository实现query查询的全部内容,更多相关接口继承CrudRepository实现query查询内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复