Hibernate命名策略更改表名
JPA Pageable查询索引是从0开始,前端传入page值默认为1。
Page taskPage=workTaskService.queryTaskPage(taskName,scheStrategy,taskStatus,
new PageRequest(page-1,limit));
最开始我以为只有这一个问题,后来还是报错,检查代码后发现又被自己蠢死了。
之前代码
@Query("select new com.ustc.inspectweb.entity.ro.WorkTaskMonitorRo(" +
"a.workTaskId,a.devType,a.endDate,a.taskName,a.taskDesc," +
"a.startDate,a.taskStatus,a.scheStrategy,a.nextExecuteTime) " +
"from WorkTaskEntity a where a.isDelete=0 " +
" and (a.taskName is null or a.taskName like concat('%',:taskName,'%'))" +
" and (a.scheStrategy is null or a.scheStrategy=:scheStrategy )" +
" and (a.taskStatus is null or a.taskStatus=:taskStatus)" +
" order by a.startDate desc")
更改之后
@Query("select new com.ustc.inspectweb.entity.ro.WorkTaskMonitorRo(" +
"a.workTaskId,a.devType,a.endDate,a.taskName,a.taskDesc," +
"a.startDate,a.taskStatus,a.scheStrategy,a.nextExecuteTime) " +
"from WorkTaskEntity a where a.isDelete=0 " +
" and (:taskName is null or a.taskName like concat('%',:taskName,'%'))" +
" and (:scheStrategy is null or a.scheStrategy=:scheStrategy )" +
" and (:taskStatus is null or a.taskStatus=:taskStatus)" +
" order by a.startDate desc")
taskName
会传入null
@RestController
Date类型转换为JSON时,格式不正确有两种解决办法:
@JsonFormat
,仅对被注解的属性生效两个方法都有,注解优先级高。
application.properties配置
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8
spring.jackson.serialization.write-dates-as-timestamps=false #值为true表示用long型时间戳
注解设置
long型的timestamp表示日期:
@JsonFormat(shape = JsonFormat.Shape.NUMBER)
字符串表示日期:
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
场景:新建一个实体类,里面有一个desc字段,结果在保存的时候,一直报错SQL Error: 1064, SQLState: 42000
解决方法:https://stackoverflow.com/questions/28946567/sql-error-1064-sqlstate-42000-while-creating-new-entity
更改字段名称_
https://etherealbits.com/2012/12/debunking-the-myths-of-rpc-rest/