当前位置: 首页 > news >正文

温州多语言网站建设seo算法培训

温州多语言网站建设,seo算法培训,设计素材网站模板,如何做网站卖衣服一、MySQL事务回顾 二、Spring事务管理 Spring框架的第一大核心:IOC控制反转 在DeptServiceImpl下删除部门方法下新加一个删除员工信息的操作,注意:此时的id是部门id。 1、问题分析 2、Transactional-Spring事务管理 一般是在Service实现类的…

一、MySQL事务回顾

image-20230519095555441

二、Spring事务管理

Spring框架的第一大核心:IOC控制反转

image-20230519093354025 image-20230519095638521

在DeptServiceImpl下删除部门方法下新加一个删除员工信息的操作,注意:此时的id是部门id。

image-20230519094945355 image-20230519095242773

1、问题分析

image-20230519095758677

2、@Transactional-Spring事务管理

image-20230519100017409

一般是在Service实现类的方法上加Transactional注解


执行多次数据访问的增删改操作上需要用到事务

image-20230519101345091 image-20230519101246113 image-20230519101218784 image-20230519101511274 image-20230519102942049

三、Spring事务进阶

image-20230519103046587

1、rollbackFor

image-20230519103807812

Int i = 1/0 是属于运行时异常

image-20230519104208589 image-20230519110308309

这是service层,需要继续往上抛异常


image-20230519110226786 image-20230519110436516

默认情况下只有运行时异常才会进行事务回滚

2、propagation

image-20230519133216508 image-20230519133416156 image-20230519133437828 image-20230519133449823

因为我们需要解散部门时,无论成功还是失败,都要记录操作日志,所以需要用到@Transaction的REQUIRES_NEW的属性,来新建一个事务

image-20230519133808397

pojo/DeptLog

package com.itheima.pojo;import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;import java.time.LocalDateTime;@Data
@NoArgsConstructor
@AllArgsConstructor
public class DeptLog {private Integer id;private LocalDateTime createTime;private String description;
}

DeptServiceImple

package com.itheima.service.impl;import com.itheima.mapper.DeptLogMapper;
import com.itheima.mapper.DeptMapper;
import com.itheima.mapper.EmpMapper;
import com.itheima.pojo.Dept;
import com.itheima.pojo.DeptLog;
import com.itheima.service.DeptLogService;
import com.itheima.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;import java.time.LocalDateTime;
import java.util.List;
import java.util.logging.LogManager;@Service
public class DeptServiceImpl implements DeptService {@Autowiredprivate DeptMapper deptMapper;@Autowiredprivate EmpMapper empMapper;//  删除部门id的同时,需要删除与部门id关联的员工信息@Autowiredprivate DeptLogService deptLogService;//  添加日志对象注入//    @Autowired
//    private DeptLogMapper deptLogMapper;/*1、查询操作* *///        实现方法public List<Dept> list(){List<Dept> deptList = deptMapper.select();return deptList;}/*2、删除指定id* */@Transactional(rollbackFor = Exception.class)  //  交给了Spring进行事务管理,将所有异常进行事务处理@Overridepublic void deleteById(Integer id) throws Exception{try {deptMapper.deleteById(id);  //  删除部门idint i = 1/0;
//            if (true){throw new Exception("出错了...");}empMapper.deleteById(id);    //  删除员工信息} finally {//        记录日志描述DeptLog deptLog = new DeptLog();deptLog.setCreateTime(LocalDateTime.now());deptLog.setDescription("执行了解散部门的操作,此次解散的部门id是"+id);deptLogService.insert(deptLog);/***可以不用写DeptLogService和DeptServiceImpl,直接写一个DeptLogMapper然后交给IOC控制器,再在* 这个实现类中注入DeptLogMapper的对象直接调用insert方法,在方法前加入* @Transactional(propagation = Propagation.REQUIRES_NEW)*/
//            deptLogMapper.insert(deptLog);}}/*3、新增部门*/public void add(Dept dept){dept.setCreateTime(LocalDateTime.now());dept.setUpdateTime(LocalDateTime.now());deptMapper.insert(dept);}/*根据ID查询*/public Dept selectById(Integer id){Dept dept = deptMapper.selectById(id);return dept;}@Override/*更新部门名称*/public void update(Dept dept) {dept.setUpdateTime(LocalDateTime.now());dept.setCreateTime(LocalDateTime.now());deptMapper.update(dept);}
}

