SpringBoot 秒杀项目

[TOC]html

项目介绍、开发环境、环境搭建

课程技术点

第一章 项目框架搭建

SpringBoot 环境搭建

集成 Thymeleaf,Result 结果封装

Result 结果封装先后对比

public Result<String> hello() {
	 		return Result.success("hello,imooc");
	       // return new Result(0, "success", "hello,imooc");
	       // 每次都要 new 对象,浪费
	       // 看起来也干净利落
	    }
复制代码

集成 thymeleaf

return hello,SpringBoot 会自动寻找视图解析器,好比我配置的 Thymeleaf,而后根据配置文件spring

#在构建 URL 时添加的前缀
spring.thymeleaf.prefix=classpath:/templates/
#构建 URL 时添加的后缀
spring.thymeleaf.suffix=.html
复制代码

组装成转发路径 hello.html缓存

@RequestMapping("/thymeleaf")
	    public String thymeleaf(Model model) {
	 		model.addAttribute("name", "Xiehang");
	 		return "hello";
	    }
复制代码

thymeleaf 配置文件安全

#不缓存页面
spring.thymeleaf.cache=false 
#内容为 text/html
spring.thymeleaf.content-type=text/html
#启用 MVC thymeleaf 视图解析
spring.thymeleaf.enabled=true
#模板编码
spring.thymeleaf.encoding=UTF-8
#要应用于模板的模板模式
spring.thymeleaf.mode=HTML5
#在构建 URL 时添加的前缀
spring.thymeleaf.prefix=classpath:/templates/
#构建 URL 时添加的后缀
spring.thymeleaf.suffix=.html
复制代码

集成 Mybatis + Druid

集成 Mybatis

Mybatis 配置bash

# mybatis
mybatis.type-aliases-package=com.xiehang.miaosha.domain
mybatis.configuration.map-underscore-to-camel-case=true
mybatis.configuration.default-fetch-size=100
mybatis.configuration.default-statement-timeout=3000
mybatis.mapperLocations = classpath:com/xiehang/miaosha/dao/*.xml
复制代码

这里不采用 xml 的方式配置 SQL 语句,而是在 dao 接口上写注解 @select、@update...mybatis

@Mapper
public interface UserDao {

    @Select("select * from user where id = #{id}")
    public User getById(@Param("id") int id);
}
复制代码

集成 Jedis + Redis 安装 + 通用缓存 Key 封装

第二章 实现登陆功能

第三章 实现秒杀功能

第四章 Jmeter 压力测试

第五章 页面优化技术

第六章 接口优化

第七章 安全优化

相关文章
相关标签/搜索