SpringBoot 学习注意的点持续学习.......
SpringBoot:
1.SpringBoot的thymeleaf模板
# 禁用缓存
在配置文件中进行注释(application.properties)
spring.thymelvdeaf.cache=false
2.页面重新编译(idea)
Ctrl+f9
3.使用thymeleaf模板,需要在页面引入
<html lang="en" xmlns:th="http://www.thymeleaf.org">
4.thymeleaf的页面引入标签
链接:th:href="@{}"
抽取:
//将公共片段插入到指定元素中
<div th:fragment="xxx"> @#$% </div>
//将声明引入片段,替换成公共片段
<div th:replace>
//用div标签对内容进行包含
<div th:replace>
引入:
<div th:insert = "~{页面名称 :: xxx}">
<div th:insert = "footer :: xxx"> </div>
from表单引入对象 th:action=""
<form th:action="@{/xxx}" method="post">
页面判断 th:if=""
<div th:if="${xxx!=null}"></div>
赋值 th:value=""
删除属性 th:attr="del_uri
5.指定sql文件,在项目运行时执行
在application.yml
默认只需要将文件命名为:
schema-*.sql、data-*.sql
默认规则:schema.sql,schema-all.sql;
可以使用
schema:
- classpath:department.sql
指定位置
6.导入Druid数据源
@Configuration
public class DruidConfig {
@ConfigurationProperties(prefix = "spring.datasource")
@Bean
public DataSource druid(){
return new DruidDataSource();
}
//配置Druid的监控
//1、配置一个管理后台的Servlet
@Bean
public ServletRegistrationBean statViewServlet(){
ServletRegistrationBean bean = new ServletRegistrationBean(new StatViewServlet(), "/druid/*");
Map<String,String> initParams = new HashMap<>();
initParams.put("loginUsername","admin");
initParams.put("loginPassword","123456");
initParams.put("allow","");//默认就是允许所有访问
initParams.put("deny","192.168.15.21");
bean.setInitParameters(initParams);
return bean;
}
//2、配置一个web监控的filter
@Bean
public FilterRegistrationBean webStatFilter(){
FilterRegistrationBean bean = new FilterRegistrationBean();
bean.setFilter(new WebStatFilter());
Map<String,String> initParams = new HashMap<>();
initParams.put("exclusions","*.js,*.css,/druid/*");
bean.setInitParameters(initParams);
bean.setUrlPatterns(Arrays.asList("/*"));
return bean;
}
}
7.整合mybatis,创建MybatisConfig文件,并将他注入到Spring中。
@Configuration
public class MyBatisConfig {
@Bean
public ConfigurationCustomizer configurationCustomizer(){
return new ConfigurationCustomizer(){
@Override
public void customize(Configuration configuration) {
configuration.setMapUnderscoreToCamelCase(true);
}
};
}
}
8.配置mybatis全局映射文件 (最简单的)
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<setting name="mapUnderscoreToCamelCase" value="true"/>
</settings>
</configuration>
9.指定全局配置文件,在application。yml文件中指定
mybatis: # 指定全局配置文件位置 config-location: classpath:mybatis/mybatis-config.xml # 指定sql映射文件位置 mapper-locations: classpath:mybatis/mapper/*.xml
10.Spring-Boot-Jpa在配置文件中自动更新或创建表 的 配置(application.yml)
jpa:
hibernate:
# 更新或者创建数据表结构
ddl-auto: update
# 控制台显示SQL
show-sql: true
11.SpringBoot整合监控模块
监控模块ops的Actuator模块 健康状态指示器(实现和规范) 1.编写一个指示器,实现HealthIndicator接口 2.指示器的名字 规范:xxxHealthIndicator 3.加入容器@Bean

浙公网安备 33010602011771号