美文网首页
1、Spring起步练习

1、Spring起步练习

作者: m小萌同学 | 来源:发表于2019-02-26 15:51 被阅读0次

一、后端开发的概念和技术栈

1.1 什么是后端开发

什么是后端开发-知乎

  • JavaWeb掌握什么?

  • 网络通信协议:http
  • 服务器:tomcat(开源) jetty(嵌入式) weblogic(商用 性能出色) ngix apache
  • 云服务器:阿里云 腾讯云
  • serlet、过滤器、监听器
  • 其他:跨域、负载均衡、缓存、日志、git、maven

1.2 Java后端技术图谱

image

二、Java EE概念

  • Java EE,Java 平台企业版,之前称为J2EE,2018年2月26日Eclipse基金会社区正式将Java EE更名为 Jakarta EE。用来开发B/S架构软件。Java EE 平台目前已经发展到了第8个大版本。

  • JavaEE 号称有十三种核心技术。它们分别是:JDBCJNDIEJB、RMI、ServletJSP、XML、JMS、Java IDL、JTS、JTA、JavaMail和JAF。

Java EE从入门到精通

三、Spring框架特点及构成

  • 特点:化繁为简

  1. 轻量级IoC容器(最重要的两个特性之一)
  2. 采用AOP编程方式(最重要的两个特性之一)
  3. 大量使用批注,简化了配置
  4. 避免重复“造轮子”,减少代码重复使用
  • 构成

Spring构成

四、Spring的起步练习步骤

1. 准备maven环境,并在idea中进行配置
  • setting配置,指定阿里云镜像

    apache-maven-3.5.4\apache-maven-3.5.4\conf\settings.xml

TIM图片20190226151757.png
  • 注意:路径不能有中文,要简单
  • 配置环境
    file-OtherSettings-Settings for new project-buld,excution,deployment-nuld Tools-Maven(不展开,点单词)-Maven home-D\tools\apache maven 3.5.4 User settings file -Override(打钩) Local repository-D\maven_jar
  • maven_jar下载框架
2. 建立项目,并添加maven支持
3. 在pom中添加SpringContext依赖
4. 编写HelloWorld类
5. 编写beans.xml文件,注入一个bean并传值
6. 编写主类,读入配置文件中的bean并调用方法
7. 观察运行结果
  • Student和Phone练习

Student类
package com.soft1721.spring.hello;
public class student {
    private String name;
    private int age;
    private Phone phone;
    public Phone getPhone() {
        return phone;
    }
    public void setPhone(Phone phone) {

        this.phone = phone;
    }
    public student() {
    }
    public student(String name, int age) {
        this.name = name;
        this.age = age;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
    @Override
    public String toString() {
        return "student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
Phone类
package com.soft1721.spring.hello;
public class Phone {
    private String brand;
    private String price;
    private String color;
    @Override
    public String toString() {
        return "Phone{" +
                "brand='" + brand + '\'' +
                ", price='" + price + '\'' +
                ", color='" + color + '\'' +
                '}';
    }
    public Phone(String brand, String price, String color) {
        this.brand = brand;
        this.price = price;
        this.color = color;
    }
    public void setBrand(String brand) {
        this.brand = brand;
    }
    public void setPrice(String price) {
        this.price = price;
    }
    public void setColor(String color) {
        this.color = color;
    }
    public String getBrand() {
        return brand;
    }
    public String getPrice() {
        return price;
    }
    public String getColor() {
        return color;
    }
}
StudentAPP类
package com.soft1721.spring.hello;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class studentAPP {
    public static void main(String[] args) {
            ApplicationContext context = new ClassPathXmlApplicationContext("/beans.xml");
            student student = (student) context.getBean("student");
    System.out.println(student.getName()+student.getAge()+student.getPhone());
        }
}
beans.xml
<?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="helloWorld" class="com.soft1721.spring.hello.HelloWorld"/>
    <bean id="phone" class="com.soft1721.spring.hello.Phone">
        <constructor-arg name="brand" value="huawei"/>
        <constructor-arg name="color" value="浅艾蓝"/>
        <constructor-arg name="price" value="2799"/>
    </bean>
    <bean id="student" class="com.soft1721.spring.hello.student">
        <property name="age" value="20"/>
        <property name="name" value="Tom"/>
        <property name="phone" ref="phone"/>

        <!--<constructor-arg name="name" value="Tom"/>-->
        <!--<constructor-arg name="age" value="21"/>-->
    </bean>

</beans>

五、学习建议

  • 了解技术图谱——有全局观
  • 大量的demo练习——打好基础
  • 基于项目的学习——融会贯通,提升综合能力
  • 及时高效的笔记——markdown语法,简书记录
  • 版本控制和代码托管——git,github等
  • 部署使用——阿里云服务器、项目部署运用

六、零碎知识点

  • 快捷键:
    换行:ctrl+shift+上、下箭头
    idea常用快捷键
  • groupID:com.soft1721
    ArtifactID:spring
  • context:上下文
    aop:面向切面编程
    beans:对象管理
    core:核心
    expressio:表达式
  • 在Spring的beans.xml配置中,通过constructor-arg和property传值,同等条件下使用property。当属型类型为基本类型,如String、double,int,float等时用value,属性是对象时用ref
  • 代码侵入性强
    侵入性,一般指的是:使用一个新的技术不会或者基本不改变原有代码结构,原有代码不作任何修改即可。
    Spring是非侵入式框架。

相关文章

  • 1、Spring起步练习

    一、后端开发的概念和技术栈 1.1 什么是后端开发 什么是后端开发-知乎 JavaWeb掌握什么? 网络通信协议:...

  • 三.Spring起步练习

    一、起步练习 1.新建Package(com.soft1721.spring.hello),在resources根...

  • Spring Boot的第一个起步练习

    Spring Boot的第一个起步练习

  • Spring起步练习

    一、准备Maven环境,并在IDEA中进行配置 下载好Maven压缩包并解压,打开config文件夹中的setti...

  • 2 Spring起步练习

    1 准备Maven环境,并在IDEA中进行配置 下载的Maven压缩包解压,配置一下config文件夹中的sett...

  • 1 Spring起步

    一、后端开发的概念和技术栈 1.1 什么是后端开发 https://blog.csdn.net/o4dc8ojo7...

  • 1 Spring起步

    一、后端开发的概念和技术栈 1.1 什么是后端开发? https://blog.csdn.net/o4dc8ojo...

  • 四.Spring Boot 整合 Mybatis 进行CRUD

    1.建立好spring-boot-mybatis项目 依赖添加(其他依赖与起步练习项目相同) 建立好包 如图myb...

  • 读书总结《Spring实战》

    第1部分 Spring 基础 第1章 Spring 起步 Spring Boot 关键目录、文件 /src/mai...

  • 7 Spring Boot起步练习

    新建一个quickstart项目 过程:file-new-project-Empty-quickstart和F:\...

网友评论

      本文标题:1、Spring起步练习

      本文链接:https://www.haomeiwen.com/subject/qlzoyqtx.html