注解忽略Controller、再次讲解跨域问题、日志记录service层运行时间、注解实现mybatis的SQL语句输出

建议在controller层写CRUD时,注明类型,因为在swagger中才好生成对应的测试文档,否则会生成CRUD四个不同的测试文档请求。

当我们的controller层不想被swagger文档测试访问时,可以使用注解:

@ApiIgnore

 关于跨域的问题: 用户登录页面是放在本地的Tocat的目录webapps下的,后台服务是用idea运行的,此时用户登录向idea中的服务发起请求,由于是不同的两个服务器,出于安全的问题考虑,此时就会产生跨域的问题

需要整合自己的日志框架的前提是 剔除掉自身携带的日志框架

spring-boot-starter-logging
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
            <!--            通过exclusions标签进行部分依赖的排除-->
            <exclusions>
                <!--排除springboot默认使用logging-->
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>


我们可以通过logger日志来记录每一个service执行的时间,根据不同的执行时间划分不同的警告级别

@Aspect
@Component
public class ServiceLogAspect {

    static final Logger logger = LoggerFactory.getLogger(ServiceLogAspect.class);
    static final long ERRORTIME = 3000;
    static final long WARNTIME = 2000;

    @Around("execution(* com.imooc.service.impl..*.*(..))")
    public Object recodeTimeLog(ProceedingJoinPoint joinPoint) throws Throwable {
        logger.info("======= 开始执行 {}.{} =========", joinPoint.getTarget().getClass(),
                joinPoint.getSignature().getName());

        long begin = System.currentTimeMillis();
        Object result = joinPoint.proceed();
        long end = System.currentTimeMillis();
        long takeTime = end - begin;
        if (takeTime > ERRORTIME) {
            logger.error("======= 执行结束,耗时{} 毫秒 ========", takeTime);
        } else if (takeTime > WARNTIME) {
            logger.warn("======= 执行结束,耗时{} 毫秒 ========", takeTime);
        } else {
            logger.info("======= 执行结束,耗时{} 毫秒 ========", takeTime);
        }
        return result;
    }
    
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

你在狗叫什么、

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值