spring data jpa 支持原生sql

只需要在repository接口里定义方法,方法上用@Query注解,设置nativeQuery=true即可

例如:

@Query(value = "select tt.*  from\n" +
"your sql",nativeQuery = true)
Object[] homeLastSixMonthAvgPrice();
注意返回的是数组哦,每个数组是一条数据,每条数据中每列又放在数组中。整体是个二维数组。

springboot primary标签

springboot中一个接口多个实现类,需要加@Primary标签

要不然,spring不知道该调用哪个实现。

示例代码:

@Primary
@Bean(name = "sjDb")
@ConfigurationProperties(prefix = "spring.sj")
public DataSource sjDataSource() {
return DataSourceBuilder.create().build();
}

@Bean(name = "tmwDb")
@ConfigurationProperties(prefix = "spring.tmw")
public DataSource tmwDataSource() {
return DataSourceBuilder.create().build();
}

spring jpa 带条件排序分页

@RequestMapping("/house_avg_price")
public List<HouseAvgDto> house_avg_price(String l, String d, Integer p){
Sort sort = new Sort(Sort.Direction.DESC, "signdate")
.and(new Sort(Sort.Direction.ASC, "location"));
PageRequest pageable = new PageRequest(p, 10,sort);
Specification<AreaAvgPriceTmw> specification = (root, cq, cb) -> {
List<Predicate> predicate = new ArrayList<>();
if(org.apache.commons.lang.StringUtils.isNotEmpty(l)){
predicate.add(cb.equal(root.<String>get("location"),l));
}
if(StringUtils.isNotEmpty(d)){
predicate.add(cb.equal(root.get("signdate"),d));
}
Predicate[] pre = new Predicate[predicate.size()];
return cq.where(predicate.toArray(pre)).getRestriction();
};
final Page<AreaAvgPriceTmw> all = areaAvgPriceTmwRepository.findAll(specification, pageable);
Iterator<AreaAvgPriceTmw> areaAvgPriceTmwEntities = all.iterator();

List<HouseAvgDto> houseAvgDtoList = new ArrayList<>();
while (areaAvgPriceTmwEntities.hasNext()){
AreaAvgPriceTmw v = areaAvgPriceTmwEntities.next();
HouseAvgDto houseAvgDto = new HouseAvgDto();
houseAvgDto.setId(v.getId());
houseAvgDto.setBroough(v.getLocation());
houseAvgDto.setSignDate(v.getSigndate());
houseAvgDto.setNewHouseAvgPrice(v.getAvgpriceNet());
houseAvgDto.setNewHouseAvgPriceShow(v.getAvgpriceNetShow());
houseAvgDto.setSecHouseAvgPrice(v.getAvgpriceSec());
houseAvgDto.setSecHouseAvgPriceShow(v.getAvgpriceSecShow());
houseAvgDtoList.add(houseAvgDto);
}
return houseAvgDtoList;
}

MacBookpro各版本变化

对比一下苹果的各个版本,看买哪个比较合适。

2012首次加入视网膜屏幕,可以自己换内存和硬盘,2个内存插槽。2016接口少了,薄了很多,logo不亮了,加入了蝴蝶键盘。2018升级了四核CPU,键盘防灰,硬盘读写大幅提升。