I'm getting and exception that I do not understand. I have a controller, it gives me back a news object and it appears in the Console, so getting the actual news object is not the problem,
@RequestMapping(value ="/viewonestatus/{id}")
public ModelAndView viewOneStatus(@PathVariable("id") Long id) {
System.out.println("!!!!!! STATUSUPDATECONTROLLER: viewOneStatus : Empezamos con el ID del Anuncio: " + id);
StatusUpdate status = statusUpdateService.get(id);
ModelAndView modelAndView = new ModelAndView();
System.out.println("!!!!!! STATUSUPDATECONTROLLER: viewOneStatus : Empezamos con el ID del Anuncio: " + status);
modelAndView.getModel().put("status", status);
modelAndView.setViewName("viewonestatus");
return modelAndView;
}
.... but when try to execute the JSP it gives me the following error, even with an almost empty JSP, like....
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
hello world
Exception: Exception: org.springframework.web.method.annotation.MethodArgumentTypeMismatchException: Failed to convert value of type [java.lang.String] to required type [java.lang.Long]; nested exception is java.lang.NumberFormatException: For input string: "viewonestatus"
Failed URL: http://localhost:8080/viewonestatus/viewonestatus
Exception message: Failed to convert value of type [java.lang.String] to required type [java.lang.Long]; nested exception is java.lang.NumberFormatException: For input string: "viewonestatus"
Thanks a lot for your help
@RequestMapping(value ="/viewonestatus/{id}")
public ModelAndView viewOneStatus(@PathVariable("id") Long id)
Here you are declaring a path variable named "id" and you declare its type as Long. Nextly you are calling url:
http://localhost:8080/viewonestatus/viewonestatus
the second "viewonestatus" is obviously not a Long type and this is why spring is throwing an exception because it can't convert "viewonestatus" to Long
your reqeust should look like
http://localhost:8080/viewonestatus/12321
Well, this was driving me nuts for about 1/2 hour. If you're using SpringBoot, this could help you.
I realized in my controller I was using
@Controller
in stead of
@RestController
That was it. Ugh.