品优购项目记录:day08

今日目标:

(1)了解网站前台的页面以及广告相关表结构

(2)完成运营商广告类型管理和广告管理

(3)完成前台工程广告轮播图的展示

(4)使用 SpringDataRedis 操作 Redis 缓存

(5)使用SpringDataRedis 实现广告的缓存

 

目录

1、运营商后台-广告类型管理和广告管理

1.1 广告管理图片上传功能

1.2 内容类目ID下拉选择

1.3 状态字段修改为复选框选择

2、网站首页-广告展示

2.1 后端

2.2 前端

2.3 引入缓存


 

1、运营商后台-广告类型管理和广告管理

准备工作:搭建服务层工程(pinyougou-content-interface 以及 pinyougou-content-service),参考sellergoods服务层进行搭建。

 

 

1.1 广告管理图片上传功能

(1)将shop-web中的图片上传相关JS、控制层类以及配置文件复制到manager-web中

 

(2)在springmvc.xml配置文件中配置多媒体解析器

	<!-- 配置多媒体解析器 -->
	<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
		<property name="defaultEncoding" value="UTF-8"></property>
		<!-- 设定文件上传的最大值5MB,5*1024*1024 -->
		<property name="maxUploadSize" value="5242880"></property>
	</bean>

(3)前端:在manager-web的goodsController.js中注入uploadService服务,并在页面中引入uploadService.js文件

 

(4)前端:在manager-web的在goodsController.js中新增方法

    // 上传文件
    $scope.uploadFile = function () {
        uploadService.uploadFile().success(
            function (rtn) {
                if (rtn.success) {
                    $scope.image_entity.url = rtn.message;
                } else {
                    alert(rtn.message);
                }
            }
        );
    }

(5)前端:页面修改绑定变量部分

 

 

1.2 内容类目ID下拉选择

(1)前端:在manager-web的contentController.js中注入contentCategory服务,并在页面引入selece2相关资contentCategoryService.js文件

 

(2)前端:在manager-web的contentController.js中添加方法

    $scope.findContentCategoryList=function(){
        contentCategoryService.findAll().success(
            function(response){
                $scope.contentCategoryList=response;
            }
        );
    }

 

(3)前端:在manager-web的content.html的内容分类ID处引入下拉框,并绑定变量

 

1.3 状态字段修改为复选框选择

(1)前端:修改页面

 

 

 

2、网站首页-广告展示

准备工作:搭建前台页面工程(pinyougou-portal-web),此工程为网站前台的入口,参照其它war模块编写配置文件。不需要添加SpringSecurity框架

 

2.1 后端

(1) 服务层接口(content-interface),新增方法

	/**
	 * 按广告分类ID查询广告
	 *
	 * @param categoryId
	 * @return java.util.List<com.pinyougou.pojo.TbContent>
	 */
	List<TbContent> findByCategoryId(Long categoryId);

 

(2) 服务层实现(content-service),新增实现

	@Override
	public List<TbContent> findByCategoryId(Long categoryId) {
		// 封装查询条件
		TbContentExample example = new TbContentExample();
		example.createCriteria().andCategoryIdEqualTo(categoryId).
				andStatusEqualTo(TbContent.STATUS_YES);
		// 排序
		example.setOrderByClause("sort_order");
		// 执行查询
		return contentMapper.selectByExample(example);
	}

 

(3) 控制层(portal-web),新增类ContentController

package com.pinyougou.portal.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.pinyougou.content.service.ContentService;
import com.pinyougou.pojo.TbContent;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 首页广告控制层
 * Author xushuai
 * Description
 */
@RestController
@RequestMapping("/content")
public class ContentController {

    @Reference
    private ContentService contentService;


    /**
     * 获取广告内容
     *
     * @param categoryId 广告分类ID
     * @return java.util.List<com.pinyougou.pojo.TbContent>
     */
    @RequestMapping("/findByCategoryId")
    public List<TbContent> findByCategoryId(Long categoryId) {
        return contentService.findByCategoryId(categoryId);
    }
}

 

2.2 前端

(1)创建contentService.js,新增方法

app.service('contentService',function ($http) {

    // 获取指定广告类型的广告
    this.findByCategoryId = function (categoryId) {
        return $http.get('content/findByCategoryId.do?category=' + categoryId);
    }
})

 

(2)创建contentController.js,新增方法

app.controller('contentController',function ($scope,contentService) {

    // 所有广告的列表
    $scope.contentList = [];
    // 查询指定广告分类的广告
    $scope.findByCategoryId = function (categoryId) {
        contentService.findByCategoryId(categoryId).success(
            function (rtn) {
                // 将categoryId作为下标,将返回结果存入广告列表
                $scope.contentList[categoryId] = rtn;
            }
        );
    }
});

(3)在portal-web中的index.html引入相关js文件和css文件,并编写基本的指令

(4)页面绑定变量,循环展示广告

 

 

2.3 引入缓存

由于首页一般访问压力较大,为了考虑高并发,我们引入redis缓存

(1)在common工程中引入redis和spring data redis的依赖

 	 <!-- 缓存 -->
	<dependency> 
		  <groupId>redis.clients</groupId> 
		  <artifactId>jedis</artifactId> 
	</dependency> 
	<dependency> 
		  <groupId>org.springframework.data</groupId> 
		  <artifactId>spring-data-redis</artifactId> 
	</dependency>	

 

