и так,у меня есть jsp страница с некой формой ввода
<%@page contentType="text/html;charset = UTF-8" language="java" %>
<%@page isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<jsp:useBean id="Type" class="spring.example.config.TypeValuesConfig"/>
<html>
<head>
Title
</head>
<body>
<form method="post" action="/addBoxEntity/${box.id}">
<h2>Information about BoxEntity</h2>
<p><input type="text" placeholder="colour" name="colour"></p>
<p><input type="hidden" placeholder="id" name="id"></p>
<p><input type="text" placeholder="name" name="name" value="${box.name}"></p>
<p><input type="number" placeholder="weight" name="weight"></p>
<p><input type="number" placeholder="memory" name="memory"></p>
<select name="type" id="type">
<c:forEach items="${Type.values}" var="type">
<option value="${type}">${type}</option>
</c:forEach>
</select>
<input type="submit" value="save">
</form>
</body>
</html>
есть контроллер,который ее принимает
@RequestMapping(value = "/addBoxEntity/{box}", method = RequestMethod.POST)
public String addBoxEntity(@PathVariable Long box, Info info) {
System.out.println(info.toString());
boxService.add(box,info);
return "redirect:/";
}
Service class:
public void add(Long boxId, Info info) {
Session session = sessionFactory.getCurrentSession();
session.save(info);
Box box=session.get(Box.class,boxId);
box.getInfo().add(info);
session.save(box);
Pojo:
@Entity
@Table(name = "INFO")
public class Info {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
@Column(name = "memory")
private Long memory;
@Enumerated(EnumType.STRING)
@Column(name = "type")
private Type type;
@Column(name = "colour")
private String color;
@Column(name = "weight")
private Double weight;
@ManyToOne
@JoinColumn(name = "box_id", nullable = true)
private Box box;
получаю ошибку
Field error in object 'info' on field 'box': rejected value [1]; codes [typeMismatch.info.box,typeMismatch.box,typeMismatch.spring.example.model.Box,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [info.box,box]; arguments []; default message [box]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'spring.example.model.Box' for property 'box'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'spring.example.model.Box' for property 'box': no matching editors or conversion strategy found]]
Info info
надо пометить аннотацией@RequestBody