Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I make a method of search using named query
@Query(value = "SELECT * FROM working_day w INNER JOIN \r\n"
+ "employees_days e ON \r\n"
+ "w.day_id = e.day_id\r\n"
+ "WHERE w.date LIKE %:date% AND e.employee_id LIKE %:employee_id%", nativeQuery = true)
List<WorkingDay> searchDaysForMonth(@Param("date") String date, @Param("employee_id") Long employeeId);
Service:
public List<WorkingDay> countDays(String date, Long employeeId) {
return workingDayRepository.searchDaysForMonth(date, employeeId);
Controller method:
@RequestMapping(value = "/employees")
@GetMapping(value = "/employees/days_in_month")
public ModelAndView getDaysForEmployee(@RequestParam(value = "date", required = false) String date,
@RequestParam(value = "employee_id") Long employeeId) {
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("days_employees");
var daysForEmployee = employeeService.countDays(date, employeeId);
modelAndView.addObject("days_employees", daysForEmployee);
Employee employee = employeeService.getById(employeeId);
modelAndView.addObject("employee", employee);
var totalDays = daysForEmployee.size();
modelAndView.addObject("totalDays", totalDays);
return modelAndView;
When I enter the following mapping value
http://localhost:8080/employees/days_in_month?date=2023-01&employee_id=2
I get MethodArgumentTypeMismatchException. Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long';
How to solve this?
–
–
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.