springboot第六篇:细节回顾

配置文件

 

.properties:目前官方不推荐,建议更换为yaml

  语法结构: key=value

 

.yaml:YamlPropertiesFactoryBean将yaml加载为Properties,YamlMapFactoryBean将yaml加载为Map,对空格要求极为严格

  语法结构:key:空格+value

##yaml

# 普通的key-value
name: tian

# 对象
student:
    name: tian
    age: 5

#行内写法
 student: {name: tian,age: 5}

# 数组
pets:
    - cat
    - dog
    - pig

pets: [cat,dog,pig]


##.properties   只能保存键值对

name=tian
student.name = tian
student.age = 5

 

.yaml多配置文件切换

server:
  port: 8081
spring:
  profiles:
    active: dev

---
server:
  port: 8082
spring:
  profiles: dev

---
server:
  port: 8083
spring:
  profiles: test

 

.yaml与.properties功能对比

 

JSR303数据校验

 

 

配置文件存放处与优先级大小

1:file: ./config/      (需要新建config文件夹)

2:file: ./

3:classpath: /config/  (需要新建config文件夹)

4:classpath:/      (项目默认存放config文件处)

 

配置文件server标签对应以下地址的class,同理其它

 

自动装配原理总结:

1:SpringBoot启动会加载大量的自动配置类

2:我们看我们需要的功能有没有在默认写好的自动配置类中

3:确认自动默认配置类中配置了哪些组件(若需要的组件在其中,就不需要手动配置了)

4:给容器中自动配置类添加组件时,会从properties类中获取某些属性。我们只需要在配置文件中指定这些属性的值即可

  xxxxAutoConfiguration:自动配置类

  xxxxProperties:封装配置文件中相关属性

5:可以通过debug=true观看哪些配置类生效,哪些没生效

 

静态资源

可通过以下地址导入

 

1:classpath:/META-INF/resources/webjars/  从www.webjars.com网站中通过maven引入的包会放入对应地址

2:classpath:/META-INF/resources/

3:classpath:/resources/    优先级高于以下俩

4:classpath:/static/      优先级高过5

5:classpath:/public/

 

页面国际化

1:首页配置:所有页面的静态资源都需要使用thymeleaf接管;@{}

2:需要配置i18n文件

3:若需要在项目中进行按钮自动切换,需要自定义一个组件LocaleResolver

4:需要将自定义组件配置到spring容器中@bean

5:#{}

 

Mybatis——mybatis-spring-boot-starter

1:导入包

2:配置文件

3:mybatis配置

4:编写dao层sql

5:service层调用dao层

6:controller调用service层

 

Shiro

1:Subject currentUser = SecurityUtils.getSubject()

2:Session session = currentUser.getSession()

3:currentUser.isAuthenticated()

4:currentUser.getPrincipal()

5:currentUser.hasRole("schwartz")

6:currentUser.isPermitted("lightsaber:wield")

7:currentUser.logout()

posted @ 2022-01-15 09:23  天叔  阅读(46)  评论(0编辑  收藏  举报