京淘day05-京淘项目前端js展现

虚树苔藓
• 阅读 1030

1.京淘后台页面分析(了解)

1.1 页面结构

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="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">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="/js/jquery-easyui-1.4.1/themes/default/easyui.css" />
<link rel="stylesheet" type="text/css" href="/js/jquery-easyui-1.4.1/themes/icon.css" />
<link rel="stylesheet" type="text/css" href="/css/jt.css" />
<script type="text/javascript" src="/js/jquery-easyui-1.4.1/jquery.min.js"></script>
<script type="text/javascript" src="/js/jquery-easyui-1.4.1/jquery.easyui.min.js"></script>
<script type="text/javascript" src="/js/jquery-easyui-1.4.1/locale/easyui-lang-zh_CN.js"></script>
</head>
<body class="easyui-layout">
  <div data-options="region:'west',title:'菜单',split:true" style="width:10%;">
           <ul class="easyui-tree">
               <li>
               <span>商品管理</span>
               <ul>
               <li><a onclick="addTab('商品新增','/item-add')">商品新增</a></li>
               <li><a onclick="addTab('商品查询','/item-list')">商品查询</a></li>
               <li><a onclick="addTab('商品更新','/item-update')">商品更新</a></li>
               </ul>
            </li>
            <li>
               <span>网站内容管理</span>
               <ul>
               <li>内容新增</li>
               <li>内容修改</li>
               </ul>
            </li>
           </ul>
   </div>
   <div id="tt" class="easyui-tabs" data-options="region:'center',title:'首页'"></div>
</body>
<script type="text/javascript">
function addTab(title, url){  
    if ($('#tt').tabs('exists', title)){
        $('#tt').tabs('select', title);
    } else {
        var url2 = "https://map.baidu.com/@12964432.517776728,4826375.366248961,13z";
        var content = '<iframe scrolling="auto" frameborder="0"  src="'+url2+'" style="width:100%;height:100%;"></iframe>';
        $('#tt').tabs('add',{
            title:title,  
            content:content,  
            closable:false
        });  
    }
}
</script>
</html>

2.商品列表展现

2.1 Item表分析

京淘day05-京淘项目前端js展现

2.2 JSON说明

2.2.1 什么是JSON

JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式。它使得人们很容易的进行阅读和编写。同时也方便了机器进行解析和生成。 JSON本质是String

2.2.2 Object格式

京淘day05-京淘项目前端js展现

2.2.3 Array格式

京淘day05-京淘项目前端js展现

2.2.4 嵌套格式

京淘day05-京淘项目前端js展现
例如:

//1.object格式
{id:1,name:"tomcat猫"...}
//2.array格式
[1,2,3,"打游戏","写代码"]
//3.嵌套格式  value可以嵌套   四层嵌套json
{"id":1,"name":"哈利波特","hobbys":["敲代码","学魔法","喜欢赫敏","打伏地魔"],
"method":[{"type":"火系","name":"三味真火"},{"type":"水系","name":"大海无量"}]}

2.3 表格数据展现

2.3.1 JSON结构

京淘day05-京淘项目前端js展现

2.3.2 编辑EasyUITable VO对象

说明: 对象转化为JSON 调用的是get方法. JSON转护为对象时调用set方法

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import java.util.List;
@Data
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
public class EasyUITable {
    private Long total;    //记录总数
 private List<Item> rows;//每页的记录
}

2.3.3 表格页面分析

说明:当添加了分页插件之后,当ajax程序解析时会动态的拼接参数.
京淘day05-京淘项目前端js展现

2.3.4 编辑ItemController

package com.jt.controller;
import com.jt.pojo.Item;
import com.jt.vo.EasyUITable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.jt.service.ItemService;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;
@RestController    //表示返回数据都是JSON
@RequestMapping("/item")
public class ItemController {
    @Autowired
    private ItemService itemService;
    /**
     * 业务: 分页查询商品信息.
     * url:  http://localhost:8091/item/query?page=1&rows=20
     * 参数: page=1 页数  &rows=20  行数
     * 返回值: EasyUITable
     */
    @RequestMapping("/query")
    public EasyUITable findItemByPage(int page,int rows){
        return itemService.findItemByPage(page,rows);
    }
}

2.3.4 编辑ItemService

package com.jt.service;
import com.jt.pojo.Item;
import com.jt.vo.EasyUITable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.jt.mapper.ItemMapper;
import java.util.List;
@Service
public class ItemServiceImpl implements ItemService {

