spring相关笔记
发布日期:2021-05-10 17:18:22 浏览次数:21 分类:精选文章

本文共 5446 字,大约阅读时间需要 18 分钟。

Spring IOC AOP���������������������

������Spring������������

������������������Spring���������������������������������������������������������������������������

  • ���������������JAR���

    ������������������������������������������Spring Framework jar������

    https://maven.springframework.org/release/org/springframework/spring/

    ���������������������������jar������

    • spring-core-4.3.9.RELEASE.jar
    • spring-beans-4.3.9.RELEASE.jar
    • spring-context-4.3.9.RELEASE.jar
    • spring-aop-4.3.9.RELEASE.jar
    • spring-expression-4.3.9.RELEASE.jar
    • commons-logging-1.2.6.jar������������������
  • ������Spring Tool Suite

    ���������������������������������������������Spring Tool Suite���STS������

    • ������Spring Tools Site
    • ���������������STS���������STS������������������������������Spring������������������������������
  • ������Spring������������

    Spring���������������������������������������������������bean���������������������������������������������

  • ������STS������������������

    • ������������������Spring������������������������applicationContext.xml
    • ���STS���������������������������Spring Tools > New Spring... > ApplicationContext File
  • ������������������������

    ������������������IDE���������������������applicationContext.xml���������������������������������������������

  • ������Spring������������

    1. IOC���������������������������������

    IOC������������������������������������������������������������������������

  • ������ApplicationContext������

    ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
  • ���������������������

    • ������������������������������String������������value������
    • ���������������������ref���������������������bean
    • ���������List���Set���Map������������property������
    ������
    ������
    • ������������������������constructor-arg������
    • ���������������������������p:������������������
  • 2. AOP������������������������

    AOP������������������������������������������������������������������

  • AOP���������������

    • ���������Aspect���
    • ������������Pointcut���
    • ���������Advice���
      ���������������������������������������������������
  • ������AOP���������

    • ���������������������Spring��� <aop:config> ������
    • ���������������������@Aspect������
    @Aspect
    public class LogAspect {
    // ���������������
    @Pointcut("execution(public void com.example.service.impl StudentServiceImpl.addStudent())")
    public void logBefore(JoinPoint joinPoint) {
    System.out.println("���������������������" + joinPoint.getArgs()[0]);
    }
    }
  • ������������������

    @Around("@umble() profit(@field String userId)")
    public String logAround(JoinPoint joinPoint, @Field String userId) {
    System.out.println("���������������" + joinPoint.getSignature().getName());
    System.out.println("���������" + Arrays.toString(joinPoint.getArgs()));
    return joinPoint.proceed();
    }
  • ������������������

    ���������������������������������������Spring������������������������������������������������

  • ������������������

    ���Spring������������������������������������

    ������ <beans> ������������������autowire������default-autowire="byName"���

  • ������������������

    ���Service������������������@Transactional���������

    @Service
    public class StudentService {
    @Transactional(readOnly = false)
    public void addStudent(Student student) {
    // ���������������
    }
    }
  • ������Spring���MyBatis������

    1. ������������

  • ������jar���

    ������������������������������������

    • spring-tx-4.3.9.RELEASE.jar
    • mybatis-3.2.5.jar
    • mysql-connector-java-5.1.48.jar
    • commons-pool-1.2.jar
    • commons-dbcp-1.2.2.jar
  • ���������������

    ���Spring���������������������������������

  • ������SqlSessionFactory

    Spring������MyBatis������������������SqlSessionFactory���SqlSession���

  • ������Mapper������

    ���Spring���������������MyBatis���Mapper���������

  • 2. MyBatis CRUD������

    ���Service���������CRUD���������

    public interface StudentRepository {
    @Select("SELECT * FROM student WHERE student_no = #{studentNo}")
    Student selectStudentByNo(@Param("studentNo") String studentNo);
    @Insert("INSERT INTO student (student_no, student_name) VALUES (#{studentNo}, #{studentName})")
    void insertStudent(Student student);
    // ������CRUD������...
    }

    ������Spring Web������������

    ������Spring������Web���������

  • ������������

    ������������������������������������������

    • spring-boot-starter-web-2.2.0.jar
    • spring-boot-starter-data-jpa-2.2.0.jar
    • spring-boot-starter-data.redis-2.2.0.jar
    • mysql-connector-java-5.1.48.jar
  • ���������������

    ���web.xml���������ContextLoaderListener���

    org.springframework.web.context.ContextLoaderListener

    ���������Spring���������������

    contextConfigLocation
    classpath:applicationContext.xml
  • ������������������

    ������������������������������������������������������������������

    • applicationContext.xml������������������������������������������������������
    • applicationContext-Data.xml: ������������MyBatis������
    • applicationContext-Service.xml: ���������bean������
    • applicationContext-Controller.xml: ���ashes���bean������
  • ���������������������������������������������������������������Spring������������������Spring���������������������������������AOP������������������MyBatis������������������������������������������Spring������������������������������������������������������������������

    上一篇:HTML5和CSS3核心笔记
    下一篇:mybatis相关笔记

    发表评论

    最新留言

    第一次来,支持一个
    [***.219.124.196]2025年04月27日 00时58分10秒