码迷,mamicode.com
首页 > Web开发 > 详细

JSP下拉选框,级联选择

时间:2015-12-27 16:14:39      阅读:135      评论:0      收藏:0      [点我收藏+]

标签:

前端:

<%@ 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;
	}
	
}

  

JSP下拉选框,级联选择

标签:

原文地址:http://www.cnblogs.com/hoge/p/5080125.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!