Java 如何在spring中显示从数据库获取的值<;表格:输入>;?

Java 如何在spring中显示从数据库获取的值<;表格:输入>;?,java,spring,spring-mvc,arraylist,Java,Spring,Spring Mvc,Arraylist,我需要显示从数据库中获取的值,这些值使用spring form:input标记存储在arraylist中。但是我发现“value”属性不受支持。请帮忙 我猜你在期待这样的事情 //假设你的课堂上有以下内容 public class Students{ private String name; private List<String> Departments; /* getters/setters */ } 公共班级学生{ 私有字符串

我需要显示从数据库中获取的值,这些值使用spring form:input标记存储在arraylist中。但是我发现“value”属性不受支持。请帮忙

我猜你在期待这样的事情

//假设你的课堂上有以下内容

    public class Students{
      private String name;
      private List<String> Departments;
     /* getters/setters */
    }
公共班级学生{
私有字符串名称;
私人名单部门;
/*能手/二传手*/
}
在HTML中可能是

    <form:input path="departments[0]" />
    <form:input path="departments[1]" />


有关单击的更多详细信息,请首先从数据库中检索列表,并在控制器中的模型属性上设置列表,请参见设置列表的示例

@Controller
public class UserController {

    @RequestMapping(method = RequestMethod.GET)
    public String userHome(Model model, EventBean event, UserService userService,ImageBean image)
    {
         List<Event> events = userService.viewNews(); //retrieve the list from datebase 
                 model.addAttribute("event", event); //add bean object 
         model.addAttribute("events", events); //add list in model attribute
         return "home";
    }
}
@控制器
公共类用户控制器{
@RequestMapping(method=RequestMethod.GET)
公共字符串userHome(模型模型、EventBean事件、UserService UserService、ImageBean映像)
{
List events=userService.viewNews();//从数据库检索列表
model.addAttribute(“event”,event);//添加bean对象
model.addAttribute(“事件”,events);//在模型属性中添加列表
返回“家”;
}
}
您的jsp页面

<form:form modelAttribute="event"> <!--set the model attribute here -->
        <form:input path="news" value="${events.get(0).news}" />
</form:form>

这是我的代码,请看一看,说出我可能做错了什么, 爪哇


publicmodelandview userEditProfile(@modeldattribute(“userDetails”)UserFormbean注册、bindingsult结果、HttpServletRequest请求){
ModelAndView mav=null;
HttpSession HttpSession=null;
List userProfileList=新建ArrayList();
httpSession=request.getSession();
if(httpSession!=null){
UserFormbean formbean=(UserFormbean)httpSession.getAttribute(“UserRegistrationFormBean”);
userProfileList=userRegistrationService.getUserProfileInfo(formbean);
mav=新模型和视图(“编辑配置文件”);
addObject(“userProfileInfoList”,userProfileList);
}
返回mav;
}
JSP::
-----

是的,没有区别。我尝试使用上述技术访问元素,但我遇到了一个问题,例如名称、电子邮件等字段被包装在父bean中。在这种情况下,访问这些元素的语法应该是什么?我得到这个异常“org.apache.jasper.JasperException:/WEB-INF/views/EditProfile.jsp(31,3)当未指定默认名称空间时,函数get必须与前缀一起使用”如果使用hibernate,则声明关系,即父类中的@OneToOne private Child,以便使用join检索并在value=“${list.get(0)”中设置值.child.childAttribute我这样做了,它成功了。现在有人能告诉我为什么这样做了,而上面的代码没有??
 public ModelAndView userEditProfile(@ModelAttribute("userDetails") UserFormbean  registration,BindingResult result,HttpServletRequest request){

         ModelAndView mav=null;
         HttpSession httpSession=null;
         List userProfileList=new ArrayList();
         httpSession=request.getSession();
         if (httpSession != null) {
         UserFormbean formbean=(UserFormbean)httpSession.getAttribute("UserRegistrationFormBean");
     userProfileList= userRegistrationService.getUserProfileInfo(formbean);
     mav=new ModelAndView("EditProfile");
     mav.addObject("userProfileInfoList", userProfileList); 


    }
     return mav;

    }

JSP::  
-----
 <c:if test="${not empty userProfileInfoList}">
 <c:forEach var="temp" items="${userProfileInfoList}">



        <div>
        <form:label path="userRegistration.email"><spring:message code="label.email"/></form:label>
        <form:input path ="userRegistration.email" value="${temp.get(0).UserRegistration.email}"/>
        <form:errors path="userRegistration.email"/> 
        </div>

       <div>
        <form:label path="userRegistration.firstName"><spring:message code="label.firstname"/></form:label>
        <form:input path ="userRegistration.firstName" value="${temp.get(0).UserRegistration.firstName}"/>
        <form:errors path="userRegistration.firstName"/>
      </div>


      <div>
        <form:label path="userRegistration.lastName"><spring:message code="label.lastname"/></form:label>
        <form:input path ="userRegistration.lastName" value="${temp.get(0).UserRegistration.lastName}"/>
        <form:errors path="userRegistration.lastName"/>
    </div>


    </c:forEach>
   </c:if>