Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 带Hibernate列表的Spring MVC_Java_Hibernate_Jsp_Spring Mvc - Fatal编程技术网

Java 带Hibernate列表的Spring MVC

Java 带Hibernate列表的Spring MVC,java,hibernate,jsp,spring-mvc,Java,Hibernate,Jsp,Spring Mvc,因此,我在Oracle中设置了一些表,使用SpringMVC,我能够获得每个表中所有对象的列表,并使用SpringFormSelect在jsp中显示它们。现在我似乎不知道如何允许用户选择一个,保留用户选择的对象,然后使用他们选择的对象进行操作。我能够得到他们选择的字符串,但这没有帮助,因为我需要实际选择的对象 @Controller public class TestController { @Autowired GenericDAO<Material> matDA

因此,我在Oracle中设置了一些表,使用SpringMVC,我能够获得每个表中所有对象的列表,并使用SpringFormSelect在jsp中显示它们。现在我似乎不知道如何允许用户选择一个,保留用户选择的对象,然后使用他们选择的对象进行操作。我能够得到他们选择的字符串,但这没有帮助,因为我需要实际选择的对象

@Controller
public class TestController {

    @Autowired
    GenericDAO<Material> matDAO;

    @Autowired
    GenericDAO<Structure> structDAO;

    @RequestMapping(method=RequestMethod.GET)
    public ModelAndView getForm(){

        ModelAndView model = new ModelAndView("testForm");

        return model;

    }

    @ModelAttribute
    public void displayForm(Model model){
        List<Structure> structList = structDAO.retrieveAll(Structure.class);
        model.addAttribute("structure", new Structure());
        model.addAttribute("structList", structList);

    }

    @RequestMapping(value="/submitChoices.html", method=RequestMethod.POST)
    public ModelAndView getStruct(@ModelAttribute("structure") Structure struct){

        //Manipulate Structure Object Here

    } 


}
@控制器
公共类测试控制器{
@自动连线
通用道;
@自动连线
一般道结构道;
@RequestMapping(method=RequestMethod.GET)
公共模型和视图getForm(){
ModelAndView模型=新的ModelAndView(“测试表单”);
收益模型;
}
@模型属性
公共作废显示表单(模型){
List structList=structDAO.retrieveAll(Structure.class);
addAttribute(“结构”,新结构());
model.addAttribute(“structList”,structList);
}
@RequestMapping(value=“/submitChoices.html”,method=RequestMethod.POST)
公共ModelAndView getStruct(@modeldattribute(“structure”)struct){
//在此操作结构对象
} 
}
JSP页面:

<body>

<springform:form method="POST" action="/project/submitchoices.html">

    <springform:select>
        <springform:option value="0" label="--- Select One ---"/>
        <springform:options items="${structList}" itemValue="type" itemLabel="type"/>

    </springform:select>

    <input type="submit" value="submit">
</springform:form>

</body>


您需要每个选项的对象ID,以便Hibernate可以识别每个选项。ID将您与选定的对象联系起来。现在你只有structList。请注意,上面有一个值=“0”。在每个填充的实际选择中,这些也需要值。

您需要每个选项的对象ID,以便Hibernate可以识别每个选项。ID将您与选定的对象联系起来。现在你只有structList。请注意,上面有一个值=“0”。在每个填充的实际选择中,这些也需要值。

在我的结构类中,我有字段“type”和“sID”,其中“sID”是主键。我是否可以将上面JSP中的itemValue更改为“sID”?我将使用${sID}代替类型;然后,当你回到控制器时,你可以使用这个id来检索和/或处理这个对象,因为你知道它是哪一个。这不起作用。我认为$符号只用于从控制器获取一些东西,并使用model.addattribute()从控制器中获取到.jsp。如果我将itemValue更改为“sID”,这是“structure”表中的一个字段,它应该将所选字段的id传递给getStruct()方法。但是,它也不起作用,它只给了我“0”,这意味着我实际上没有获得Id。也许我和你不在同一页上,因为你所有的代码都不在这里。看看这个例子。他甚至有一个可以下载的例子。在我的结构类中,我有字段“type”和“sID”,其中“sID”是主键。我是否可以将上面JSP中的itemValue更改为“sID”?我将使用${sID}代替类型;然后,当你回到控制器时,你可以使用这个id来检索和/或处理这个对象,因为你知道它是哪一个。这不起作用。我认为$符号只用于从控制器获取一些东西,并使用model.addattribute()从控制器中获取到.jsp。如果我将itemValue更改为“sID”,这是“structure”表中的一个字段,它应该将所选字段的id传递给getStruct()方法。但是,它也不起作用,它只给了我“0”,这意味着我实际上没有获得Id。也许我和你不在同一页上,因为你所有的代码都不在这里。看看这个例子。他甚至有一个可以下载的例子。