省市区三级级联,含有数据库.单一外键模式.

1.最重要的是js部分.其他的数据库使用Oralce10g,MyEclipse8.6,tomcat6.x可.
2. 本身整个文件 16M>10M无法全部上传,所以学会抽出对自己有用的部分
MarketAction.java

package com.action;

import java.util.Date;
import java.util.List;
import java.util.Map;
import com.entity.Market;
import com.biz.MarketBiz;
import com.entity.Province;
import com.biz.ProvinceBiz;
import java.util.ArrayList;
import java.io.UnsupportedEncodingException;

import net.sf.json.JSONArray;
import net.sf.json.JsonConfig;

/**
* ********************************************************
* @ClassName: MarketAction
* @Description: 市级表
* @author 生成Action类
* @date 2014-08-28 下午 09:32:26
*******************************************************
*/
public class MarketAction {

private MarketBiz marketbiz;

private Market market = new Market();

private List<Market> marketlist = new ArrayList<Market>();

private List<Province> provincelist = new ArrayList<Province>();

private JSONArray jsons;

private Integer id;

/**
*
*添加表<Market>信息
*
**/
public String addMarket(){
Integer results = marketbiz.addMarket(market);
if (results > 0 ) {
return "successs";
}else {
return "error";
}
}

/**
*
*查询表<Market>所有信息
*
**/
public String getAllMarket(){
marketlist = marketbiz.getAllMarket();
if (marketlist.size() > 0 ) {
return "success";
}else {
return "error";
}
}

/**
*
*根据@id查询表<Market>信息
*
**/
public String getMarket_id(){
market.setProvince_id(id);
marketlist = marketbiz.getMarket_id(market);
if (marketlist.size() > 0 ) {
JsonConfig config = new JsonConfig();
config.setExcludes(new String[]{"county"});
jsons = JSONArray.fromObject(marketlist,config);
return "edit";
}else {
return "error";
}
}

/**
*
*根据@id修改表<Market>信息
*
**/
public String updaMarket_id(){
try {

marketbiz.updaMarket_id(market);
} catch (Exception e) {
// TODO: handle exception
return "error";
}
return "successs";
}

/**
*
*根据@id删除表<Market>信息
*
**/
public String deleMarket(){
try {
marketbiz.deleMarket(market);
} catch (Exception e) {
// TODO: handle exception
return "error";
}
return "successs";
}

/**
*
*查询关联表<Province>信息
*
**/
public String reAllProvince(){
provincelist = marketbiz.reAllProvince();
if (provincelist.size() > 0 ) {
return "relist";
}else {
return "error";
}
}

public Market getMarket() {
return market;
}
public void setMarket(Market market) {
this.market = market;
}
public List<Province> getProvincelist() {
return provincelist;
}
public void setProvincelist(List<Province> provincelist) {
this.provincelist = provincelist;
}
public List<Market> getMarketlist() {
return marketlist;
}
public void setMarketlist(List<Market> marketlist) {
this.marketlist = marketlist;
}
public void setMarketbiz(MarketBiz marketbiz) {
this.marketbiz = marketbiz;
}

public JSONArray getJsons() {
return jsons;
}

public void setJsons(JSONArray jsons) {
this.jsons = jsons;
}

public Integer getId() {
return id;
}

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

}



jilian.js

function changes(obj,selectid,url){ //当前对象,选中的id,url路径.
var id = "#"+selectid;
if($(obj).val() != 0){
$.ajax({type:"post",url:url,dataType:"json",
data:{"id":$(obj).val()},//简写:TUDD.
success:function(data){
$(id).html("");
$.each(data,function(i,item){
if(selectid == "shi"){
$(id).append("<option value="+item.market_id+">"+item.market_name+"</option>");
}
if(selectid == "xian"){
$(id).append("<option value="+item.county_id+">"+item.county_name+"</option>");
}
});
if(selectid == "shi"){ // 如果下一个是市,就加上请选择市.
$(id).attr("disabled",false);
$(id).append("<option value='0' selected='selected'>---请选择市/区---</option>");
$.each($("select"),function(i,item){
if(i >= $(id).index()){
i++;
$("select:eq("+i+")").attr("disabled",true);//改变select不可用
$("select:eq("+i+")").val(0);
}
})

}
if(selectid == "xian"){ //同上
$(id).attr("disabled",false);
$(id).append("<option value='0' selected='selected'>---请选择县/区---</option>");
}
}
});
}else if(selectid == "shi" || selectid == "xian"){ //如果当前选择项是 请选择,那么下个就也是请选择,
//且不可用-
$.each($("select"),function(i,item){
if(i >= $(id).index()){
$(item).attr("disabled",true);
$(item).val(0);
}
})
}
}

页面部分:list.jsp

<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>县级表总览</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

</head>

<body>
<table align="center" border="1">
<caption style="color:red;"><a href="index.jsp">Url控制</a></caption>
<tr align="center">
<td>市级id(外键)</td>
<td>县级id</td>
<td>县级名称</td>
<td>操作</td>
</tr>
<s:iterator value="countylist" status="s" var="li">
<tr align="center" <s:if test="%{#s.index % 2 == 0}">style="background-color:red;"</s:if>>
<td><s:property value="%{#li.market_id.market_id}"/></td>
<td><s:property value="%{#li.county_id}"/></td>
<td><s:property value="%{#li.county_name}"/></td>
<td>
<a href="countyreAllMarket.action">添加</a>
<a href="countygetCounty_id.action?county.county_id=<s:property value="%{#li.county_id}"/>">修改</a>
<a href="javascript:confirmdel(<s:property value="%{#li.county_id}"/>)">删除</a>
</td>
</tr>
</s:iterator>
</table>

<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript">
function confirmdel(id){
if(confirm("确定要删除么")){
location.href="countydeleCounty.action?county.county_id="+id;
}
}
</script>
</body>
</html>

struts-contor.xml

<?xml version="1.0" encoding="GBK" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<constant name="struts.devMode" value="false"/>
<constant name="struts.i18n.encoding" value="GBK"></constant>
<constant name="struts.ui.theme" value="simple"></constant>
<constant name="struts.enable.DymicMethodInvocation" value="false"/>
<package name="default" namespace="/" extends="json-default">

<!-- 表<Market> <MarketAction> 配置 -->
<action name="market*" class="MarketAction" method="{1}">
<result name="relist">Market/save.jsp</result>
<result name="success">Market/list.jsp</result>
<result name="successs" type="redirectAction">marketgetAllMarket.action</result>
<result name="edit" type="json">
<param name="root">jsons</param>
</result>
<result name="error">Market/error.jsp</result>
</action>

<!-- 表<Province> <ProvinceAction> 配置 -->
<action name="province*" class="ProvinceAction" method="{1}">
<result name="success">MyJsp.jsp</result>
<result name="successs" type="redirectAction">provincegetAllProvince.action</result>
<result name="edit">Province/update.jsp</result>
<result name="error">Province/error.jsp</result>
</action>

<!-- 表<County> <CountyAction> 配置 -->
<action name="county*" class="CountyAction" method="{1}">
<result name="relist">County/save.jsp</result>
<result name="success">County/list.jsp</result>
<result name="successs" type="redirectAction">countygetAllCounty.action</result>
<result name="edit" type="json">
<param name="root">jsons</param>
</result>
<result name="error">County/error.jsp</result>
</action>

</package>
</struts>


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值