Repository
@Query(value = "SELECT * FROM module m WHERE (:name is null or m.name ilike :name||'%') AND " +
"(:code is null or m.code ilike :code||'%' ) AND (:is_active is null or m.is_active = :is_active)" +
"AND (:create_date is null or m.create_date between to_date(':first_date','yyyy-MM-dd') and to_date(':second_date','yyyy-MM-dd')) ORDER BY id DESC", nativeQuery = true)
ArrayList<ModuleEntity> findAllWithFilters(String name, String code, Boolean is_active, Timestamp first_date, Timestamp second_date);
Service
public ArrayList<ModuleEntity> findAllWithFilters(String name, String code, Boolean is_active, Timestamp first_date, Timestamp second_date) {
return moduleRepository.findAllWithFilters(name, code, is_active, first_date, second_date);
}
Entity
@Column
@DateTimeFormat(pattern = "yyyy-MM-dd")
@Temporal(TemporalType.TIMESTAMP)
Timestamp create_date;
Controller
@GetMapping(FETCH_MODULES)
public HashMap<String, Object> getModules(@RequestParam("page") int page,
@RequestParam("limit") int limit,
@RequestParam(value = "code", required = false) String code,
@RequestParam(value = "name", required = false) String name,
@RequestParam(value = "is_active", required = false) Boolean is_active,
@RequestParam(value = "create_date_before", required = false) @DateTimeFormat(pattern ="yyyy-MM-dd") Timestamp first_date,
@RequestParam(value = "create_date_after", required = false) @DateTimeFormat(pattern ="yyyy-MM-dd") Timestamp second_date){
HashMap<String, Object> response = new HashMap<>();
if (code != null || name != null || is_active != null || first_date != null || second_date != null){
ArrayList<ModuleEntity> moduleFilters = moduleService.findAllWithFilters(name, code, is_active, first_date, second_date);
I need to find the range of creation date values (from and to) but I can't convert String to Timestamp type, here is the error message:
Resolved [org.springframework.web.method.annotation.MethodArgumentTypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'java.sql.Timestamp'; Failed to convert from type [java.lang.String] to type [@org.springframework.web.bind.annotation.RequestParam @org.springframework.format.annotation.DateTimeFormat java.sql.Timestamp] for value '2022-12-21']
Please tell me how to convert