SQL:
CREATE VIEW my_view AS SELECT my_view_id, my_view_name FROM my_table;
创建java实体类
@Entity
@Table(name = "my_view")
public class MyView implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "my_view_id")
private Long myViewId;
@NotNull
@Column(name = "my_view_name")
private String myViewName;
}
创建Repository
import org.springframework.data.repository.CrudRepository;
public interface MyViewRepository extends CrudRepository<MyView, Long> {
}
此时则可以测试使用该Repository
@Autowired
private MyViewRepository myViewRepository;
// ...
long count = myViewRepository.count();