zoukankan      html  css  js  c++  java
  • 课时1:Spring环境搭建、STS工具、第一个Spring程序

    .1)概要以及介绍

      1.2002 作者 Rod Jonnon 发布了一篇文章<Expoer One-toOne j2eedvelopment and Design>

      2.2003年根据这篇文章产生了一些感悟 产生了Spring

      3.spring最基础的核心AOP IOC

      4.经过了18年的的洗礼衍生出很多框架 Spring Data,Spring Boot ,Spring Cloud,Spring Framework,Springsocial

    .2)IOC:控制反转 (DI:依赖注入)

      1.搭建Spring的环境

        1.1 导入spring的依赖jar包

      <!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-context</artifactId>
          <version>4.3.9.RELEASE</version>
        </dependency>
         <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
        <dependency>
          <groupId>org.projectlombok</groupId>
          <artifactId>lombok</artifactId>
          <version>1.18.10</version>
          <scope>provided</scope>
        </dependency>

        1.2 编写配置文件

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
    
    </beans>

      2.开发Spring程序(IOC)

        2.1 编写配置文件

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
    <bean id="student" class="net.bdqn.hbz.pojo.Student">
        <property name="stuno" value="1"></property>
        <property name="stuName" value="zs"></property>
        <property name="stuAge" value="24"></property>
    </bean>
    </beans>

          2.1.1 id:唯一标识符 class:指定类的路径

          2.1.2 property标签 :代表该class的属性

            2.1.2.1 name:属性名称

            2.1.2.1 value :属性值

        2.2 通过bean的id来获取一个对象

    //创建上下文对象
            ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");
            //通过bean的id来获取对象
            Student student =(Student) context.getBean("student");
            System.out.println(student);

      3.这样写的一些分析以及好处

        3.1 不需要new

        3.2 对象属性的赋值

        3.3 在applicationContext.xml中产生的对象,被spring放入了一个 称为Spring IOC容器里面

  • 相关阅读:
    SQL 高级查询(层次化查询,递归)
    IntelliJ IDEA添加注释常用的快捷键
    java配置环境变量
    Python单例模式的4种实现方法 ++ redis pool的一种单例实现方式
    MYSQL安装配置文件my-small.ini、my-medium.ini、my-large.ini、my-huge.ini文件的作用
    flask中使用flask-sqlalchemy
    Python向Mysql写入时间类型数据
    [慢查优化]慎用MySQL子查询,尤其是看到DEPENDENT SUBQUERY标记时
    Cocos2d-x 3.2 创建新应用
    In-App Purchase Programming Guide----(六) ----Working with Subscriptions
  • 原文地址:https://www.cnblogs.com/thisHBZ/p/12484316.html
Copyright © 2011-2022 走看看