    @Autowired
    private ItemMapper itemMapper;
    /**
     * 分页Sql:
     *         查询第一页:
     *             select * from tb_item limit 起始位置,查询条数
     *                select * from tb_item limit 0,20    共21个数  index[0,19]
     *            查询第二页:
     *                select * from tb_item limit 20,20    index[20,3
     *          查询第N页:
     *      *          select * from tb_item limit (page-1)rows,20
     * @param page
     * @param rows
     * @return
     */
    @Override
    public EasyUITable findItemByPage(int page, int rows) {
        long total = itemMapper.selectCount(null);
        //1.手写分页
        int startIndex = (page - 1) * rows;
        List<Item> itemList = itemMapper.findItemByPage(startIndex,rows);
        return new EasyUITable(total, itemList);
    }
}

2.3.5 编辑ItemMapper

public interface ItemMapper extends BaseMapper<Item>{
    @Select("select * from tb_item order by updated desc limit #{startIndex},#{rows}")
    List<Item> findItemByPage(int startIndex, int rows);
}

2.3.6 页面效果展现

京淘day05-京淘项目前端js展现

2.4 MybatisPlus实现分页

2.4.1 编辑ItemService

package com.jt.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jt.pojo.Item;
import com.jt.vo.EasyUITable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.jt.mapper.ItemMapper;
import java.util.List;
@Service
public class ItemServiceImpl implements ItemService {
    @Autowired
    private ItemMapper itemMapper;
        //2.利用MP方式实现分页
        IPage mpPage = new Page(page,rows);
        QueryWrapper<Item> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("updated");
        mpPage = itemMapper.selectPage(mpPage,queryWrapper);
        long total = mpPage.getTotal();    //获取记录总数
        List<Item> itemList = mpPage.getRecords();    //获取查询当前页
        return new EasyUITable(total, itemList);
    }
}

2.4.2 添加配置了类

package com.jt.config;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration   //bean标签使用
public class MybatisPlusConfig {
    //将分页拦截器交了Spring容器管理 MP是Mybatis的增强工具
    @Bean
    public PaginationInterceptor paginationInterceptor(){
        return new PaginationInterceptor();
    }
}

2.5 数据格式化说明

2.5.1 格式化价格

1.页面JS说明

<th data-options="field:'price',width:70,align:'right',formatter:KindEditorUtil.formatPrice">价格</th> 

2.格式化代码
京淘day05-京淘项目前端js展现

2.5.2 格式化状态

1).页面JS

<th data-options="field:'status',width:60,align:'center',formatter:KindEditorUtil.formatItemStatus">状态</th>

2).JS分析
京淘day05-京淘项目前端js展现

2.6 实现商品分类回显

2.6.1 业务需求

说明:当用户展现列表数据时,要求将商品分类信息,进行展现.根据cid返回商品分类的名称
京淘day05-京淘项目前端js展现

2.6.2 编辑item-list页面

京淘day05-京淘项目前端js展现

2.6.3 编辑页面JS

编辑 js/common.js
京淘day05-京淘项目前端js展现

2.6.4 编辑ItemCat POJO对象

在jt-common中添加Itemcat POJO对象

package com.jt.pojo;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.experimental.Accessors;
@TableName("tb_item_cat")
@Data
@Accessors(chain = true)
public class ItemCat extends BasePojo{
    @TableId(type = IdType.AUTO)
    private Long id;        //主键
    private Long parentId;  //父级ID
    private String name;    //名称
    private Integer status; //状态信息
    private Integer sortOrder;  //排序号
    private Boolean isParent;   //是否为父级
}

2.6.5 页面URL分析

京淘day05-京淘项目前端js展现

2.6.6 编辑ItemCatController

package com.jt.controller;
import com.jt.pojo.ItemCat;
import com.jt.service.ItemCatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/item/cat")
public class ItemCatController {
    @Autowired
    private ItemCatService itemCatService;
    /**
     * 需求: 根据itemCatId查询商品分类名称
     * url:  http://localhost:8091/item/cat/queryItemName?itemCatId=163
     * 参数: itemCatId=163
     * 返回值: 商品分类名称
     */
    @RequestMapping("/queryItemName")
    public String queryItemName(Long itemCatId){
        ItemCat itemCat = itemCatService.findItemCatById(itemCatId);
        return itemCat.getName();
    }
}

2.6.7 编辑ItemCatService

package com.jt.service;
import com.jt.mapper.ItemCatMapper;
import com.jt.pojo.ItemCat;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class ItemCatServiceImpl implements ItemCatService{
    @Autowired
    private ItemCatMapper itemCatMapper;
    @Override
    public ItemCat findItemCatById(Long itemCatId) {
        return itemCatMapper.selectById(itemCatId);
    }
}

