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 壓力測試

第五章 頁面優化技術

第六章 接口優化

第七章 安全優化

相關文章
相關標籤/搜索