SSH---------------动态下拉框(1、仅easyui代码,2、easyui+java)

1、 仅easyui代码

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/js/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/js/themes/icon.css">
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.8.0.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.easyui.min.js"></script>

    <link rel="stylesheet" href="${pageContext.request.contextPath}/js/ztree3.5/zTreeStyle.css" type="text/css">
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/js/ztree3.5/jquery.ztree.all-3.5.js"></script>
</head>
<body  >

<input class="easyui-combobox" id="language" name="language"
       data-options="valueField:'id',textField:'text',url:'${pageContext.request.contextPath}/demo/combobox_data1.json'" >
</body>
</html>

2、easyui+java

jsp:

<tr>
   <td>选择区域</td>
   <td>
      <input class="easyui-combobox" name="region.id"  
                  data-options="valueField:'id',textField:'name',url:'${pageContext.request.contextPath}/region_selectregion.action'" />
   </td>
</tr>

action:

public void selectregion() throws IOException {
    List<Region> regionList=iRegionService.findAll();
    RespJson(regionList,new String[]{});    //基类方法
}

基类:

protected  void RespJson(Object o,  String[] strs) throws IOException {
    JsonConfig jsonConfig = new JsonConfig();
    jsonConfig.setExcludes(strs);
    HttpServletResponse httpServletResponse = ServletActionContext.getResponse();
    httpServletResponse.setHeader("content-type", "text/json;charset=utf-8");
    if(o instanceof Collection){   //是否是集合
        JSONArray jsonObject=JSONArray.fromObject(o, jsonConfig);
        httpServletResponse.getWriter().write(jsonObject.toString());
    }else{
        JSONObject jsonObject = JSONObject.fromObject(o, jsonConfig);
        httpServletResponse.getWriter().write(jsonObject.toString());
    }
}

在Region中无name属性,新加入getName方法,json中的标题字段,仅仅是get方法中的字段

package com.dong.bos.model;
import java.util.Objects;

public class Region {
    private String id;
    private String province;
    private String city;
    private String district;
    private String postcode;
    private String shortcode;
    private String citycode;
    public String getName() {
        return province+city+district;
    }
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getProvince() {
        return province;
    }

    public void setProvince(String province) {
        this.province = province;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getDistrict() {
        return district;
    }

    public void setDistrict(String district) {
        this.district = district;
    }

    public String getPostcode() {
        return postcode;
    }

    public void setPostcode(String postcode) {
        this.postcode = postcode;
    }

    public String getShortcode() {
        return shortcode;
    }

    public void setShortcode(String shortcode) {
        this.shortcode = shortcode;
    }

    public String getCitycode() {
        return citycode;
    }

    public void setCitycode(String citycode) {
        this.citycode = citycode;
    }

    public Region() {
    }

    public Region(String id, String province, String city, String district, String postcode, String shortcode, String citycode) {
        this.id = id;
        this.province = province;
        this.city = city;
        this.district = district;
        this.postcode = postcode;
        this.shortcode = shortcode;
        this.citycode = citycode;
    }

    @Override
    public String toString() {
        return "Region{" +
                "id='" + id + '\'' +
                ", province='" + province + '\'' +
                ", city='" + city + '\'' +
                ", district='" + district + '\'' +
                ", postcode='" + postcode + '\'' +
                ", shortcode='" + shortcode + '\'' +
                ", citycode='" + citycode + '\'' +
                '}';
    }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值