EasyUI combobox 动态下拉列表

1.通过<select>元素创建一个预定义结构的下拉列表框。

           <div style="margin-bottom: 10px">
                <label for="accept" class="textbox-label">上级组织名称</label>
                    <select id="cc2"
                    class="easyui-combobox" name="parent" style="400px;" //这里的name  一定是保存的实体类的名字一样。
                     data-options="panelHeight:70">
                </select>  
            </div>

2.使用Javascript创建下拉列表框。

$("#cc2").combobox ({
            editable : false,
            url : "/org/getOrgName ",//url
            valueField : "id", //相当于 option 中的 value 发送到后台的
            textField : "orgName"//option中间的内容 显示给用户看的
        });
       

后台数据:

1.创建一个vo

package com.xintouyun.duchaban.bean;

public interface GetOrgNameVo {
    String getId();
    String getOrgName();//组织名

}

2.repo层

package com.xintouyun.duchaban.repo;

import java.io.Serializable;
import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;


import com.xintouyun.duchaban.bean.GetOrgNameVo;


import com.xintouyun.duchaban.entity.SysOrg;

public interface SysOrgRepo extends JpaRepository<SysOrg, Serializable> {

    @Query(value = " from SysOrg  ")
    List<GetOrgNameVo> findByid();

}

3.service 层

package com.xintouyun.duchaban.service;

import java.util.List;

import com.xintouyun.duchaban.bean.GetOrgNameVo;

public interface SysOrgService {
        
        List<GetOrgNameVo> getOrgName();

}

4.serviceImpl 层

package com.xintouyun.duchaban.service.impl;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.xintouyun.duchaban.bean.GetOrgNameVo;
import com.xintouyun.duchaban.bean.SysOrgVo;

import com.xintouyun.duchaban.repo.SysOrgRepo;

import com.xintouyun.duchaban.service.SysOrgService;

@Service
@Transactional
public class SysOrgServiceImpl implements SysOrgService {

    @Autowired
    private SysOrgRepo orgRepo;
    
 
    @Override
public List<GetOrgNameVo> getOrgName() {
    
    return orgRepo.findByid();
}




}

5. controller 层

package com.xintouyun.duchaban.controller;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.xintouyun.duchaban.bean.GetOrgNameVo;
import com.xintouyun.duchaban.service.SysOrgService;

@Controller
@RequestMapping("/org")

public class SysOrgController {
    @Autowired
    private SysOrgService OrgService;
   

    @PostMapping("/getOrgName")
    @ResponseBody
    public  List<GetOrgNameVo> getOrgName(){
         return OrgService.getOrgName();
    
    }

原文地址:https://www.cnblogs.com/xiaoqiuliang/p/9555072.html