You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
admin-client-temperature/src/main/java/com/rehome/mqttclienttemperature/dao/TemperatureEspRepository.java

108 lines
4.1 KiB
Java

package com.rehome.mqttclienttemperature.dao;
import com.rehome.mqttclienttemperature.entity.TemperatureEsp;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import java.util.List;
/**
* Esp8266 DHT湿
* T :
* ID :OID
*
*/
public interface TemperatureEspRepository extends JpaRepository<TemperatureEsp,Long> {
//方法名称必须要遵循驼峰式命名规则findBy关键字+属性名称(首字母大写)+查询条件(首字母大写)
TemperatureEsp findByDataDate(String dataDate);
TemperatureEsp findByDataHour(String dataHour);
TemperatureEsp findByDataMinute(String dataMinute);
@Query(value = "select * from temperature t where t.data_date=?1 and t.location_desc=?2", nativeQuery = true)
List<TemperatureEsp> findByDataDateAndLocationDesc(String dataDate,String locationDesc);
List<TemperatureEsp> findFirst10ByDataDateAndLocationDesc(String dataDate,String locationDesc, Sort sort);
Page<TemperatureEsp> queryFirst10ByDataDateAndLocationDesc(String dataDate,String locationDesc, Pageable pageable);
TemperatureEsp findFirstByOrderByDataDateDesc();
// 五、分页查询
//
// Page<User> findALL(Pageable pageable);
// Page<User> findByUserName(String userName,Pageable pageable);
//
// 在查询的方法中需要传入参数Pageable ,
// 当查询中有多个参数的时候Pageable建议做为最后一个参数传入 。
// Pageable 是 Spring 封装的分页实现类,使用的时候需要传入页数、每页条数和排序规则。
//
// int page=1,size=10;
// Sort sort = new Sort(Direction.DESC, "id");
// Pageable pageable = new PageRequest(page, size, sort);
// userRepository.findALL(pageable);
// userRepository.findByUserName("testName", pageable);
//
//
// 六、限制查询
//
// 查询前 N 个元素
//
// User findFirstByOrderByLastnameAsc();
// User findTopByOrderByAgeDesc();
// Page<User> queryFirst10ByLastname(String lastname, Pageable pageable);
// List<User> findFirst10ByLastname(String lastname, Sort sort);
// List<User> findTop10ByLastname(String lastname, Pageable pageable);
//
// 使用Spring JPA中Page、Pageable接口和Sort类完成分页排序【专题】
//
// 首先来说一下分页和排序所用到的Page、Pageable接口和Sort类都是什么
//
// JpaRepository提供了两个和分页和排序有关的查询
//
// List findAllSort sort 返回所有实体,按照指定顺序排序返回
//
// List findAllPageable pageable 返回实体列表实体的offest和limit通过pageable来指定
//
// Sort对象用来指示排序最简单的Sort对象构造可以传入一个属性名列表不是数据库列名是属性名默认采用升序排序。例
//
// Sort sort = new Sort("id")
// //或 Sort sort = new Sort(Direction.ASC,"id");
// return userDao.findAll(sort);
// 程序将查询所有user并按照id进行生序排序。Sort还包括其他一些构造方法在这里就不一一赘述。
//
// Pageable接口用于构造翻页查询PageRequest是其实现类可以通过提供的工厂方法创建PageRequest
//
// public static PageRequest of(int page, int size)
// 也可以在PageRequest中加入排序
//
// public static PageRequest of(int page, int size, Sort sort)
// 方法中的参数page总是从0开始表示查询页size指每页的期望行数。
//
// Page接口可以获得当前页面的记录、总页数、总记录数、是否有上一页或下一页等。Spring Data翻页查询总是返回Page对象Page对象提供了以下常用的方法
//
// int getTotalPages() 总的页数
// long getTotalElements() 返回总数
// List getContent() 返回此次查询的结果集
// ————————————————
}