Tag: spring form

Jsp页面给了我一个List,但是我的类想要一个Set

我有一个名为Menu的类,其中包含一个名为voceMenuList的字段,其中包含“Home”,“contact”等菜单项。 public class Menu implements Serializable{ private Set voceMenuList; public void setVoceMenuList(Set voceMenuList) { this.voceMenuList = voceMenuList;} public Set getVoceMenuList() { return voceMenuList;} } 这是我的jsp页面,我在输入文本中打印对象VoceMenu的字段,以便编辑该值 … URL … 当我发布页面时,我收到以下错误,可能是因为jsp页面返回一个List,但是我的类期望一个Set。 我该如何解决这个问题? 谢谢 org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.beans.InvalidPropertyException: Invalid property ‘voceMenuList[0]’ of bean class [com.springgestioneerrori.model.Menu]: Getter for property ‘voceMenuList’ threw exception; nested exception is […]

Spring MVC Form:抽象类列表的数据绑定

我inheritance了一些我需要添加function的代码,它涉及一个基于Spring和Spring Form构建的程序,带有一个列表和绑定的抽象元素 所以我们有一个像下面这样的抽象类 public abstract class A { private int id; private String name; private int type; ….getters and setters below } 还有一些实现如 public class AImplOne extends A { private String text; …getters, setters etc } public class AImplTwo extends A { private int mediaID; …getters, setters etc } 所以AImpl类实现了A,但是根据实现类型有一个额外的信息。 然后我们有一个B类,它包含A对象列表,其中包含A实现的列表(可以是不同实现类型的混合列表) public class B { […]

如何在spring 中保存许多对象

@Component @Entity @Table(name=”menu”) @Configurable public class Menu implements Serializable{ …. @OneToMany(mappedBy=”menu”, fetch=FetchType.EAGER) private Set voceMenuList; public Set getVoceMenuList() { return voceMenuList; } public void setVoceMenuList(Set voceMenuList) { this.voceMenuList = voceMenuList; } ….. } 我打印一个表单来编辑菜单,以及它的相对VoceMenu对象,这样: Menu id …… ….. 但是,当我尝试保存对象菜单时,我收到此错误: bean类[com.springgestioneerrori.model.Menu]的属性’voceMenuList [0]’无效:无法使用属性路径’voceMenuList [0]’访问大小为0的索引0的元素

java.lang.IllegalStateException:BindingResult和bean名称’category’的普通目标对象都不能作为请求属性使用

我在网上查看了几乎所有与此问题相关的答案,但无法在我的代码中找出问题所在。 这是我的JSP页面。 当我删除 它工作正常。 我可以与我的控制器通信。 所以问题与这条线有关。 @Controller public class SearchCategory { @Autowired private CategoryService categoryService; @RequestMapping(value = “/search_category”, method = RequestMethod.POST) public @ResponseBody String searchCategoryFromDatabase(@ModelAttribute(“category”) Category category, BindingResult result){ return “something”; } } 这是我的web.xml appServlet org.springframework.web.servlet.DispatcherServlet contextConfigLocation /WEB-INF/servlet-context.xml 1 appServlet / contextConfigLocation /WEB-INF/applicationContext.xml hibernateFilter org.springframework.orm.hibernate4.support.OpenSessionInViewFilter hibernateFilter /* org.springframework.web.context.ContextLoaderListener 这是我的servlet-context.xml 还有我的applicationContext.xml classpath:hibernate.cfg.xml com.XXXX hibernate.dialect=org.hibernate.dialect.MySQLDialect 我可能在我的XML文件中做错了。 我是今年spring的新手 […]