在Struts2中,使用绑定select进行页面查询
2017-04-21 16:43
417 查看
使用绑定数据的select框作为查询条件进行列表查询参考小例子
1 自定义下拉框Vo对象
publicclass GameNameSelectVO {
private String id; //游戏名称ID
private String gameName; //游戏名称
public String getId() {
return id;
}
public voidsetId(String id) {
this.id = id;
}
public String getGameName() {
return gameName;
}
public voidsetGameName(String gameName) {
this.gameName = gameName;
}
}
2 Action 作为查询控制器
privateList<GameNameSelectVO> gameNameList; //页面游戏名称下拉对象集合
private String gameNameID; //游戏名称
需要提供get set方法
方法
/**
* 进入游戏参数查询页面
* @return
*/
@SuppressWarnings("unchecked")
public String toParameterPage(){
//获得省份信息
fundvo = gameInfoMonitorService.getProvinceInfo(String.valueOf(pid));
if(null == gameNameID){
gameNameID = "0";//初始查询全部
}
//获得游戏名称下拉数据集合
gameNameList = gameInfoMonitorService.getGameNameSelectList();
//得到每页记录数
PropertyUtil p = new PropertyUtil();
int pageSize = Integer.parseInt(p.getProperty("/system.properties", "account.alarm.pageSize"));
// 获得查询记录总数
int count = gameInfoMonitorService.getParameterListCount();
// 根据总记录数、每页记录数、当前页码生成分页对象
page = new Page<GameInfoPageVO>(count, pageSize, getCurrentPage());
gameInfoVOList = gameInfoMonitorService.getParameterList(gameNameID,page.getCurrentPage(),page.getPageSize());
return "parameterPage";
}
3 Impl 实现类
/**
* 获得游戏名称下拉集合
*/
public List<GameNameSelectVO>getGameNameSelectList() {
StringBuffer hql = new StringBuffer();
hql.append(" select rd.id,rd.game_name fromT_RCVD_GAME_DEFINITION rd " );
List<GameNameSelectVO> volist = new ArrayList<GameNameSelectVO>();
try{
List list = hibernateDao.queryBySql(hql.toString());
for(Iterator it =list.iterator();it.hasNext();){
Object [] objs = (Object[])it.next();
GameNameSelectVO vo = new GameNameSelectVO();
vo.setId(objs[0].toString());
vo.setGameName(objs[1].toString());
volist.add(vo);
}
}catch(Exception e){e.printStackTrace();}
return volist;
}
4 JSP页面
<div class="searchtime">
游戏名称:<select name="gameNameID" id="" style="width: 10%;" >
<option value="0">--全部--</option>
<s:iterator value="gameNameList" var="gameNameVo">
<option value="<s:property value="id"/>" <c:if test="${gameNameVo.id eq gameNameID }" >selected</c:if> > <s:property value="gameName"/></option>
</s:iterator>
</select>
<input type="submit" value="查询" class="button"/>
</div>
1 自定义下拉框Vo对象
publicclass GameNameSelectVO {
private String id; //游戏名称ID
private String gameName; //游戏名称
public String getId() {
return id;
}
public voidsetId(String id) {
this.id = id;
}
public String getGameName() {
return gameName;
}
public voidsetGameName(String gameName) {
this.gameName = gameName;
}
}
2 Action 作为查询控制器
privateList<GameNameSelectVO> gameNameList; //页面游戏名称下拉对象集合
private String gameNameID; //游戏名称
需要提供get set方法
方法
/**
* 进入游戏参数查询页面
* @return
*/
@SuppressWarnings("unchecked")
public String toParameterPage(){
//获得省份信息
fundvo = gameInfoMonitorService.getProvinceInfo(String.valueOf(pid));
if(null == gameNameID){
gameNameID = "0";//初始查询全部
}
//获得游戏名称下拉数据集合
gameNameList = gameInfoMonitorService.getGameNameSelectList();
//得到每页记录数
PropertyUtil p = new PropertyUtil();
int pageSize = Integer.parseInt(p.getProperty("/system.properties", "account.alarm.pageSize"));
// 获得查询记录总数
int count = gameInfoMonitorService.getParameterListCount();
// 根据总记录数、每页记录数、当前页码生成分页对象
page = new Page<GameInfoPageVO>(count, pageSize, getCurrentPage());
gameInfoVOList = gameInfoMonitorService.getParameterList(gameNameID,page.getCurrentPage(),page.getPageSize());
return "parameterPage";
}
3 Impl 实现类
/**
* 获得游戏名称下拉集合
*/
public List<GameNameSelectVO>getGameNameSelectList() {
StringBuffer hql = new StringBuffer();
hql.append(" select rd.id,rd.game_name fromT_RCVD_GAME_DEFINITION rd " );
List<GameNameSelectVO> volist = new ArrayList<GameNameSelectVO>();
try{
List list = hibernateDao.queryBySql(hql.toString());
for(Iterator it =list.iterator();it.hasNext();){
Object [] objs = (Object[])it.next();
GameNameSelectVO vo = new GameNameSelectVO();
vo.setId(objs[0].toString());
vo.setGameName(objs[1].toString());
volist.add(vo);
}
}catch(Exception e){e.printStackTrace();}
return volist;
}
4 JSP页面
<div class="searchtime">
游戏名称:<select name="gameNameID" id="" style="width: 10%;" >
<option value="0">--全部--</option>
<s:iterator value="gameNameList" var="gameNameVo">
<option value="<s:property value="id"/>" <c:if test="${gameNameVo.id eq gameNameID }" >selected</c:if> > <s:property value="gameName"/></option>
</s:iterator>
</select>
<input type="submit" value="查询" class="button"/>
</div>
相关文章推荐
- 使用Oracle的instr函数与索引配合提高模糊查询的效率 一般来说,在Oracle数据库中,我们对tb表的name字段进行模糊查询会采用下面两种方式: 1.select * from tb wh
- oracle的存储过程中使用变量或参数进行模糊查询(like的变量绑定)
- 对页面元素中事件进行提取,保持 ,使用完成后再进行事件绑定
- mybatis使用select语句进行关联查询
- thinkphp5里面 使用where('id',$id)->select()查询一条记录,在视图页面出错
- 使用ArcGIS for Desktop的Select by attribute进行多条件查询的问题解决
- JAVA_WEB Struts2学习:使用验证框架进行校验JSP页面元素 反编译工具的配置 Strtuts2 国际化学习
- 使用asp.net进行多关键字查询的例子
- 使用JNDI进行高级DNS查询
- 如何使用DataBinder.Eval()方法进行数据绑定
- 如何实现对页面select进行强制赋值
- 浏览ASP页面,出现的错误“操作必须使用一个可更新的查询”
- 使用ActiveReport for .net 进行报表开发(二)--绑定数据源
- .net学习_使用databinder进行数据绑定20060525
- Repeater 实现分页、自行绑定数据,对Repeater 进行镶嵌使用
- 怎么样对二个数据库表进行关联查询 (select dbo 关联)
- 对 Repeater 进行绑定 使用 DataBinder.Eval(Container.DataItem,"personname")
- 数据绑定技术—如何使用DataBinder.Eval()方法进行数据绑定
- 如果需要对DataTable进行大批量Select查询,首先为表创建DataView
- 使用自定义的数据源进行DataGrid控件的数据绑定