• JSP下拉选框,级联选择


    前端:

    <%@ page contentType="text/html;charset=UTF-8" %>
        
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <%@ include file="/WEB-INF/views/include/taglib.jsp"%>
    <%@ include file="/WEB-INF/views/include/head.jsp"%>
    <title>Insert title here</title>
    <script type="text/javascript">
    //获取查重内容列表
    function getnext(tablename) {
        
        if(tablename!=""){
            $.ajax({
                type: "post",
                url: "${ctx}/home/findfields",
                data: {tablename:tablename,dbname:'jk'},
                success: function(data){
                    //alert(data);
                    debugger;
                    $('#fieldSelect').empty();
                    $('#fieldSelect').append('<option value="" >选择查重字段</option>');
                    $.each(data, function (i, item) {  
                        //alert(item.id + ","  + item.name);  
                        var v=item.fieldname;
                        var c=item.fieldcomment;
                        $('#fieldSelect').append('<option value="'+v+'" >'+c+'</option>');
                    });
                    
                    
                }
             });
        }
        
    }
    $(function($) {
          // 你可以在这里继续使用$作为别名...
          $('#tableSelect').change(function(){ 
              var p1=$(this).children('option:selected').val();//这就是selected的值 
              getnext(p1);
             
              }) 
        });
    </script>
    </head>
    <body>
    <div class="container" style="margin:200px;">
    <table class="table">
    <tbody>
    <tr>
    <td></td>
    <td>
    查重项目
    </td>
    <td>
    查重字段
    </td>
    <td></td><td></td><td></td>
    </tr>
    <tr>
    <td></td><td></td><td></td><td></td><td></td><td></td>
    </tr>
    <tr>
    <td></td>
    <td>
    <select name="tableSelect" id="tableSelect">
                       <option value="" >选择查重项目</option>        
                    <c:forEach var="item" items="${dataList}" >
                       <option value="${item.tablename}" >${item.tablecomment} </option>                                
                    </c:forEach>
                 </select>
    </td>
    <td>
    <select name="fieldSelect" id="fieldSelect">
                       <option value="" >选择查重字段</option>        
                    <c:forEach var="item" items="${fieldList}" >
                       <option value="${item.fieldname}" >${item.fieldcomment} </option>                                
                    </c:forEach>
                 </select>
    </td>
    <td></td><td></td><td></td>
    </tr>
    <tr>
    <td></td><td></td><td></td><td></td><td></td><td></td>
    </tr>
    </tbody>
    </table>
    
                 </div>
    </body>
    </html>

    后端:

    package com.wbh.wbhsq.web;
    
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.Model;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestParam;
    
    import org.springframework.web.bind.annotation.ResponseBody;
    import org.springframework.web.servlet.ModelAndView;
    
    import com.wbh.wbhsq.entity.SqData;
    import com.wbh.wbhsq.service.SqdataService;
    
    
    
    @Controller
    @RequestMapping(value = "${adminPath}/home")
    public class HomeController extends BaseController {
    	
    	@Autowired
    	private SqdataService  sqdataService;
    	
    	@RequestMapping(value = {"view"})
    	public String view(@RequestParam(required=true) String loadCode)
    	{
    	  
    		return "wbhsq/home";
    	}
    	
    	@RequestMapping(value="getList")
    	public ModelAndView getList(ModelAndView  model) throws Exception{
    	    List<SqData> list=sqdataService.findAll();
    	    model.addObject("dataList", list);
    		model.setViewName("wbhsq/getList");
    		return model;	
    	}
    	
    	@RequestMapping(value="setsql")
    	public ModelAndView setsql(ModelAndView  model) throws Exception{
    	    List<SqData> list=sqdataService.findAllTable();
    	    model.addObject("dataList", list);
    	    list=sqdataService.findAll();
    	    model.addObject("fieldList", list);
    		model.setViewName("wbhsq/setsql");
    		return model;	
    	}
    	
    	/**
    	 * 获取字段列表
    	 * 2015年12月27日
    	 * By hoge
    	 * @param model
    	 * @param rid
    	 * @return
    	 */
    	@RequestMapping(value = {"findfields"})
    	public  @ResponseBody List<SqData> findfields(Model model,String tablename) {
    		Map<String,Object> filter = new HashMap<String, Object>();
    		filter.put("tablename", tablename);
    		List<SqData> fieldList = sqdataService.query(filter);
    		return fieldList;
    	}
    	
    }
    

      

  • 相关阅读:
    在不是modelAttribute的情况下,如何保存页面输入值的方法(多行遍历)
    关于Hibernate中No row with the given identifier exists问题的原因及解决
    Oracle中exit,return,continue
    如何将表的行数赋值给变量(MySQL)
    论MySQL中如何代替Oracle中select into new_table from old_table
    有关linux下redis overcommit_memory的问题,有需要的朋友可以参考下。
    CentOS 6.6 中 mysql_5.6 主从数据库配置
    CentOS 6.6 中jdk1.6的安装和配置方法
    解决 Amoeba连接mysql出错 解决方案
    Linux系统memcached安装
  • 原文地址:https://www.cnblogs.com/hoge/p/5080125.html
Copyright © 2020-2023  润新知