随笔分类 - |--- SpringBoot
摘要:1、定时任务 1)cron表达式 2)SpringBoot整合corn表达式做定时任务
阅读全文
摘要:前言 仔代码检视时,讨论到在controller层手动添加日志太麻烦,于是想要注解和切面实现日志的自动输出,简化代码、简练程序 利用Aspect实现日志切面 1、添加aop依赖 <dependency> <groupId>org.springframework.boot</groupId> <art
阅读全文
摘要:1、为什么会出现跨域问题? 浏览器不允许通过ajax请求,来请求另一个网站的资源 2、SpringBoot如何通过Filter来解决跨域问题 2.1、写一个 CrosFilter 类来实现 javax.servlet.Filter 接口 public class CrosFilter impleme
阅读全文
摘要:ApplicationRunner接口 在项目中,可能会遇到这样一个问题:在项目启动完成之后,紧接着执行一段代码。 在SpringBoot中,提供了一个接口:ApplicationRunner。该接口中,只有一个run方法,他执行的时机是:spring容器启动完成之后,就会紧接着执行这个接口实现类的
阅读全文
摘要:异步任务 @Service public class AsyncService { @Async //标识着这是一个异步任务 public void hello(){ try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("数据处理中 .... "...
阅读全文
摘要:SpringBoot可以在数据源创建的同时执行建表语句和数据插入的sql语句: 默认只需要将文件命名为: schema-*.sql、data-*.sql 默认规则:schema.sql,schema-all.sql; 或者可以指定sql文件的位置 schema: - classpath:depart
阅读全文
摘要:一、springboot错误的默认处理机制 默认效果: 1)、浏览器,返回一个默认的错误页面 2)、如果是其他客户端,默认响应一个json数据 二、如何定制错误响应 1、如何定制错误的页面; 1)、有模板引擎的情况下;error/状态码; 【将错误页面命名为 错误状态码.html 放在模板引擎文件夹
阅读全文
摘要:1、抽取公共片段<div th:fragment="copy"> 2011 The Good Thymes Virtual Grocery</div> 2、引入公共片段<div th:insert="~{footer :: copy}"></div>~{templatename::selector}
阅读全文
摘要:在以前的 SpringMVC中,国际化需要以下3步骤 1)、编写国际化配置文件; 2)、使用ResourceBundleMessageSource管理国际化资源文件 3)、在页面使用fmt:message取出国际化内容 SpringBoot中实现国际化的步骤: 1)编写国际化配置文件,抽取页面需要显
阅读全文
摘要:1、引入 thymeleaf 切换thymeleaf版本 <properties> <thymeleaf.version>3.0.9.RELEASE</thymeleaf.version> <!-- 布局功能的支持程序 thymeleaf3主程序 layout2以上版本 --> <!-- thyme
阅读全文
摘要:1)所有的 /webjars/**, 都去classpath:/META-INF/resources/webjars/ 找资源 webjars:以jar包的方式引入静态资源; 2)/** 访问当前项目的任何资源,都去(静态资源的文件夹)下寻找 "classpath:/META-INF/resourc
阅读全文
摘要:1、默认配置 1)日志的使用 //记录器 Logger logger = LoggerFactory.getLogger(getClass()); @Test public void contextLoads() { //System.out.println(); //日志的级别; //由低到高 t
阅读全文
摘要:不仅要引入 <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.1.RELEASE</version> <relat
阅读全文
摘要:由于SpringBoot默认是以jar包的方式启动嵌入式的Servlet容器来启动SpringBoot的web应用,没有web.xml文件。 //注册三大组件 //servlet @Bean public ServletRegistrationBean myServlet(){ ServletReg
阅读全文
摘要:在Spring Boot2.0以上配置嵌入式Servlet容器时EmbeddedServletContainerCustomizer类不存在,查询发现被WebServerFactoryCustomizer替代 使用WebServerFactoryCustomizer接口替换EmbeddedServl
阅读全文
摘要:推荐尚硅谷 雷丰阳的springboot,这老师源码信手拈来,很厉害,教程讲解的超级好以下是我的笔记:http://note.youdao.com/noteshare?id=49d7a6950c927a696392db0665d4838c 链接:https://pan.baidu.com/s/18a
阅读全文
摘要:静态资源的文件夹 "classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/" "/":当前项目的根路径 这里有个坑==》启动项目后访问不到静态资源,一直宝4
阅读全文
摘要:1、导入依赖 <!--导入配置文件处理器 配置文件进行绑定就会有提示--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-configuration-processor</artifa
阅读全文
摘要:1、导入依赖呀 <!--导入配置文件处理器 配置文件进行绑定就会有提示--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-configuration-processor</artif
阅读全文
摘要:1、首先定义一个拦截器 package com.leyou.interceptor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.web.servlet.HandlerInte
阅读全文