2.6.8 页面效果展现

京淘day05-京淘项目前端js展现

2.6.9Ajax嵌套问题

说明: 由于页面中发起2次ajax请求,并且2次Ajax是一种嵌套的关系.
解决方案: 如果遇到ajax嵌套问题 则一般将内部ajax设置为同步状态即可.
扩展知识: JS中闭包概念

3 树形结构展现

3.1 common.js的依赖问题

1.在index.jsp中引入了其他页面

<jsp:include page="/commons/common-js.jsp"></jsp:include>

2.页面引入
京淘day05-京淘项目前端js展现

3.2 商品分类业务分析

3.2.1 分级说明

一般条件下商品分类分为3级.
京淘day05-京淘项目前端js展现

3.2.2 表结构设计

京淘day05-京淘项目前端js展现
京淘day05-京淘项目前端js展现

3.3 树形结构问题

3.3.1 页面JS

京淘day05-京淘项目前端js展现

3.3.2 JSON结构

[{"id":100,"text":"tomcat","state":"open/closed"}]

3.3.3 封装 EasyUITree 对象

在jt-manage中添加VO对象
京淘day05-京淘项目前端js展现

3.4 新增页面分析

3.4.1 页面流转过程

1.点击商品新增按钮
2.发起请求 /page/item-add
3.请求被IndexController中的restFul拦截
4.实现页面跳转 /WEB/INF/views/item-add.jsp
京淘day05-京淘项目前端js展现

3.4.2 页面结构分析

1).页面按钮
京淘day05-京淘项目前端js展现
2.页面树形结构展现详情
京淘day05-京淘项目前端js展现
京淘day05-京淘项目前端js展现

3.4.3 树形结构展现


树控件读取URL。子节点的加载依赖于父节点的状态。当展开一个封闭的节点,如果节点没有加载子节点,它将会把节点id的值作为http请求参数并命名为’id’,通过URL发送到服务器上面检索子节点。
1.用户在默认条件下 如果没有展开子节点,则不会发送请求.
2.当用户打开封闭的节点时,则会将改节点的ID当做参数,向后端服务器请求.
京淘day05-京淘项目前端js展现

3.4.4 编辑ItemCatController

/**
     * 业务需求: 实现商品分类树形结构展现
     * url地址:   http://localhost:8091/item/cat/list
     * 参数:      id= 父级节点的ID
     * 返回值:    List<EasyUITree>
     */
    @RequestMapping("/list")
    public List<EasyUITree> findItemCatList(Long id){
        //暂时只查询一级商品分类信息
        long parentId = (id==null?0:id);
        return itemCatService.findItemCatList(parentId);
    }

3.4.5 编辑ItemCatService

@Override
public List<EasyUITree> findItemCatList(long parentId) {
    //思路.返回值的数据从哪来? VO 转化 POJO数据
    //1.实现数据库查询
    QueryWrapper queryWrapper = new QueryWrapper();
    queryWrapper.eq("parent_id", parentId);
    List<ItemCat> catList = itemCatMapper.selectList(queryWrapper);
    //2.准备返回值数据
    List<EasyUITree> treeList = new ArrayList<>();
    //3.实现数据的转化 catList转化为 treeList 
    for (ItemCat itemCat : catList) {
        long id = itemCat.getId();       //获取ID值
        String text = itemCat.getName(); //获取商品分类名称
        String state = itemCat.getIsParent() ? "closed" : "open";
        EasyUITree easyUITree = new EasyUITree(id, text, state);
        treeList.add(easyUITree);
    }
    return treeList;
}

3.4.6 页面效果展现


京淘day05-京淘项目前端js展现