DpetLogService

package com.itheima.service;import com.itheima.pojo.DeptLog;public interface DeptLogService {void insert(DeptLog deptLog);
}

DeptLogServiceImpl

package com.itheima.service.impl;import com.itheima.mapper.DeptLogMapper;
import com.itheima.pojo.DeptLog;
import com.itheima.service.DeptLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;@Service
public class DeptLogServiceImpl implements DeptLogService {@Autowiredprivate DeptLogMapper deptLogMapper;//    开启一个新事务@Transactional(propagation = Propagation.REQUIRES_NEW)@Overridepublic void insert(DeptLog deptLog) {deptLogMapper.insert(deptLog);}
}

DeptLogMapper

package com.itheima.mapper;import com.itheima.pojo.DeptLog;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;@Mapper
public interface DeptLogMapper {@Insert("insert into dept_log(create_time, description) VALUES (#{createTime},#{description})")
//    @Transactional(propagation = Propagation.REQUIRES_NEW)public void insert(DeptLog deptLog);
}

四、AOP基础-Spring框架的第二大核心

AOP概述

image-20230519144922918 image-20230519144936888

AOP快速入门

image-20230519160123162
package com.itheima.aop;import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;@Slf4j
@Component  // 交给IOC容器
@Aspect     // 表示这个是AOP类
public class TimeAspect {
//  当前共性功能应该加在哪些方法上@Around("execution(* com.itheima.service.*.*(..))") //切入点表达式public void recordTime(ProceedingJoinPoint joinPoint) throws Throwable {
//        1、获取方法运行开始时间long begin = System.currentTimeMillis();
//        2、运行原始方法,o是原始方法的返回值Object o = joinPoint.proceed();
//        3、获取方法结束运行结束时间long end = System.currentTimeMillis();
//        计算方法耗时
//        joinPoint.getSignature():原始方法的签名log.info(joinPoint.getSignature()+"方法耗时:{}ms",end-begin);}
}
image-20230519160259797

image-20230519160606985

image-20230519161148430

小结

image-20230519161318405

五、AOP基础-核心概念

AOP核心概念

image-20230519164857827

AOP执行流程

image-20230519164715406

小结

连接点JoinPoint能够被AOP所控制的方法
切入点PointCut实际被AOP控制的方法,通过切入点表达式
通知Advice将所有共性功能封装起来的方法
切面Aspect描述通知与切入点之间的对应关系
目标对象Target通知所对应的对象
image-20230519170101230

六、AOP进阶

image-20230519171259826

1、通知类型

image-20230519174120073 image-20230519174551031

切入点表达式抽取

image-20230519174957352 image-20230519175305641

小结

image-20230519175400903

2、通知顺序

image-20230523105728939 image-20230523110339906

3、切入点表达式

execution

image-20230523110701548 image-20230523113303585 image-20230523151557536 image-20230523151743153

MyAspect6.java

package com.itheima.aop;import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;@Component
@Slf4j
@Aspect
public class MyAspect6 {
//    @Pointcut("execution(public void com.itheima.service.impl.DeptServiceImpl.delete(java.lang.Integer))")
//    @Pointcut("execution(void com.itheima.service.DeptService.delete(java.lang.Integer))")//基于接口描述
//    @Pointcut("execution(void delete(java.lang.Integer))")包名.类名不建议省略,匹配的范围过大,影响匹配的效率
//    @Pointcut("execution(* com.itheima.service.DeptService.*(*))")//匹配返回值为任意,DeptService接口下所有方法任意类型的一个参数
//    @Pointcut("execution(* com..DeptService.get(*))")//匹配返回值为任意,com包下任意子包中DeptService接口/类下get方法,为任意类型的一个参数@Pointcut("execution(* com.itheima.service.DeptService.delete(java.lang.Integer)) ||"+"execution(* com.itheima.service.DeptService.list())")//匹配前面一个或者后面任意一个public void pt(){}@Before("pt()")public void before(){System.out.println("before ...6");}
}

