SpringBoot JPA接口使用方法

来源:互联网 发布:手机放线软件 编辑:程序博客网 时间:2024/05/17 08:13

SpringData其中的一个核心接口给我们提供了常用的方法 .
Repository 接口是 Spring Data 的一个核心接口,它不提供任何方法,开发者需要在自己定义的接口中声明需要的方法 :

public interface Repository

@Resourceprivate JdbcTemplate jdbcTemplate;public Demo getById(long id){    String sql = "select *from Demo where id=?";    RowMapper<Demo> rowMapper = new BeanPropertyRowMapper<Demo>(Demo.class);    return jdbcTemplate.queryForObject(sql, rowMapper,id);}@Resourceprivate DemoDao demoDao;public void save(Demo demo){    demoRepository.save(demo);}