java - Spring MVC: Cannot convert value of type String to required type Category for property 'category' -
i have class named project has attribute category. classes project , category have one-to-many relationship.
public class project { @manytoone(fetch = fetchtype.lazy) @joincolumn(name="category_id") private category category; public class category { @onetomany(fetch=fetchtype.lazy, mappedby="category") private set<project> project = new hashset<project>(0);
in jsp have dropdown select category specific project
<select class="form-control" name="category" > <c:foreach items="${categorieslist}" var="category"> <option value="${category.id}"><c:out value="${category.category_name}" /></option> </c:foreach> </select>
and controller looks so
@requestmapping(value = "/client/post_project", method = requestmethod.post) public string postproject(@modelattribute("project") project p){ projectservice.addproject(p); return "/client/project"; }
i'm trying add project keep having error. can tell me doing wrong?
field error in object 'project' on field 'category': rejected value [3]; codes [typemismatch.project.category,typemismatch.category,typemismatch.model.category,typemismatch]; arguments [org.springframework.context.support.defaultmessagesourceresolvable: codes [project.category,category]; arguments []; default message [category]]; default message [failed convert property value of type 'java.lang.string' required type 'model.category' property 'category'; nested exception java.lang.illegalstateexception: cannot convert value of type [java.lang.string] required type [model.category] property 'category': no matching editors or conversion strategy found]
wiki
Comments
Post a Comment