4

实例

@Query(value = "SELECT max(version) FROM demo where user_id=?1",nativeQuery=true)
    int getMaxVersion(Long userId);

或者

@Query(value="select "
            + "b.id,"
            + "b.name,"
            + "b.distribute_address,"
            + "p.name as pointName,"
            + "p.code "
            + "from business b left join product p on b.id=p.business_id where b.status=0 order by id desc limit :page,:pageSize",nativeQuery=true)
    public List<Object[]> queryBusinessAndProductVos(@Param("page") int page,@Param("pageSize") int pageSize);

或者

@PersistenceContext
    EntityManager entityManager;
    @Override
    public List<Employee> getFirstNamesLikeAndBonusBigger(String firstName, Double bonusAmount) {
        Query query = entityManager.createNativeQuery("select e.* from spring_data_jpa_example.bonus b, spring_data_jpa_example.employee e\n" +
                "where e.id = b.employee_id " +
                "and e.firstname LIKE ? " +
                "and b.amount> ? ", Employee.class);
        query.setParameter(1, firstName + "%");
        query.setParameter(2, bonusAmount);
        return query.getResultList();
    }

想获取最新内容,请关注微信公众号
图片描述


codecraft
11.9k 声望2k 粉丝

当一个代码的工匠回首往事时,不因虚度年华而悔恨,也不因碌碌无为而羞愧,这样,当他老的时候,可以很自豪告诉世人,我曾经将代码注入生命去打造互联网的浪潮之巅,那是个很疯狂的时代,我在一波波的浪潮上留下...