Python 官方文档:入门教程 => 点击学习
目录jpa查询指定的字段下面是实例代码spring data jpa查询自定义查询字段jpa查询指定的字段 JpaRepository中new的方式产生新的对象,并配置好其构造函数
JpaRepository中new的方式产生新的对象,并配置好其构造函数
JPA对字段命名有一点规则,推荐使用驼峰式命名,如果下面的方法会报错,并且没有明确的报错信息,请先看字段是否合法!!!!!
JpaRepository:
@Transactional
public interface PayeeDataRepo extends JpaRepository<PayeeData, String> {
@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<PayeeData> 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;
}
}
@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<Map<String, Object>> getHotCity(Date date, String pcode);
List<Map<String, Object>> cityHotBOList = quesRepository.getHotCity(dataDate, pcode);
if(null == cityHotBOList || cityHotBOList.size() <= 0){
return null;
}
for(int i = 0; i< top && i<cityHotBOList.size();i++){
Map<String, Object> cityHotBO = cityHotBOList.get(i);
HotCityResVO hotCityResVO = new HotCityResVO();
hotCityResVO.setName((String)cityHotBO.get("city"));
List<Attractions> attractionsList = attractionsRepository.findByCity((String)cityHotBO.get("city"));
hotCityResVO.setCode(attractionsList.get(0).getCityCode());
hotCityResVO.setNum((BigDecimal)cityHotBO.get("view"));
hotCityResVOList.add(hotCityResVO);
}
以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程网。
--结束END--
本文标题: jpa实现只查询指定的字段
本文链接: https://lsjlt.com/news/159281.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0