![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Springboot
花繁柳密处
拨得开,才是手段;风狂雨急时,立得定,方见脚跟。
展开
-
Springboot概述
为了在JavaEE领域提供一种更为简便的开发方式,来取代繁琐的项目搭建工作,Spring推出了Springboot项目。该项目可以让使用者更快速地搭建项目,从而更专注于业务系统的开发。系统配置、基础代码、项目依赖的jar包,甚至开发时所应用到的服务器(Tomcat、jetty等)等,Springboot都可以帮我们准备好。只要在建立项目时,使用构建工具加入相应的Springboot依赖包,项目即可运行,无需关心版本兼容、部署war包等问题。四大核心:(1)自动配置:针对很多Spring应用程序和常见的应原创 2021-04-04 15:05:57 · 130 阅读 · 0 评论 -
自定义配置读取(Environment;@Value;@ConfigurationProperties)
我们可以在application.yml中进行自定义配置,问题是如何使用这些配置。Springboot给我们提供了三种方式:Environment类读取;@Value注解读取;@ConfigurationProperties注解读取。首先,在application.yml中准备自定义配置:my-jdbc: url: localhost:3306 user: root password: 123456 db: name: mysql version: 1.0原创 2021-03-27 09:58:35 · 729 阅读 · 0 评论 -
Springboot中过滤器Filter的配置与使用(UTF-8字符编码(解决乱码),请求URL过滤(HttpServletRequestWrapper))
之前在web.xml文件中,总会使用下面的配置进行字符编码:<filter> <filter-name>encoding</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding&原创 2021-03-26 19:24:46 · 1254 阅读 · 0 评论 -
Springboot运行单元测试@SpringBootTest
首先,需要导入相关依赖:<dependency> <!--springboot测试的起步依赖--> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId></dependency>(此处没有添加任何<scope>,<exclusions>等配置);之后,编原创 2021-03-14 11:03:12 · 1309 阅读 · 0 评论 -
登录拦截器
无需多言,只为查找方便:@Componentpublic class LoginInterceptor implements HandlerInterceptor {// 登录拦截器 @Autowired private TAdminInfoService tAdminInfoService; public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object ha原创 2021-01-26 13:56:21 · 78 阅读 · 0 评论 -
@DS注解的使用,动态数据源,事务
有时,在一个项目中会用到多数据源,此时可以使用苞米豆的dynamic-datasource-spring-boot-starter:首先,引入jar包:<dependency> <groupId>com.baomidou</groupId> <artifactId>dynamic-datasource-spring-boot-starter</artifactId> <version>2.5.4</version>原创 2021-01-12 20:58:37 · 30919 阅读 · 4 评论 -
使用RequestParam或HttpServletRequest获取上传的文件
前端(注意form的method与enctype):<form action="/upload" id="form" method="post" enctype="multipart/form-data"> 姓名:<input type="text" id="name" name="name"><br> 文件:<input type="file" name="myFile"><br> <button type="su原创 2021-01-03 17:11:39 · 2739 阅读 · 0 评论 -
Springboot中的MatrixVariable注解(PathVariable的升级版)
MatrixVariable,翻译过来就是"矩阵变量":PathVariable主要用于获取URI中的单一变量,MatrixVariable可以获取复杂变量;规则:(1)URI中的参数与值使用key-value形式;(2)多个参数间使用分号隔开;(3)若一个参数有多个值,值与值之间使用逗号隔开举例:首先,因为Springboot默认不使用MatrixVariable绑定参数,我们需要添加配置类:@Configurationpublic class MyWebConfig impleme原创 2020-12-28 20:43:17 · 411 阅读 · 0 评论 -
Springboot中的PathVariable注解(URI变量与方法参数)
@PathVariable主要用来修饰方法参数,表示此参数为请求URI的变量;请求URI中的变量,会自动转换为方法参数的类型;例1:@RequestMapping("/test/{name}")public String testName(@PathVariable String name) { System.out.println(name); return "test";}(默认情况下,@PathVariable中的变量名称为name,因此该变量会与方法中名称为name.原创 2020-12-28 20:09:51 · 1095 阅读 · 0 评论 -
使用@ConfigurationProperties进行属性配置时返回值为null;注意事项
今天在学习过程中遇到一个问题:Springboot环境下的自定义配置:boot.user-name=Jack对应的属性配置文件:@ConfigurationProperties(prefix = "boot")public class ValueTest { public String userName;}通过如下Controller取值为null:@GetMapping(value = "/value")@ResponseBodypublic ValueTest value原创 2020-12-07 20:46:21 · 2947 阅读 · 0 评论 -
Springboot中自定义错误日志&@ControllerAdvice&BasicErrorController&@ExceptionHandler
参考文件一对前后端分离的解释@Getter@Setter@Builder@AllArgsConstructor@JSONField5个注解分别何意@ControllerAdvice等其他注解的含义默认异常处理,以及未被@ControllerAdvice处理的,都会被转向/error(从默认的异常页面可以看出来),BasicErrorController用来处理这类请求(按照第一个参考,可以实现获取异常信息等)参考资料:SpringBoot 用 @ControllerAdvice 和原创 2020-12-07 19:26:27 · 642 阅读 · 0 评论 -
Springboot环境下静态资源文件读取;ClassPathResource;FileNotFoundException
String strpath = “keyword.txt”; //获取文本文档路径Resource resource = new ClassPathResource(strpath);File file = resource.getFile();System.out.println(file.exists());InputStreamReader isr = new InputStreamReader(new FileInputStream(file), “gbk”);BufferedRea原创 2020-11-29 11:22:12 · 1608 阅读 · 0 评论