当前位置: 代码迷 >> Web前端 >> select 取舍查询
  详细解决方案

select 取舍查询

热度:150   发布时间:2012-09-11 10:49:03.0
select 选择查询

??? 有时候我们经常遇到数据库的值是0或1的数据,但是要用select表示出来的是用中文。我就遇到过这样的问题,现在解决了,分享给大家。

?这是一个静态的常量类

?public static final String ISRECOMMEND = "1"; //1:推荐,0:未推荐
??? ?public static final String DISRECOMMEND = "0";//1:推荐,0:未推荐
??? ?public static final String HZISRECOMMEND = "已推荐";
??? public static final String HZDISRECOMMEND = "未推荐";
??? public static? HashMap<String, String>? isRecommendmap = new HashMap<String, String>();
??? static{
??? ??? isRecommendmap.put(ISRECOMMEND, HZISRECOMMEND);
??? ??? isRecommendmap.put(DISRECOMMEND, HZDISRECOMMEND);
??? ???
??? }

用静态块把键值存放在map里面

?

action**********

?

private String hzisrecommend=SystemParams.HZISRECOMMEND;
?private String hzdisrecommend=SystemParams.HZDISRECOMMEND;

private String isRecommend;

在此省略get set 方法。。。

?

取map里面的值? 这是通过一个display做的分页查询

?SystemParams.isRecommendmap.get(hzisrecommend);
??? ??? ??? ??? ?SystemParams.isRecommendmap.get(hzdisrecommend);
??? ??? ??? ??? getRequest().setAttribute("map", SystemParams.isRecommendmap);

if (!StringUtils.isBlank(isRecommend)) {
??? ??? ??? ??? ??? ?
??? ??? ??? ??? ??? isRecommend = URLEncoderHZ.decode(isRecommend);
??? ??? ??? ??? ??? pageRequest.getFilters().put("isRecommend", isRecommend);
??? ??? ??? ??? }

jsp***********

?

<s:select cssClass="STYLE10" name="isRecommend" list="#request.map" listKey="key"
??? ??? ??? ??? ??? ??? ???????? listValue="value" headerKey="" headerValue="请选择" ></s:select>

?

  相关解决方案