下面是请求主体的模型类
@NoArgsConstructor
@AllArgsConstructor
@Data
public class ActiveAccountRequest {
@Column(name = "startDate")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime startDate;
@Column(name = "endDate")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime endDate;
private List<Character> channel;
}
用于JPA连接的我的存储库用户
@Repository
public interface ReportingGenRepo extends JpaRepository<ReportingGeneral, Integer> {
@Query(value = "SELECT REPORTING_GENERAL.USERNAME AS userName, " +
"ANY_VALUE (REPORTING_GENERAL.CONTACT_NUMBER ) AS contactNumber,ANY_VALUE (REPORTING_GENERAL.PRIMARY_KEY) AS primaryKey," +
"MIN( REQUEST_TIME ) AS minRequestTime ,MAX( REQUEST_TIME ) AS maxRequestTime, " +
"COUNT(IF ( RESPONSE_CODE = '1', 1, NULL )) AS success,COUNT(IF " +
"( RESPONSE_CODE != '1', 1, NULL )) AS failed,COUNT(*) AS totalHits,CHANNEL as channel" +
" FROM REPORTING_GENERAL WHERE " +
" REPORTING_GENERAL.ID > 0 AND CHANNEL IN ?3 AND (REPORTING_GENERAL.REQUEST_TIME BETWEEN ?1 AND ?2)" +
"GROUP BY channel, username",
countQuery = "SELECT count(*) FROM REPORTING_GENERAL WHERE " +
" REPORTING_GENERAL.ID > 0 AND CHANNEL IN ?3 AND (REPORTING_GENERAL.REQUEST_TIME BETWEEN ?1 AND ?2)" +
"GROUP BY channel, username ", nativeQuery = true)
public Page<ActiveAccountReport> getActiveAccountReportFilters(
LocalDateTime startDate,
LocalDateTime endDate,
List<String> channel,
Pageable pageable);
下面是我的Controller类
@RestController
@RequestMapping("/repo")
public class ReportingGenController {
@Autowired
private ReportingGenService reportingGenService;
@GetMapping("/get")
public Page<ActiveAccountReport> findAll(@RequestBody ActiveAccountRequest activeAccountRequest,
@RequestParam(value = "page",defaultValue = "0") Integer page, @RequestParam(value = "size",defaultValue = "1") Integer size){
return reportingGenService.paginatedActiveAccountReports(activeAccountRequest,page,size);
}
}
现在我想在requestBody中为我的endDate和startDate给予一个默认值。
3条答案
按热度按时间h4cxqtbf1#
只需使用所需的默认值
LocalDateTime
初始化字段。alen0pnh2#
当使用Lombok尤其是
@Data
注解时,您无法设置默认值,在我看来,你有两个选择来设置你的变量的默认数据,
第一个:从类中删除
@Data
注解,实现getter和setter手册并设置值,如以下代码片段所示对于第二个,您可以使用内部类构建器来实现它,请查看此引用https://www.baeldung.com/lombok-builder-default-value
wlzqhblo3#
你可以的
当你要声明你的变量Stat date或end Date时,你可以用默认值初始化,例如
像这样