Imooc·Java高并发秒杀API(三)
2016-06-11 11:59
423 查看
Imooc·Java高并发秒杀API
(Spring对RESTful规范的友好支持与利用Bootstrap快速开发漂亮页面)
一、Spring对RESTful规范的友好支持
package org.seckill.web; import java.util.Date; import java.util.List; import javax.annotation.Resource; import org.seckill.dto.Exposer; import org.seckill.dto.SeckillExecution; import org.seckill.dto.SeckillResult; import org.seckill.entity.Seckill; import org.seckill.enums.SeckillStatEnum; import org.seckill.expression.RepeatKillException; import org.seckill.expression.SeckillCloseException; import org.seckill.service.SeckillService; import org.seckill.service.impl.SeckillServiceImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.CookieValue; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; @Controller @RequestMapping("/seckill") public class SeckillController { private Logger logger = LoggerFactory.getLogger(this.getClass()); @Autowired private SeckillService seckillService; @RequestMapping(value="/list", method=RequestMethod.GET) public String list(Model model){ List<Seckill> list = seckillService.getSeckillList(); model.addAttribute("list",list); return "/list"; } }
二、利用Bootstrap快速开发漂亮页面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@ include file="common/tag.jsp"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE html> <html lang="zh-CN"> <head> <title>秒杀列表页</title> <%@ include file="common/head.jsp" %> </head> <body> <!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> <script src="//cdn.bootcss.com/jquery/1.11.3/jquery.min.js"></script> <!-- Include all compiled plugins (below), or include individual files as needed --> <script src="js/bootstrap.min.js"></script> <div class="container"> <div class="panel panel-default"> <div class="panel-heading text-center"> <h2>秒杀列表</h2> </div> <div class="panel-body"> <table class="table table-hover"> <thead> <tr> <th>名称</th> <th>库存</th> <th>开始时间</th> <th>结束时间</th> <th>创建时间</th> <th>详情页</th> </tr> </thead> <tbody> <c:forEach var="sk" items="${list}"> <tr> <td>${sk.name }</td> <td>${sk.number }</td> <td> <fmt:formatDate value="${sk.startTime}" pattern="yyyy-MM-dd HH:mm:ss"/> </td> <td> <fmt:formatDate value="${sk.endTime}" pattern="yyyy-MM-dd HH:mm:ss"/> </td> <td> <fmt:formatDate value="${sk.createTime}" pattern="yyyy-MM-dd HH:mm:ss"/> </td> <td> <a class="btn btn-info" href="/seckill/${sk.seckillId }/detail" target="blank">link</a> </td> </tr> </c:forEach> </tbody> </table> </div> </div> </div> </body> </html>
三、效果图
相关文章推荐
- Java压缩技术(三) ZIP解压缩——Java原生实现
- java 加载Properties
- Java压缩技术(二) ZIP压缩——Java原生实现
- Java压缩技术(一) ZLib
- StringTokenizer类的使用
- java中jdbc事务管理
- 【Java学习-J.160611.0.21】Servlet基础四 cookie部分
- java for 的用法总结
- java中的synchronized
- leetcode 236. Lowest Common Ancestor of a Binary Tree-二叉树共同祖先|深度遍历|递归|非递归
- Spring基础—Bean容器
- 查找代码错误.java
- java创建邮件模板
- Java基础知识强化105:打印数组的方法总结
- java中jdbc调用存储过程
- spring框架简介
- JAVA中关于同步与死锁的问题
- Struts2 框架下 session 读出来为null
- mysql/sql server和java之间的数据类型对应关系
- JavaWeb学习笔记之Log4j使用教程