SpringBoot基本使用

SpringBoot简化Spring开发:stater(场景启动器),XxxAutoConfiguration,XxxProperties

1. 配置文件

SpringBoot默认的配置文件

application.properties:优先级高

application.yml(yaml)

application.properties:
SpringBoot基本使用

一个项目多端口启动

导成jar包,在window的cmd窗口运行
SpringBoot基本使用
在eclipse中多端口运行项目
SpringBoot基本使用

yml配置文件基本格式

SpringBoot基本使用
​ 使用缩进代表层次级别,同一层次的属性,在垂直方向上对齐

​ 属性: 属性值 中间一定要有空格

@ConfigurationProperties

使用此注解可以将配置文件的字段直接赋值到对象属性。
可以赋值一般的字符串类型和数组,map.
SpringBoot基本使用
Pom.xml文件配置自定义属性前缀提示
SpringBoot基本使用

Application.yml
SpringBoot基本使用
Application.properties
SpringBoot基本使用

@Value

@Value(“${student.sname}”)Spring里的语法,可以取出配置文件对应的值
SpringBoot基本使用

@PropertySource

这个注解可以读取非默认的配置文件中的属性值
SpringBoot基本使用

Spring的配置文件也支持

@ImportResource(“classpath:spring.xml”)

加载指定的xml配置文件,一般写在启动类上

Spring.xml
SpringBoot基本使用

Springboot的启动类
SpringBoot基本使用

Servcie类

SpringBoot基本使用

测试类

SpringBoot基本使用

SpringBoot推荐使用配置类

配置类:定义一个类打上注解@Configuration

​ 在配置类中定义方法,方法的返回值是一个 bean @Bean
SpringBoot基本使用

测试类
SpringBoot基本使用

2.日志输出

Spring SpringBoot

日志门面 logging slf4j

日志实现 log4j logback jbosslogging(hibernateVlidator)
SpringBoot基本使用
Application.properties中配置日志输出级别
SpringBoot基本使用

3. static文件夹

存放静态资源:html jpg css js

默认的静态资源路径有多个,也可以自己配置路径

我们一般就是使用static
SpringBoot基本使用

**4.**templates文件夹

存放有模板引擎的页面

模板引擎:服务器端提供的技术,将域中的数据使用模板语法进行解析,变成html响应给用户

JSP:EL JSTL,SpringBoot官方不推荐

thymeleaf: SpringBoot官方推荐

*thymeleaf*
SpringBoot基本使用
SpringBoot基本使用
模板引用的基本配置
SpringBoot基本使用
thymeleaf没有提示安装插件

SpringBoot基本使用
SpringBoot基本使用
SpringBoot基本使用

配置xml本地约束

http://www.thymeleaf.org/xsd/thymeleaf-extras-dialect-2.1.xsd

SpringBoot基本使用

禁用模板缓存
SpringBoot基本使用
SpringBoot基本使用

SpringBoot基本使用

5. Restful风格实现CRUD

*登录*

后台先登录,在访问

用户请求/路径或者/index.html路径,都应该先去登录页面login.html(templates/login.html)
SpringBoot基本使用
SpringBoot基本使用
SpringBoot基本使用
SpringBoot基本使用

没有登录的用户不能访问后台

添加拦截器

SpringBoot基本使用
SpringBoot基本使用

6.事物控制

@EnableTransactionManagement
SpringBoot基本使用
@Transactional
SpringBoot基本使用

7.数据源

SpringBoot有内置的数据源

SpringBoot基本使用
配置druid(阿里巴巴开发的)

SpringBoot基本使用