在struts2中从数据库填充选择列表

问题描述:

我是 Struts2 的新手,并需要帮助来填充 struts2 中的选择列表.有一个简单的注册表单,其中需要从数据库中填写选择列表,比如用户名列表.我使用以下格式:

I am new to Struts2, and need assistance to populate select list in struts2. Have simple registration form in which need to fill select list from database say user name list. I use below format :

<s:select name="username" label="Username" headerKey="-1" headerValue="Select Search Engines" list="%{#{'value':'front','value1':'front1'}}" theme="simple" onchange="getData(this.value)"/>

但是如何从数据库中填充呢?

But how to fill it from database?

您将从数据库中获得满足某些条件的对象列表.

From the database you would get a list of objects that satisfy some criteria.

List<Engine> engines = enginDAO.getEngines();
//getter and setter here

现在您必须将 engines 填充到列表中.

Now you have to populate engines to the list.

<s:select name="username" label="Username" headerKey="-1" headerValue="Select Search Engines" list="%{engines}" listKey="id" listValue="name" theme="simple" onchange="getData(this.value)"/>