jpa实现只查询指定的字段

网友投稿 1656 2022-11-17

jpa实现只查询指定的字段

jpa实现只查询指定的字段

目录jpa查询指定的字段下面是实例代码spring data jpa查询自定义查询字段

jpa查询指定的字段

JpaRepository中new的方式产生新的对象,并配置好其构造函数

JPA对字段命名有一点规则,推荐使用驼峰式命名,如果下面的方法会报错,并且没有明确的报错信息,请先看字段是否合法!!!!!

下面是实例代码

JpaRepository:

@Transactional

public interface PayeeDataRepo extends JpaRepository {

@Query("select new com.stylefeng.guns.workday.bean.PayeeData(p.id,p.name,p.bankAccountNumberEncode,p.adhocPayeeID,p.isDomestic,p.bankAccountName ) from PayeeData p")

List finddAllNoBankNumber();

}

PayeeData Bean:

public class PayeeData implements Serializable {

public PayeeData() {

}

public PayeeData(String id, String name, String bankAccountNumberEncode, String adhocPayeeID, Integer isDomestic, String bankAccountName) {

this.id = id;

this.name = name;

this.bankAccountNumberEncode = bankAccountNumberEncode;

this.adhocPayeeID = adhocPayeeID;

this.isDomestic = isDomestic;

this.bankAccountName = bankAccountName;

}

}

spring data jpa查询自定义查询字段

@Query(value = "SELECT a.city city,sum(m.page_view) view from t_ques m " +

"LEFT JOIN attractions a on m.spot_name=a.name where m.ques_time<= ?1 and a.province_code=?2 GROUP BY a.city ORDER BY view desc", nativeQuery = true)

List> getHotCity(Date date, String pcode);

List> cityHotBOList = quesRepository.getHotCity(dataDate, pcode);

if(null == cityHotBOList || cityHotBOList.size() <= 0){

return null;

}

for(int i = 0; i< top && i

Map cityHotBO = cityHotBOList.get(i);

HotCityResVO hotCityResVO = new HotCityResVO();

hotCityResVO.setName((String)cityHotBO.get("city"));

List attractionsList = attractionsRepository.findByCity((String)cityHotBO.get("city"));

hotCityResVO.setCode(attractionsList.get(0).getCityCode());

FfLEW hotCityResVO.setNum((BigDecimal)cityHotBO.get("view"));

hotCityResVOList.add(hotCityResVO);

}

Map cityHotBO = cityHotBOList.get(i);

HotCityResVO hotCityResVO = new HotCityResVO();

hotCityResVO.setName((String)cityHotBO.get("city"));

List attractionsList = attractionsRepository.findByCity((String)cityHotBO.get("city"));

hotCityResVO.setCode(attractionsList.get(0).getCityCode());

FfLEW hotCityResVO.setNum((BigDecimal)cityHotBO.get("view"));

hotCityResVOList.add(hotCityResVO);

}

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:CF711D-Directed Roads(组合数学 dfs找环)
下一篇:container and Injection
相关文章

 发表评论

暂时没有评论,来抢沙发吧~