1.maven添加
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
2.接口继承
import 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);
}