随笔分类 -  Spring boot

摘要:首先是创建工程,和前文一样,创建工程时,也是选择Web、Jdbc以及MySQL驱动,创建成功之后,一定接下来手动添加Druid依赖,由于这里一会需要开发者自己配置DataSoruce,所以这里必须要使用druid-spring-boot-starter依赖,而不是传统的那个druid依赖,因为dru 阅读全文
posted @ 2020-08-05 21:16 柒丶月 阅读(749) 评论(0) 推荐(0)
摘要:基本配置 JdbcTemplate基本用法实际上很简单,开发者在创建一个SpringBoot项目时,除了选择基本的Web依赖,再记得选上Jdbc依赖,以及数据库驱动依赖即可,如下: 项目创建成功之后,记得添加Druid数据库连接池依赖(注意这里可以添加专门为Spring Boot打造的druid-s 阅读全文
posted @ 2020-08-05 21:12 柒丶月 阅读(146) 评论(0) 推荐(0)
摘要:自定义欢迎页 Spring Boot 项目在启动后,首先会去静态资源路径下查找index.html作为首页文件,若查找不到,则会去查找动态的index文件作为首页文件。例如,如果想使用静态的index.html作为首页,那么只需在resources/static 目录下创建index.html 文件 阅读全文
posted @ 2020-08-05 21:07 柒丶月 阅读(179) 评论(0) 推荐(0)
摘要:添加依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-aop</artifactId> </dependency> Service层 @Service public 阅读全文
posted @ 2020-08-05 20:57 柒丶月 阅读(56) 评论(0) 推荐(0)
摘要:导入thymeleaf依赖 hello.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> hello </body> </html> Hell 阅读全文
posted @ 2020-08-05 20:56 柒丶月 阅读(69) 评论(0) 推荐(0)
摘要:Servlet @WebServlet(urlPatterns = "/myservlet") public class MyServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest req, Ht 阅读全文
posted @ 2020-08-05 20:55 柒丶月 阅读(91) 评论(0) 推荐(0)
摘要:两个类 CommandLineRunner ApplicationRunner 1. CommandLineRunner @Component @Order(99) //数字越小,优先级越大,默认情况下,优先级的值为Integer.MAX_VALUE,表示优先级最低 public class MyC 阅读全文
posted @ 2020-08-05 20:52 柒丶月 阅读(112) 评论(0) 推荐(0)
摘要:定义拦截器 public class MyInterceptor implements HandlerInterceptor { @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse re 阅读全文
posted @ 2020-08-05 20:50 柒丶月 阅读(74) 评论(0) 推荐(0)
摘要:同源策略 很多人对跨域有一种误解,以为这是前端的事,和后端没关系,其实不是这样的,说到跨域,就不得不说说浏览器的同源策略。 同源策略是由Netscape提出的一个著名的安全策略,它是浏览器最核心也最基本的安全功能,现在所有支持JavaScript的浏览器都会使用这个策略。所谓同源是指协议、域名以及端 阅读全文
posted @ 2020-08-05 20:49 柒丶月 阅读(102) 评论(0) 推荐(0)
摘要:在 SpringBoot 项目中 ,异常统一处理,可以使用 Spring 中 @ControllerAdvice 来统一处理,也可以自己来定义异常处理方案。SpringBoot 中,对异常的处理有一些默认的策略,我们分别来看。 默认情况下,SpringBoot 中的异常页面 是这样的: 我们从这个异 阅读全文
posted @ 2020-08-05 20:47 柒丶月 阅读(139) 评论(0) 推荐(0)
摘要:1. 处理全局异常 @ControllerAdvice public class MyCustomException { @ExceptionHandler(MaxUploadSizeExceededException.class) public void myexception(MaxUpload 阅读全文
posted @ 2020-08-05 20:44 柒丶月 阅读(102) 评论(0) 推荐(0)
摘要:在application.properties 限制文件属性 表单上传 spring.servlet.multipart.max-file-size=1KB <!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta na 阅读全文
posted @ 2020-08-05 20:42 柒丶月 阅读(75) 评论(0) 推荐(0)
摘要:默认策略 SpringBoot 中对于SpringMVC的自动化配置都在WebMVCAutoConfiguration类中。在WebMvcAutoConfiguration类中有一个静态内部类WebMvcAutoConfigurationAdapter,实现了WebMvcConfigurer接口。W 阅读全文
posted @ 2020-08-05 20:39 柒丶月 阅读(111) 评论(0) 推荐(0)
摘要:默认实现 Json是目前主流的前后端数据传输方式,SptringMVC中使用消息转换器HttpMessageConverter对JSON的转换提供了很好的支持,在SpringBoot中更进一步,对相关的配置做了简化。默认情况下,当开发者新创建一个SpringBoot项目后,添加web依赖,这个依赖默 阅读全文
posted @ 2020-08-05 20:14 柒丶月 阅读(951) 评论(0) 推荐(1)
摘要:整合Thymeleaf 在 pom.xml 中引入相关依赖 引入 Web 项目及 Thymeleaf 模板相关的依赖项。 实例: <!-- 引入web项目相关依赖 --> <dependency> <groupId>org.springframework.boot</groupId> <artifa 阅读全文
posted @ 2020-08-05 19:35 柒丶月 阅读(1191) 评论(0) 推荐(0)