在struts2中从数据库填充选择列表 [英] Populate select list from database in struts2

查看:33
本文介绍了在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)"/>

这篇关于在struts2中从数据库填充选择列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