@annotation

image-20230523153020619

MyLog

package com.itheima.aop;import lombok.extern.slf4j.Slf4j;import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;@Retention(RetentionPolicy.RUNTIME)//该注解表示注解的生命周期
@Target(ElementType.METHOD)//表示该注解作用在哪一部分
public @interface MyLog {
}

MyAspect7

package com.itheima.aop;import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;@Slf4j
@Component
@Aspect
public class MyAspect7 {@Pointcut("@annotation(com.itheima.aop.MyLog)")public void pc(){}@Before("pc()")public void func(){log.info("MyAspect7...");}
}
image-20230523160655953

只需要在想要匹配的方法上加@MyLog注解就可以调用通知方法

小结

image-20230523161211924

4、连接点

image-20230523162227036

MyAspect8

package com.itheima.aop;import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;import java.util.Arrays;@Component
@Slf4j
@Aspect
public class MyAspect8 {@Pointcut("execution(* com.itheima.service.DeptService.*(..))")public void pt(){}@Before("pt()")public void before(JoinPoint joinPoint){log.info("before....");}@Around("pt()")public Object around(ProceedingJoinPoint joinPoint) throws Throwable {log.info("MyAspect8 around before...");//        1、获取目标类名String className = joinPoint.getTarget().getClass().getName();log.info("目标类名:{}",className);//        2、获取目标方法签名Signature signature = joinPoint.getSignature();log.info("目标方法签名:{}",signature);//        3、获取目标方法名String signatureName = joinPoint.getSignature().getName();log.info("目标方法名:{}",signatureName);//        4、获取目标方法运行参数Object[] args = joinPoint.getArgs();String arg = Arrays.toString(args);log.info("目标方法参数:{}",arg);//        5、执行原始方法,获取返回值Object result = joinPoint.proceed();log.info("目标方法的返回值:{}",result);log.info("MyAspect8 after ...");return result;}@After("pt()")public void after(){log.info("after...");}
}

测试类

package com.itheima;import com.itheima.service.DeptService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;@SpringBootTest
class SpringbootAopQuickstart1ApplicationTests {@AutowiredDeptService deptService;@Testpublic void test1(){deptService.delete(10);}@Testpublic void test2(){deptService.list();}
}

执行delete之后

image-20230523165601716

只有环绕通知才可以执行原始方法

前置通知在原始方法执行前运行,后置通知在原始方法执行后运行

七、AOP案例

image-20230523171728414

image-20230523172429155

1、准备工作

<!--AOP依赖-->
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-aop</artifactId><version>2.7.1</version>
</dependency>
-- AOP案例
-- 操作日志表
create table operate_log(id int unsigned primary key auto_increment comment 'ID',operate_user int unsigned comment '操作人ID',operate_time datetime comment '操作时间',class_name varchar(100) comment '操作的类名',method_name varchar(100) comment '操作的方法名',method_params varchar(1000) comment '方法参数',return_value varchar(2000) comment '返回值',cost_time bigint comment '方法执行耗时, 单位:ms'
) comment '操作日志表';

sql表格对应的实体类

package com.itheima.pojo;import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;import java.time.LocalDateTime;@Data
@NoArgsConstructor
@AllArgsConstructor
public class OperateLog {private Integer id; //IDprivate Integer operateUser; //操作人IDprivate LocalDateTime operateTime; //操作时间private String className; //操作类名private String methodName; //操作方法名private String methodParams; //操作方法参数private String returnValue; //操作方法返回值private Long costTime; //操作耗时
}

2、编码

image-20230524154418945

LogAspect.java

package com.itheima.aop;import com.alibaba.fastjson.JSONObject;
import com.itheima.mapper.OperateLogMapper;
import com.itheima.pojo.OperateLog;
import com.itheima.utils.JwtUtils;
import io.jsonwebtoken.Claims;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;
import java.util.Arrays;@Component
@Slf4j
@Aspect //切面类
public class LogAspect {@Autowired//用于获取jwt令牌private HttpServletRequest httpServletRequest;@Autowiredprivate OperateLogMapper operateLogMapper;@Around("@annotation(com.itheima.anno.Log)")//切点表达式public Object recordLog(ProceedingJoinPoint joinPoint) throws Throwable {
//        1、获取操作人ID,当前登录员工id,这一步需要用到jwt令牌,在Header中String jwt = httpServletRequest.getHeader("token");
//        解析jwt令牌Claims claims = JwtUtils.parseJwt(jwt);Integer operateUser  = (Integer) claims.get("id");//        2、操作时间LocalDateTime operateTime = LocalDateTime.now();//        3、操作类名String className = joinPoint.getTarget().getClass().getName();//        4、操作方法名String methodName = joinPoint.getSignature().getName();//        5、操作方法参数Object[] args = joinPoint.getArgs();String methodParams = Arrays.toString(args);//         获取方法开始时间long begin = System.currentTimeMillis();
//        6、操作方法返回值,转换为json格式的字符串保存起来Object result = joinPoint.proceed();String returnValue = JSONObject.toJSONString(result);
//        获取结束时间long end = System.currentTimeMillis();//        7、操作耗时long costTime = end - begin;//        将日志内容插入到表中OperateLog operateLog = new OperateLog(null,operateUser,operateTime,className,methodName,methodParams,returnValue,costTime);operateLogMapper.insert(operateLog);log.info("AOP操作日志:{}",operateLog);return result;//返回的是执行方法的返回值}
}

OperateLogMapper

package com.itheima.mapper;import com.itheima.pojo.OperateLog;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;@Mapper
public interface OperateLogMapper {@Insert("insert into operate_log (operate_user, operate_time, class_name, method_name, method_params, return_value, cost_time) " +"values (#{operateUser}, #{operateTime}, #{className}, #{methodName}, #{methodParams}, #{returnValue}, #{costTime});")public void insert(OperateLog operateLog);}

注意

image-20230524155552227

文章转载自:
http://damnum.rzgp.cn
http://puffiness.rzgp.cn
http://patriarchy.rzgp.cn
http://ostracoderm.rzgp.cn
http://stratigraphic.rzgp.cn
http://fanback.rzgp.cn
http://republican.rzgp.cn
http://carrying.rzgp.cn
http://fibrinolysis.rzgp.cn
http://proboscidean.rzgp.cn
http://further.rzgp.cn
http://assumpsit.rzgp.cn
http://unsoiled.rzgp.cn
http://caliche.rzgp.cn
http://henchman.rzgp.cn
http://dempster.rzgp.cn
http://pianette.rzgp.cn
http://clothing.rzgp.cn
http://prosage.rzgp.cn
http://stapes.rzgp.cn
http://wimshurst.rzgp.cn
http://transferential.rzgp.cn
http://debauchery.rzgp.cn
http://doa.rzgp.cn
http://springe.rzgp.cn
http://butanone.rzgp.cn
http://technically.rzgp.cn
http://symbolization.rzgp.cn
http://commonplace.rzgp.cn
http://droplight.rzgp.cn
http://qom.rzgp.cn
http://demonomancy.rzgp.cn
http://occur.rzgp.cn
http://intransigency.rzgp.cn
http://semidivine.rzgp.cn
http://preconquest.rzgp.cn
http://rhumbatron.rzgp.cn
http://rurban.rzgp.cn
http://calvinistic.rzgp.cn
http://negation.rzgp.cn
http://asshur.rzgp.cn
http://nounal.rzgp.cn
http://versitron.rzgp.cn
http://auditorship.rzgp.cn
http://thigmotropism.rzgp.cn
http://orchil.rzgp.cn
http://jacob.rzgp.cn
http://polynya.rzgp.cn
http://chromatolytic.rzgp.cn
http://batik.rzgp.cn
http://puppetoon.rzgp.cn
http://meatball.rzgp.cn
http://rustler.rzgp.cn
http://ambiversion.rzgp.cn
http://strict.rzgp.cn
http://aspartate.rzgp.cn
http://exhort.rzgp.cn
http://dynatron.rzgp.cn
http://mshe.rzgp.cn
http://side.rzgp.cn
http://exhilaratingly.rzgp.cn
http://biogeocoenose.rzgp.cn
http://quarterfinalist.rzgp.cn
http://bustling.rzgp.cn
http://oolitic.rzgp.cn
http://sicilian.rzgp.cn
http://enamor.rzgp.cn
http://atmospherical.rzgp.cn
http://diphtheria.rzgp.cn
http://combat.rzgp.cn
http://hotbrained.rzgp.cn
http://crissum.rzgp.cn
http://uglify.rzgp.cn
http://lamprey.rzgp.cn
http://dichasial.rzgp.cn
http://declasse.rzgp.cn
http://flawless.rzgp.cn
http://massacre.rzgp.cn
http://colourbred.rzgp.cn
http://sclerotoid.rzgp.cn
http://ho.rzgp.cn
http://verily.rzgp.cn
http://birdseed.rzgp.cn
http://lyase.rzgp.cn
http://hypothecary.rzgp.cn
http://poddy.rzgp.cn
http://breechless.rzgp.cn
http://retinopathy.rzgp.cn
http://crenelation.rzgp.cn
http://tetched.rzgp.cn
http://halting.rzgp.cn
http://abernethy.rzgp.cn
http://repolish.rzgp.cn
http://perichondrium.rzgp.cn
http://craniectomy.rzgp.cn
http://odu.rzgp.cn
http://festive.rzgp.cn
http://agitational.rzgp.cn
http://madid.rzgp.cn
http://thermoregulation.rzgp.cn
http://www.dt0577.cn/news/62298.html

相关文章:

