스프링 폼 바인딩 문제가 발생했습니다. 두 모델 카테고리 및 제품이 있습니다. 양식을 제출하는 동안스프링 폼 바인딩 드롭 다운 개체
<form:select path="category" >
<form:options items="${categoryList}"/>
</form:select>
: 컨트롤러에서
@Entity
@Table(name="PRODUCT")
public class Product
{
@Id
@GeneratedValue
private long productID;
@ManyToOne
@JoinColumn(name="categoryID")
private Category category;
//Getters and setters
}
@Entity
@Table(name = "CATEGORY")
public class Category {
@Id
@GeneratedValue
private long categoryID;
private String categoryName;
}
내가 코드 아래 사용하여 JSP 페이지에서 카테고리의 값 드롭 다운을 채울 수 있어요 제품 페이지를
@RequestMapping(value = "/productpage", method=RequestMethod.GET)
private ModelAndView getAddProductPage(){
ModelAndView modelAndView = new ModelAndView("add-product","product",new Product());
Map<Category,String> categoriesMap = new HashMap<Category, String>();
List<Category> categories = categoryService.getAllCategories();
if(categories != null && !categories.isEmpty())
{
for(Category category : categories)
{
categoriesMap.put(category, category.getCategoryName());
}
}
modelAndView.addObject("categoryList",categories);
return modelAndView;
}
을 추가 렌더링하기 400 오류가 발생했습니다. 클라이언트가 보낸 요청의 구문이 올바르지 않습니다. Failed to convert property value of type 'java.lang.String' to required type 'com.example.model.Category' for property 'category'.
각 옵션 카테고리의 페이지 소스를 올바르게 보면 할당되어 있습니다. 그러나 봄을 잘못 던지는 것을 이해하지 못한다. 도움이 필요하다. 미리 감사드립니다!
for(Category category : categories)
{
categoriesMap.put(category.geCategorytId(), category.getCategoryName());
}
및보기의 변화 :
감사하지만 그것은 작동하지 않았다는 메시지와 함께 잘못을 던졌습니다 속성 유형의 값 필수 유형 'java.lang.String의'긴 변환하지 못했습니다 'for 속성'category.categoryID '; – Rohit