当前位置:网站首页>收货地址列表展示【项目 商城】
收货地址列表展示【项目 商城】
2022-06-11 10:58:00 【日星月云】
收货地址列表展示
1.持久层
规划查询SQL语句
1.数据库数据的查询操作
select * from t_address where uid=? order by is_default DESC,created_time DESC
2.接口与抽象方法
/** * 根据用户的id查询用户的收货地址数据 * @param uid 用户id * @return 收货地址数据 */
List<Address> findByUid(Integer uid);
3.在.xml文件中添加对应的SQL语句映射。
<select id="findByUid">
select * from t_address where uid=#{uid}
order by is_default DESC,created_time DESC
</select>
AddressMapper–findByUid
测试
4.完成单元测试方法。
@Test
public void findByUid(){
List<Address> list = addressMapper.findByUid(8);
System.out.println(list);
}
2.业务层
1.不用抛出相关的异常,不用进行异常的设计
2.设计业务层的接口和抽象方法
List<Address> getByUid(Integer uid);
3.需要在实现类中实现此方法的逻辑
public List<Address> getByUid(Integer uid) {
List<Address> list = addressMapper.findByUid(uid);
for (Address address : list) {
address.setAid(null);
address.setUid(null);
address.setProvinceCode(null);
address.setCityCode(null);
address.setAreaCode(null);
address.setZip(null);
address.setTel(null);
address.setIsDefault(null);
address.setCreatedUser(null);
address.setCreatedTime(null);
address.setModifiedUser(null);
address.setModifiedTime(null);
}
return list;
}
AddressService–getByUid
测试
4.单元测试暂时省略。
实现抽象方法
3.控制器
1.请求设计
/address
HttpSession
GET
JsonResult<List<Address>>
2.实现请求方法的编写
@RequestMapping({
"","/"})
public JsonResult<List<Address>> getByUid(HttpSession session){
Integer uid = getuidFromSession(session);
List<Address> data = addressService.getByUid(uid);
return new JsonResult<>(OK,data);
}
AddressController–getByUid
测试
3.先登录,再访问请求的地址进行数据的测试。
前端页面
在address.html页面中编写查询用户收货地址数据的列表展示。
// <!--showAddressList-->
$(document).ready(function () {
showAddressList();
});
function showAddressList() {
$("#address-list").empty();
$.ajax({
url: "/address",
type: "GET",
dataType: "JSON",
success: function (json) {
if (json.state==200) {
let list = json.data;
for (let i = 0; i < list.length; i++) {
console.log(list[i].name);
let tr = '<tr>'
+ '<td>#{tag}</td>'
+ '<td>#{name}</td>'
+ '<td>#{province}#{city}#{area}#{address}</td>'
+ '<td>#{phone}</td>'
+ '<td><a class="btn btn-xs btn-info"><span class="fa fa-edit"></span> 修改</a></td>'
+ '<td><a οnclick="deleteByAid(#{aid})" class="btn btn-xs add-del btn-info"><span class="fa fa-trash-o"></span> 删除</a></td>'
+ '<td><a οnclick="setDefault(#{aid})" class="btn btn-xs add-def btn-default">设为默认</a></td>'
+ '</tr>';
tr = tr.replace(/#{aid}/g, list[i].aid);
tr = tr.replace(/#{tag}/g, list[i].tag);
tr = tr.replace("#{name}", list[i].name);
tr = tr.replace("#{province}", list[i].provinceName);
tr = tr.replace("#{city}", list[i].cityName);
tr = tr.replace("#{area}", list[i].areaName);
tr = tr.replace("#{address}", list[i].address);
tr = tr.replace("#{phone}", list[i].phone);
$("#address-list").append(tr);
}
//将某个元素隐藏使用hide()
$(".add-def:eq(0)").hide();
}else{
alert("用户收货地址加载失败")
}
}
});
}
// <!--showAddressList-->
address.html–showAddressList
测试

README–收货地址列表展示
边栏推荐
- 杰理之获取 BLE 出现电压检测、ADC 检测不准【篇】
- 杰理之获取 BLE 查看代码异常复位等异常情况原因【篇】
- 恋爱时将房屋一半产权登记在女方名下,分手后想要回
- Update failed to update bytea type PostgreSQL
- International multilingual sea mall rebate product automatic matching order source code
- 找到自己的优势,才能干活不累,事半功倍!
- C language course design
- Leetcode (Sword finger offer) - 10- ii Frog jumping on steps
- Development of official account system for digital collection app applet
- 距离度量 —— 欧式距离(Euclidean Distance)
猜你喜欢

An introduction to creating VOC datasets or Yolo datasets using labelimg

SurroundDepth:自监督多摄像头环视深度估计

Using domestic MCU (national technology n32g031f8s7) to realize pwm+dma control ws2812

Application of volatile in single chip microcomputer

Store management skills: how to manage chain stores efficiently?

使用Labelimg制作VOC数据集或yolo数据集的入门方法

Shi Yigong: I was not interested in research until I graduated from my doctor's degree! I'm confused about the future, and I don't know what to do in the future

杰理之获取 BLE 查看代码异常复位等异常情况原因【篇】

Iterator mode -- battlefield autumn point

想做钢铁侠?听说很多大佬都是用它入门的
随机推荐
[games101] operation 2 -- triangle rasterization
MySQL下载安装使用-完整详细步骤
C language course design
Why does a ddrx power supply design require a VTT power supply
使用Yolov3训练自己制作数据集,快速上手
Campus lost and found applet source code can be used for graduation design
Where is it safer to open an account for soda ash futures? How much capital is needed to buy soda ash futures?
Electron desktop development (development of an alarm clock [End])
Yibentong 1122: calculating saddle point
Leetcode (Sword finger offer) - 10- ii Frog jumping on steps
Inventory of the 9 most famous work task management software at home and abroad
Typeerror: argument of type "Int 'is not Iterable
国际多语言出海商城返佣产品自动匹配订单源码
小白在同花顺上直接开户是安全的吗?
数据库系统概论 ---- 第二章 -- 关系数据库(2.4 关系代数)
Unity font spacing
命令模式--进攻,秘密武器
Cloud image quality assistant IAPP source code
Half of the property rights of the house are registered in the woman's name when they are in love, and they want to return after they break up
Implementing declarative rest calls using feign