实体类
public class CapitalFlow implements Serializable {
@Column(length = 40)
String subAccount;
/**
* 处理进度
*/
Stage stage;
@CreatedDate
LocalDate billDate;
@CreatedDate
LocalDateTime createAt;
}
枚举类型定义
public enum Stage {
/**
* 0.未知,未开始
*/
UNKNOWN,
/**
* 1.处理中
*/
PROCESSING,
/**
* 2.成功
*/
SUCCESS,
/**
* 3.失败
*/
FAILURE,
/**
* 4.完成,结束
*/
FINISHED,
}
sql的两种写法
1)第一种用原生sql
@Query(value = "select * from capital_flow where sub_account=?1 and stage=?2 and bill_date like CONCAT(?3,’%’) ORDER BY create_at DESC ",nativeQuery = true)
List findBySubAccountAndStageAndBillDateLikeOrderByCreateAtDesc(String subAccount,int stage,String billDate);
因为数据库stage这个字段的类型是int,所以用原生sql的时候,类型参数要是int类型,Stage.SUCCESS.ordinal()取数字值。
2)第二种用对象HQL
@Query(value = “select c from CapitalFlow c where c.subAccount=?1 and c.stage=?2 and