  • 成都住建局官网登录入口查询百度网盘优化
  • 实训课网站开发个人小结谷歌搜索引擎google
  • 用vue做网站一般用什么组件库怎么做网络推广最有效
  • 西安网站设计方案北京cms建站模板
  • 在哪个网站可以做图文合并注册平台
  • 怎么上传自己做的网站口碑营销例子
  • 青岛网站制作公司排名百度站长工具seo查询
  • php个人网站源码下载每日财经要闻
  • 公司网站的宣传栏怎么做定制网站+域名+企业邮箱
  • wordpress编辑器 填满如何获取网站的seo
  • php空间放两个网站网络推广营销软件
  • 不花钱的网站怎么做外贸做网站公司哪家好
  • 建立网站的软件下载广告开户南京seo
  • 织梦网站怎么做seo58同城如何发广告
  • 南京电子商务网站开发公司找做网站的公司
  • iis 网站目录权限设置百度系app
  • 网站内容侵权 怎么做西安seo哪家好
  • 专做3dmax的网站百度网站搜索排名
  • 升阳广州做网站公司西安百度百科
  • 龙华哪有做网站设计seo怎么优化关键词排名
  • 宁波网站推广方法网站友情链接美化代码
  • 当今做哪个网站致富东莞排名优化团队
  • java web网站开发报告全网推广费用
  • 信息手机网站模板下载软件站长工具网站备案查询
  • 一个公司可以做两个网站么网络推广可做哪些方面
  • 快速网站开发淘宝关键词优化软件
  • 如何做电子书网站电商网站开发需要多少钱
  • 都江堰做网站网络营销岗位描述的内容
  • 网页制作模板简单如何优化网站推广
  • 做彩票网站推广犯法吗百度app浏览器下载