一、精灵前台项目搭建
1.1 整体架构设计
二、构建JL-WEB
2.1 在Idea创建jl-web子工程
- new -> Moudule> maven 创建子项目
jl-web
- 在pom.xml 里添加 :
<packaging>war</packaging>
- 添加
jl-common
依赖和跳过测试类打包的插件- 配置
application.yml
设置端口为8092
,定义springmvc视图解析器
- 导入静态资源文件
- 修改redis 配置文件 : 将
jl-manage
的redis.properties
文件赋值到jl-web中
- 设置
webapp
- 在springBootRun启动类中修改在启动时不要加载数据源配置
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
- 在
Run Configurations
中添加jl-web的springboot启动项,并将working directory
设置为$MODULE_DIR$
2.1.1 pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>jl</artifactId>
<groupId>com.jl</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>jl-web</artifactId>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>com.jl</groupId>
<artifactId>jl-common</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<!--跳过测试类打包 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
2.1.2 application.yml
server:
port: 8092
spring: #定义springmvc视图解析器
mvc:
view:
prefix: /WEB-INF/views/
suffix: .jsp
2.2 修改nginx 实现域名代理
2.2.1 修改nginx配置文件
修改之后重启nginx
#配置前台服务器
server {
listen 80;
server_name www.jl.com;
location / {
proxy_pass http://localhost:8092;
}
}
2.2.2 修改hosts文件
127.0.0.1 www.jl.com
三、伪静态
3.1 静态页面特点
1.浏览器加载静态资源的速度更快. 浏览器自己有缓存.
2.静态页面更加容易被搜索引擎收录. 百度/谷歌
3.用户的交互性弱.
3.2 搜索引擎工作原理
百度通过
倒排索引
的方式实现秒杀级查询
3.3 伪静态
伪静态技术是指展示出来的是以html一类的静态页面形式,但其实是用ASP一类的动态脚本来处理的,即
以html结尾的动态页面
3.4 修改servlet拦截策略
Springboot中默认不拦截为.html结尾的请求.但是根据伪静态的要求,必须拦截以.html为结尾的请求.则需要修改默认的拦截配置
在jl-web中添加该配置
@Configuration //表示配置类
public class MvcConfigurer implements WebMvcConfigurer{
//开启匹配后缀型配置
@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
configurer.setUseSuffixPatternMatch(true);
}
}
四、HttpClient(了解)
HttpClient 是Apache Jakarta Common 下的子项目,可以用来提供高效的、最新的、功能丰富的支持 HTTP 协议的客户端编程工具包
HttpClient 提供的主要的功能 :
(1)实现了所有 HTTP 的方法(GET,POST,PUT,DELETE 等)
(2)支持自动转向
(3)支持 HTTPS 协议
(4)支持代理服务器等
SpringCloud中服务和服务之间的调用全部是使用HttpClient 传送门
4.1 导入jar包
<!--添加httpClient jar包 -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
4.2 HttpClinet入门案例
1.实例化httpClient对象
2.准备url请求地址 https://www.baidu.com/
3.封装请求方式对象 GET/POST/PUT/DELETE
4.发起http请求.获取服务器响应.
5.判断返回值状态码信息 200.
6.从响应对象中获取服务器返回值数据.
public class TestHttpClient {
@Test
public void testGet() throws ClientProtocolException, IOException {
CloseableHttpClient client = HttpClients.createDefault();
String url = "https://www.baidu.com";
HttpGet get = new HttpGet(url);
CloseableHttpResponse response = client.execute(get);
if(response.getStatusLine().getStatusCode() == 200) {
//表示请求服务正确
HttpEntity entity = response.getEntity();//返回值实体对象
String result = EntityU