SSH:Structs+Spring+Hibernate!

SSM:SpringMvc+Spring+Mybatis


官方文档:https://docs.spring.io/spring-framework/docs/4.3.9.RELEASE/spring-framework-reference/    --html---Distribution Zip Files


官方下载地址: http://repo.spring.io/release/org/springframework/spring


github:https://github.com/spring-projects/spring-framework


没有小叶子的点idea左上角File,然后点Project Structure,在点Modules模块,中间会出现你的项目,展开你的项目,项目里面会有spring这样的小叶子。在点中小叶子,右侧有+号,点击加号勾选里面的xml文件最后点右下角的apply应用就行了。

去maven仓库导包 ,导

Spring Web MVC(会帮你把其他的也导进来)


<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>5.3.9</version>

</dependency>

<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-jdbc</artifactId>
    <version>5.3.9</version>
</dependency>


Spring是一个轻量级的控制反转(IoC)和面向切面编程(AOP)的容器框架

控制反转,简单点说,就是创建对象的控制权,被反转到了Spring框架上。

优点:

开源的免费的框架(容器)

轻量级的、非入侵式的框架

控制反转(IOC)、面向切面编程(AOP)

支持事务的处理,对框架整合的支持


spring boot (快速开发的脚手架,可以快速开发单个微服务 ,和maven一样约定大于配置)

spring cloud(基于springboot实现的)


憋端:配置地狱(直到springboot出来解放)



2.IOC理论推导(src散掉建model)

https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#spring-core

不用管理对象的创建 耦合性大大降低  主动权给调用的用户  控制反转

利用set方法注入



使用

1.导包

pom.xml

2.配置文件

pom.xml

 <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>5.3.9</version>
        </dependency>

3.使用

package com.kuang.pojo;

public class Hello {
    private String str;

    public String getStr() {
        return str;
    }

    public void setStr(String str) {
        this.str = str;
    }

    @Override
    public String toString() {
        return "Hello{" +
                "str='" + str + '\'' +
                '}';
    }
}


resources--beans.xml


 <bean id="hello" class="com.kuang.pojo.Hello">
        <!--ref:引用spring容器中创建好的对象
        value:基本数据类型-->
        <property name="str" value="Spring"/>
    </bean>
   //获取spring的上下文对像CPX就出来了
        //拿到spring容器
        ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
        //我们的对象现在都在Spring中管理了,我们要使用,直接去里面取出来就可以!
        Hello hello = (Hello) context.getBean("hello");
        System.out.println(hello.toString());








点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论
返回
顶部