(2)后端:修改content-service中的findByCategoryId的实现

    @Override
    public List<TbContent> findByCategoryId(Long categoryId) {
        // 先从redis中查询数据
        List<TbContent> contentList = (List<TbContent>) redisTemplate.boundHashOps("content").get(categoryId);
        if (contentList == null) {// 缓存中没有数据
            // 封装查询条件
            TbContentExample example = new TbContentExample();
            example.createCriteria().andCategoryIdEqualTo(categoryId).
                    andStatusEqualTo(TbContent.STATUS_YES);
            // 排序
            example.setOrderByClause("sort_order");
            // 执行查询
            contentList = contentMapper.selectByExample(example);
            // 将查询到的数据存入缓存
            redisTemplate.boundHashOps("content").put(categoryId, contentList);
        }
        return contentList;
    }

 

(3)后端:修改content-service中的add、delete、update的实现,完成修改数据时同步更新缓存

    /**
     * 增加
     */
    @Override
    public void add(TbContent content) {
        contentMapper.insert(content);
        // 更新缓存
        redisTemplate.boundHashOps("content").delete(content.getCategoryId());
    }

    /**
     * 修改
     */
    @Override
    public void update(TbContent content) {
        // 删除修改前的分类ID对应的缓存数据
        Long categoryId = contentMapper.selectByPrimaryKey(content.getId()).getCategoryId();
        redisTemplate.boundHashOps("content").delete(categoryId);

        // 执行修改
        contentMapper.updateByPrimaryKey(content);

        // 判断是否修改了广告分类
        if (categoryId.longValue() != content.getCategoryId().longValue()) {
            // 更新修改后的对应的分类ID的缓存数据
            redisTemplate.boundHashOps("content").delete(content.getCategoryId());
        }
    }

    /**
     * 批量删除
     */
    @Override
    public void delete(Long[] ids) {
        for (Long id : ids) {
            // 更新缓存
            Long categoryId = contentMapper.selectByPrimaryKey(id).getCategoryId();//广告分类ID
            redisTemplate.boundHashOps("content").delete(categoryId);
            // 执行删除
            contentMapper.deleteByPrimaryKey(id);
        }
    }

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1.2. 结构化一下 1.3. 图形化一下 1.3.1. 运营商后台 1.3.2. 商家后台 1.3.3. 网页前台 参考京东 2. 技术选型 前端:angularJS + Bootstrap 后台:SSM( springmvc+spring+mybatis) 数据库:mysql,使用mycat读写分离 开发模式:SOA 服务中间件:dubbox,需要和zookeeper配合使用 注册中心:zookeeper 消息中间件:Activemq,使用spring-jms 负载均衡:nginx 搜索:solr集群(solrCloud),配合zookeeper搭建, 使用spring-data-solor 缓存:redis集群,使用spring-data-redis 图片存储:fastDFS集群 网页静态化:freemarker 单点登录:cas 权限管理:SpringSecurity, 跨域:cros 支付:微信扫描 短信验证:阿里大于 密码加密:BCrypt 富文本:KindEditor 事务:声明式事务 任务调度:spring task 所有的技术,都可能涉及到为什么用?怎么用?用的过程中有什么问题? 3. 框架搭建 3.1. 前端 理解baseControler.js、base.js、base_pagination.js,以及每一个xxxController.js里面都公共的做了些什么。 baseControler.js 分页配置 列表刷新 处理checkBox勾选 xxxControler.js 自动生成增删改查 base_pagination.js 带分页 base.js 不带分页 3.2. dao 使用了mybatis逆向工程 4. 模块开发 逐个模块开发就好 4.1. 学会评估模块难不难 一个模块难不难从几方面考虑。 涉及几张表? 1,2张表的操作还是没有什么难度的。 涉及哪些功能? 增删改查,批量删除。 前端展示? 分页列表、树形、面包屑、三级联动、内容格式化。 4.2. 举几个简单模块的例子 4.2.1. 品牌管理 单表 分页、新增、删除、修改 4.2.2. 规格管理 2张表 分页、新增、删除、修改、显示优化(显示列表内容的一部分) 4.2.3. 模板管理 2张表 分页、新增、删除、修改、显示优化(显示列表内容的一部分) 4.2.4. 分类管理 单表 4.2.5. 商家审核 单表 4.3. 举一个复杂模块 4.3.1. 商品新增 需要插入3张表,tb_goods、tb_goods_desc、tb_item 前端:三级联动、富文本、图片上传、动态生成内容 4.3.2. 商品修改 需要从3张表获取数据,然后进行回显。 4.4. 典型模块设计 4.4.1. 管理后台 商品新增、商品修改 4.4.2. 前台页面 搜索模块实现 购物车模块实现 支付模块实现 秒杀模块实现 5. 开发过程中问题&优化 1.1. 登录 单点登录怎么实现 session怎么共享 1.2. 缓存 哪些场景需要用到redis redis存储格式的选择 怎么提高redis缓存利用率 缓存如何同步 1.3. 图片上传 图片怎么存储 图片怎么上传 1.4. 搜索 ​ 怎么实现 数据量大、 并发量高的搜索 怎么分词 1.5. 消息通知 ​ 哪些情况用到activeMq 1.6. 优化 seo怎么优化 怎么加快访问速度 1.7. 秒杀 ​ 怎么处理高并发 ​ 秒杀过程中怎么控制库存
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值