点赞
收藏
评论区
推荐文章
凯文86 凯文86
4年前
2021年前端趋势预测
淘系前端团队2021年前端趋势预测作者:发布于:知乎上,有人提问《2021前端会有什么新的变化?》狼叔的回答二天超过6.1万阅读量,目前444个赞同,2个专业徽章,整体上看,这篇回答大家还是相当认可的。(https://imghelloworld.osscnbeijing.aliyuncs.com/d2fa7c39e3e0
免费云服务器试用就来AWS
多数商家都已经意识到,抖音官方网站流量越来越贵,出价成本也越来越高,当大批量淘系玩家入局以后,他们并没有走“兴趣电商”的新套路,而是继续沿用淘系老玩法,仅仅是把淘系平面电商进化成了抖音立体电商。把淘系的“S单玩法”换成了抖音的“亏品玩法”,也就是我们所说的“憋单”。淘系算法下不S单很难做起来,抖系算法下不亏品也很难做起来,虽然手段不同但是原理相似,这就导致
AWS放福利啦
多数商家都已经意识到,抖音官方网站流量越来越贵,出价成本也越来越高,当大批量淘系玩家入局以后,他们并没有走“兴趣电商”的新套路,而是继续沿用淘系老玩法,仅仅是把淘系平面电商进化成了抖音立体电商。把淘系的“S单玩法”换成了抖音的“亏品玩法”,也就是我们所说的“憋单”。淘系算法下不S单很难做起来,抖系算法下不亏品也很难做起来,虽然手段不同但是原理相似,这就导致
开发者必须知道的网站,不看后悔
多数商家都已经意识到,抖音官方网站流量越来越贵,出价成本也越来越高,当大批量淘系玩家入局以后,他们并没有走“兴趣电商”的新套路,而是继续沿用淘系老玩法,仅仅是把淘系平面电商进化成了抖音立体电商。把淘系的“S单玩法”换成了抖音的“亏品玩法”,也就是我们所说的“憋单”。淘系算法下不S单很难做起来,抖系算法下不亏品也很难做起来,虽然手段不同但是原理相似,这就导致
中国区新用户注册即可免费使用12个月云服务产品啦
多数商家都已经意识到,抖音官方网站流量越来越贵,出价成本也越来越高,当大批量淘系玩家入局以后,他们并没有走“兴趣电商”的新套路,而是继续沿用淘系老玩法,仅仅是把淘系平面电商进化成了抖音立体电商。把淘系的“S单玩法”换成了抖音的“亏品玩法”,也就是我们所说的“憋单”。淘系算法下不S单很难做起来,抖系算法下不亏品也很难做起来,虽然手段不同但是原理相似,这就导致
中国开发者利好消息!
多数商家都已经意识到,抖音官方网站流量越来越贵,出价成本也越来越高,当大批量淘系玩家入局以后,他们并没有走“兴趣电商”的新套路,而是继续沿用淘系老玩法,仅仅是把淘系平面电商进化成了抖音立体电商。把淘系的“S单玩法”换成了抖音的“亏品玩法”,也就是我们所说的“憋单”。淘系算法下不S单很难做起来,抖系算法下不亏品也很难做起来,虽然手段不同但是原理相似,这就导致
Stella981 Stella981
3年前
Netty干货分享:京东京麦的生产级TCP网关技术实践总结
1、引言京东的京麦商家后台2014年构建网关,从HTTP网关发展到TCP网关。在2016年重构完成基于Netty4.xProtobuf3.x实现对接PC和App上下行通信的高可用、高性能、高稳定的TCP长连接网关。早期京麦搭建HTTP和TCP长连接功能主要用于消息通知的推送,并未应用于API网关。随着逐步对NIO的深入学习和对Netty框
Easter79 Easter79
3年前
Taro 助力京喜拼拼项目性能体验优化
背景—2020年是社区团购风起云涌的一年,互联网大厂纷纷抓紧一分一秒跑步进场。“京喜拼拼”(微信搜京喜拼拼)是京东旗下的社区团购平台,依托京东供应链体系,精选低价好货,为社区用户提供次日达等优质服务。京喜拼拼团队技术选型使用Taro以便于实现多端需求,因此Taro团队有幸参与到“京喜拼拼”小程序的性能体验优化工作。全面体验
直播预告丨大模型+Agents疏通京东金融运营堵点
大模型时代,“应用变了”:把大模型装进金融营销分几步?11月24日(周五)14:0015:00开播!数字化打破信息孤岛,也建立更多孤岛运营人员被困在自己的环节里十余个子系统、子模块如何整合?自然语言任务中的“幻觉”如何克服?如何将AI训练成业务运营高手?京
京东云开发者 京东云开发者
5个月前
京点点AIGC平台:实现高效、可控、智能的多模态内容生成和优化
作者:京东零售高继航1前言2024年,京东零售技术自研的京点点AIGC内容生成平台(以下简称“京点点”)已覆盖电商运营涉及的20核心场景,AI能力单日调用超1000万次。“京点点”致力于电商场景下商品内容、营销素材的智能化、自动化生产和运营,已帮助京东3
美凌格栋栋酱 美凌格栋栋酱
5个月前
Oracle 分组与拼接字符串同时使用
SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(