潘的日记本


  • 首页

  • 关于

  • 标签

  • 归档

  • 搜索

Thymeleaf使用(五)

发表于 2019-11-21

Thymeleaf使用

1
2
3
4
5
6
@ConfigurationProperties(prefix = "spring.thymeleaf")
public class ThymeleafProperties {
private static final Charset DEFAULT_ENCODING = Charset.forName("UTF-8");
private static final MimeType DEFAULT_CONTENT_TYPE = MimeType.valueOf("text/html");
public static final String DEFAULT_PREFIX = "classpath:/templates/";
public static final String DEFAULT_SUFFIX = ".html";
  • 只要我们把HTML页面放在classpath:/templates/,thymeleaf就能自动渲染;

  • 使用:

1、导入thymeleaf的名称空间

1
<html lang="en" xmlns:th="http://www.thymeleaf.org">

2、使用thymeleaf语法;

1
2
3
4
5
6
7
8
9
10
11
12
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1>成功!</h1>
<!--th:text 将div里面的文本内容设置为 -->
<div th:text="${hello}">这是显示欢迎信息</div>
</body>
</html>
阅读全文 »

Spring Boot Web开发(四)

发表于 2019-11-21

Web开发

1、简介

使用SpringBoot;

1)、创建SpringBoot应用,选中我们需要的模块;

2)、SpringBoot已经默认将这些场景配置好了,只需要在配置文件中指定少量配置就可以运行起来

3)、自己编写业务代码;

1
2
xxxxAutoConfiguration:帮我们给容器中自动配置组件;
xxxxProperties:配置类来封装配置文件的内容;

2、SpringBoot对静态资源的映射规则;

1
2
3
@ConfigurationProperties(prefix = "spring.resources", ignoreUnknownFields = false)
public class ResourceProperties implements ResourceLoaderAware {
//可以设置和静态资源有关的参数,缓存时间等
阅读全文 »

Spring Boot配置(三)

发表于 2019-11-21

一、配置文件

  • Spring Boot使用一个全局得配置文件。作用:修改SpringBoot得Zion给配置默认值

    • application.properties
    • application.yml
  • 配置文件放在src/main/resources目录或者类路径/config下

    • springboot启动会扫描一下位置的application.properties或者application.yml文件作为Spring boot的默认配置文件
      -file:/config/
      -file:/
      -classpath:/config/
      -classpath:/
    • 优先级由高到低,高优先级的配置会覆盖低优先级的配置;
    • Springboot会从这四个位置全部加载主配置文件;互补配置
    • 还可以通过spring.config.location 来改变默认的配置文件位置
  • .yml是YAML(YAML Ain’t Markup Language)语言得文件,以数据为中心,比json、xml等更适合做配置文件

    • http://www.yaml.org/ 参考语法规范
    • YAML 配置例子
1
2
server:
port:8080
  • 全局配置文件得可以对一些默认配置值进行修改
阅读全文 »

Holle World探究(二)

发表于 2019-11-17

1、POM文件

1、父项目

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.9.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
他的父项目
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.1.9.RELEASE</version>
<relativePath>../../spring-boot-dependencies</relativePath>
</parent>
他来真正管理Spring Boot 应用里面的所有依赖版本

Spring Boot的版本仲裁中心:
以后我们导入依赖默认是不需要写版本;(没有在dependencies里面管理的依赖自然需要生面版本号)

2、导入的依赖

1
2
3
4
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
  • spring-boot-starter-web:
    spring-boot-starter:spring-boot场景启动器;帮我们导入了web模块正常运行所依赖的组件;

Spring Boot将所有功能场景都抽取出来,做成一个个的starters(启动器),只需要在项目里面引入这些starter相关场景的所有依赖都会导入进来。要用什么功能就导入什么场景的启动器。

2、主程序类,主入口类

1
2
3
4
5
6
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}

@SpringBootApplication: Spring Boot应用标注在某个类上说明这个类是SpringBoot的主配置类,SpringBoot就应该运行这个类的main方法来启动SpringBoot应用;

阅读全文 »

Spring Boot入门(一)

发表于 2019-10-06

1、Spring Boot 简介

  • 简化spring应用开发得一个框架;
  • 整个Spring技术栈得一个大整合;
  • J2EE开发的一站式解决方案;

2、微服务

2014、Martin fowler
微服务:构架风格
一个应用应该是一组小型服务;可以通过HTTP的方式进行互通;

单体应用:ALL IN ONE;

  • Simple to:develop,test,deploy,scale
    每一个功能元素最终都是一个可独立替换和独立升级的软件单元
    环境约束:
  • jdk1.8 :Spring Boot 1.7以上;
  • maven3.x :maven3.3以上;
  • intellIjIDEA2017 :STS
  • Spring Boot RELEASE:

3、统一环境:

1.maven设置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<localRepository>D:\ideaall\libmaven</localRepository>//大概50行

<mirrors>
<mirror>
<id>nexus-aliyun</id>
<mirrorOf>*</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
</mirrors>//大概150行


<profiles>
<profile>
<id>jdk-1.8</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.8</jdk>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.comilerVersion>1.8</maven.compiler.comilerVersion>
</properties>
</profile>//大概200行
阅读全文 »
1…34
paniford

paniford

35 日志
10 标签
© 2021 paniford
由 Hexo 强力驱动
|
主题 — NexT.Gemini v5.1.4