新项目记录

1.springboot测试时出现

是因为我没在根目录下写一个springboot的启动类:写个App.class,再在test测试类跑起来就不会出现这个错误了

2. @EnableCaching

https://blog.csdn.net/micro_hz/article/details/76599632

http://blog.didispace.com/springbootcache1/

https://blog.csdn.net/zl_momomo/article/details/80403564

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-cache</artifactId>
</dependency>

@Cacheable(value = { "sampleCache" },key="#id")

@Cacheable(value=“sampleCache”),这个注释的意思是,当调用这个方法的时候,会从一个名叫 sampleCache 的缓存(缓存本质是一个map)中查询key为id的值,如果不存在,则执行实际的方法(即查询数据库等服务逻辑),并将执行的结果存入缓存中,否则返回缓存中的对象。这里的缓存中的 key 就是参数 id,value 就是 返回的String 对象 
 

3.

@SpringBootApplication
@MapperScan(basePackages = "com.imooc.dataobject.mapper")
@EnableCaching
public class SellApplication {

4.

之前是,直接在Mapper类上面添加注解@Mapper,这种方式要求每一个mapper类都需要添加此注解,麻烦。

通过使用@MapperScan可以指定要扫描的Mapper类的包的路径

5.@Aspect   @Pointcut AOP

参照sell项目SellerAuthorizeAspect

6.@ConfigurationProperties
spring-boot 提供该注解将配置文件的值映射到类上使用

使用原则:在某个业务逻辑中需要获取一下配置文件中的某项值,使用@Value;如果专门编写了一个javaBean来和配置文件进行映射,我们就直接使用@ConfigurationProperties;

springboot @value和@configurationproperties注解的区别

7.idea安装lombok插件

@Data : 注解在类上, 为类提供读写属性, 此外还提供了 equals()、hashCode()、toString() 方法
@Getter/@Setter : 注解在类上, 为类提供读写属性
@ToString : 注解在类上, 为类提供 toString() 方法
@Slf4j : 注解在类上, 为类提供一个属性名为 log 的 log4j 的日志对象
@Log4j : 注解在类上, 为类提供一个属性名为 log 的 log4j 的日志对

8.@Valid在controller中使用

@Validated和@Valid区别

@Validated

用于验证注解是否符合要求,直接加在变量user之前,在变量中添加验证信息的要求,当不符合要求时就会在方法中返回message 的错误提示信息。

BuyerOrderController中

9.@ControllerAdvice 拦截异常并统一处理

@ExceptionHandler(value = SellerAuthorizeException.class)
@ResponseStatus(HttpStatus.FORBIDDEN)

sell中SellExceptionHandler类

10.

<!-- org.apache.commons.lang3.StringUtils-->
<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-lang3</artifactId>
    <version>3.5</version>
</dependency>

11.拦截器在springboot中使用

@Configuration
public class WebConfig  extends WebMvcConfigurerAdapter{
   
   @Autowired
   UserArgumentResolver userArgumentResolver;
   
   @Autowired
   AccessInterceptor accessInterceptor;
   
   @Override
   public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
      argumentResolvers.add(userArgumentResolver);
   }
   
   @Override
   public void addInterceptors(InterceptorRegistry registry) {
      registry.addInterceptor(accessInterceptor);
   }
   
}

 

12.@Configuration和@Bean配合相当于配置文件

 

 

 

 

 

 

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值