百战商城(六)-Redis缓存大广告数据

一.门户系统轮播图显示
1.页面分析
门户系统的index.jsp
在这里插入图片描述

{
   
    "src": "http://image.baizhan.com/images/2015/03/03/2015030304360302109345.jpg",
    "width": 670,
    "height": 240,
    "alt": "",
    "href": "http://sale.jd.com/act/e0FMkuDhJz35CNt.html?cpdad=1DLSUE",
    "srcB": 	"http://image.baizhan.com/images/2015/03/03/2015030304360302109345.jpg",
    "widthB": 550,
    "heightB": 240
}

2.控制器

@Controller
public class DispatcherController {
   
    @Autowired
    private ContentService contentService;

    /**
     * 进入主页面的控制器方法
     * 需要向作用域存放ad1, 代表轮播图信息
     *
     * @return
     */
    @RequestMapping({
   "/", "/index", "/default"})
    public String toIndex(Model model) {
   
        // 查询
        String ad1 = contentService.contentList();
        // 保存到作用域
        model.addAttribute("ad1", ad1);
        // 页面跳转
        return "index";
    }
}

3.门户系统服务代码

public interface ContentService {
   
    /**
     * 查询门户系统需要的轮播图信息
     *
     * @return
     */
    String contentList();
}
@Service
public class ContentServiceImpl implements ContentService {
   
    @Autowired
    private RpcContentService rpcContentService;
    @Value("${ad_category_id}")
    private long cid;
    @Value("${portal_ad_count}")
    private int count;
    @Value("${ad_img_width}")
    private int width;
    @Value("${ad_img_height}")
    private int height;
    @Value("${ad_img2_width}")
    private int width2;
    @Value("${ad_img2_height}")
    private int height2;

    @Override
    public String contentList() {
   
        // 返回结果
        String jsonStr = "[]";
        try {
   
            // 远程调用查询
            RpcResult<List<Content>> result = rpcContentService.contentList(cid, count);
            // 判断结果状态
            if(result.getStatus() == 200) {
   
                // 获取数据
                List<Content> data = result.getData();
                // 准备list集合
                List<Map<String, Object>> list = new ArrayList<>();
                // 转换
                for (Content content : data) {
   
                    Map<String, Object> map = new HashMap
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值