随笔分类 - springboot
摘要:@Configuration public class CorsConfig implements WebMvcConfigurer { @Override public void addCorsMappings(CorsRegistry registry) { // 设置允许跨域的路由 regis
阅读全文
摘要:/* * Copyright 2013-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this fi
阅读全文
摘要:@Resource注解是Java平台提供的注解,用于进行依赖注入。当你在类中的字段或属性上使用@Resource注解时,Java容器会自动为该字段或属性注入一个合适的Bean对象。 @Resource注解可以标注在字段或属性的setter方法上。如果标注在字段上,则会自动注入与该字段类型相匹配的Be
阅读全文
摘要:总体上,@Controller和@RestController都是Spring MVC框架中的注解,用于标识一个类是Spring MVC controller处理器,可以接收HTTP请求。但它们在处理请求和返回结果方面存在一些不同。 返回类型: @Controller:如果使用@Controller
阅读全文
摘要:pom文件中导入依赖 <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-boot-starter</artifactId> <version>3.0.0</version> </dependency> <depend
阅读全文
摘要:原代码没加@RequestParam,一直给我报这个错,传这个List根本不行 ```java @RequestMapping(value = "/searchPhoneInfos2", method = RequestMethod.GET) public CommonResult searchPh
阅读全文
摘要:依赖 <!--Spring Boot Redis --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </depend
阅读全文
摘要:使用@Valid注解如: public RespBean doLogin(@Valid LoginVo loginVo, HttpServletRequest request, HttpServletResponse response) { log.info("{}", loginVo); retu
阅读全文
摘要:RestControllerAdvice+ExceptionHandler这两个注解的组合,被用作项目的全局异常处理。一旦项目中发生了异常,就会进入使用了RestControllerAdvice注解类中使用了ExceptionHandler注解的方法。 下面是一些项目全局异常的处理 @Control
阅读全文
摘要:在学习谷粒学院要用阿里云发送短信验证码,无法申请到短信,于是便用邮箱发送验证码。 依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-mail</artifactId>
阅读全文
摘要:使用swagger可以帮我们在后端测试接口。 引入依赖: <!--swagger--> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.7.0</v
阅读全文
摘要:项目结构 父工程只要一个pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSch
阅读全文
摘要:pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance
阅读全文