2018年04月18日 09:59:31 achang编程 阅读数:872
4.页面:把json数据显示到省列表中
//显示省列表信息
function getProrvinces(){
$.ajax({
"url":"${pageContext.request.contextPath}/dict/showProvince.do",
"data":"",
"type":"GET",
"dataType":"json",
"success":function(obj){
$("#receiverState").html("---请选择---");
for(i=0;i
$("#receiverState").append
("");
}
}
});
}
1.持久层 首先在bean中创建City类;在DictMapper接口定义方法
List selectCity(String provinceCode);
在DictMapper.xml映射文件,定义select
节点,完成查询城市信息的功能
select
id,
province_code as provinceCode,
city_code as cityCode,
city_name as cityName
from
t_dict_cities
where
province_code = #{provinceCode}
测试:
2.显示城市信息-业务层 在IDictService接口中定义方法
List getCity(String provinceCode);
在DictService类中实现方法,返回持久层的集合
3.显示城市信息-控制器层 请求的url
/dict/showCity.do
请求参数:provinceCode
请求方式:GET
响应方式:ResponseBody
@
@
public ResponseResult
> showCity(String provinceCode){
1.创建rr对象
2.调用业务层方法,放回list
3.把list数据设置到rr对象中
4.return rr
}
测试:
4.显示城市信息-页面
onchange=getCities(this.value);
function getCities(provinceCode){
$.ajax({
"url":"${pageContext.request.contextPath}/dict/showCity.do",
"data":"provinceCode="+provinceCode,
"type":"GET",
"dataType":"json",
"success":function(obj){
$("#receiverCity").html("");
for(i = 0;i
$("#receiverCity").append("");
}
}
});
}
1.持久层 在bean包中,创建Area类;在DictMapper接口中定义方法
List selectArea(String cityCode);
在DictMapper.xml中,定select
节点
select
xx
from
t_dict_areas
where
city_code = #{cityCode}
2.业务层 在IDictService 接口中定义方法
List getArea(String cityCode);
在DictService类中实现该方法,返回持久层的集合
3.控制器层
/dict/showArea.do
请求参数:cityCode
请求方式:GET
响应方式:ResponseBody
@
@
public ResponseResult
> showArea(String cityCode){
1.创建rr对象
2.调用业务层方法,返回list
3.把集合设置到rr对象中
4.return rr;
}
4.页面
function getAreas(cityCode){
}
省市区函数的调整
getProvinces(provinceCode,cityCode,areaCode);
getCities(provinceCode,cityCode,areaCode);
getAreas(cityCode,areaCode)
getProrvinces(-1,-1,-1);
在select中修改函数的参数
onchange=getCities(this.value,-1,-1);
onchange="getAreas(this.value,-1)
分别在getProvinces()函数的ajax异步提交完成调用 getCities(this.value,-1,-1),getCyties()函数的ajax异步提交完成调用getAreas(this.value,-1)
页面调整:
//所有的dd隐藏
$("#leftsidebar_box dd").hide();
//让账号管理显示
$("#leftsidebar_box .address dd").show();
//所有的自定义列表的标题后边的图片 myOrder2.png
$("#leftsidebar_box dt img").attr("src","../images/myOrder/myOrder2.png");
//设置账号管理的图片和其他的三个不相同 $("#leftsidebar_box .address").find('img').attr("src","../images/myOrder/myOrder1.png");
注意: 在DictMapper接口中定义3个方法,获取省市区名字的方法
String selectProvinceNameByCode(String provinceCode);
String selectCityNameByCode(String cityCode);
String selectAreaNameByCode(String areaCode);
在DictMapper.xml中定义3个节点,分别完成查询省市区名字的功能
select
province_name as provinceName
from
t_dict_provinces
where
province_code=#{provinceCode}
测试:
城市和区县的select语句同上
给taddress添加isdefault;添加列的语句:alter table taddress add isdefault int(1);
首先在bean包创建Address类;然后在mapper 包中创建AddressMapper接口,在接口定义方法:
void insert(Address address);
新建AddressMapper.xml文件(拷贝*.xml文件,改名) 定义insert
节点,插入地址信息
insert into t_address(
id,uid,recv_name,
recv_province,
recv_city,recv_area,
recv_district,
recv_address,recv_phone,
recv_tel,recv_zip,
recv_tag,is_default,
created_user,created_time,
modified_user,modified_time
) values(
#{id},#{uid},#{recvName},
#{recvProvince},
#{recvCity},#{recvArea},
#{recvDistrict},
#{recvAddress},#{recvPhone},
#{recvTel},#{recv_zip},
#{recvTag},#{isDefault},
#{createdUser},#{createdTime},
#{modifiedUser},#{modifiedTime}
)
测试:
".."> select id,uid,recv_name as recvName, recv_province as recvProvince, recv_city as recvCity, recv_area as recvArea, recv_district as recvDistrict, recv_address as recvAddress, recv_phone as recvPhone, recv_tel as recvTel, recv_zip as recvZip, recv_tag as recvTag, is_default as isDefault, created_user as createdUser, created_time as createdTime, modified_user as modifiedUser, modified_time as modieidTime from t_address where uid=#{uid}
测试: