SpringBoot brief

A, springboot is what?

 

1. What is springboot?


1.1springboot is a lightweight framework spring ecosystem, in other words springboot is spring, is a derivative version of spring


1.2 If it is spring framework, the project set up is completed, can not implement any code that is to say spring is no way to help developers to connect to the database, the database do CRUD, there is no way to automatically shiro integrated in, the manual requires developers write xml configuration file, their own integration

 

1.3springboot is actually a lot better spring integrated framework, according to a standardized configuration can be written directly springboot provided, no longer need to write xml configuration file, springboot official explanation given is to kill xml file, use Java code to write configuration by Java class instead xml

 

Second, why use?

2. Why use springboot instead of spring?
Fool-developed and less configuration, reducing the standard developers, low-level developers can also write business logic, no longer need to understand the integration and consolidation of internal operating principles and framework

 

Third, the actual operation?

3.1 created maven project, in pro.xml file, spring-boot-starter-parent introduced in.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.aaa</groupId>
    <artifactId>20190815-springboot</artifactId>
    <version>SNAPSHOT-1.0 </ Version > 

        <-! 1. Add the spring as the parent project 
            2. At this point the project has become a sub-project under the spring items. 
        -> 
    < parent > 
        < the groupId > org.springframework.boot </ the groupId > 
        < the artifactId > Spring-Boot-parent-Starter </ the artifactId > 
        < Version > 1.5.22.RELEASE </ Version > 
    </ parent > 
    < Dependencies > 
    <! - 
        defines a number of starter in springboot, each starter has a different role

        web-start: the introduction of basic environmental project running 

            tomcat: tomcat final springboot automatically integrated into the project, eliminating the need for external tomcat to boot 
            various notes 
                @Controller 
                @Service 
                @ RequestMapping 
                @ResponseBody 
    -> 
    < dependency > 
        < the groupId > org.springframework.boot </ the groupId > 
        < the artifactId > Spring-Boot-Starter-Web </ the artifactId > 
    </ dependency > 
    </ Dependencies > 
</ Project > 

        <-! & lt ;!–-> 
        <! - did not actually integrated in springboot in mybatis, following jar package dependencies, is mybatis companies themselves in order to integrate springboot provided, not springboot comes -> 
        <! - it needs from maven download the jar package -> 
        <-! & ndash; & gt; -> 
        <-! <dependency> -> 
        - <! org.mybatis.spring.boot </ the groupId> <the groupId> -> 
        < ! - <the artifactId> MyBatis-Spring-Boot-Starter </ the artifactId> -> 
        <-! <Version> 1.3.0 </ Version> -> 
        <-! </ dependency> ->

 

 

 

3.2 Creating import category in java source files, the new package, at the root of the package, the establishment of ApplicationRun.

Package com.aaa.zxf.springboot;
 / * 
* 1.springboot entry method 
* 
* 2. The basic shape architecture. 
* 
* 3. @ SpringBootApplication annotation 
* Configuration on springboot required 
* and ApplicationRun class, the class is identified as the inlet of the entire project. 
*note! 
* This class must be placed on the floor all business. 
* That is, at least needs to be in packet springboot 
* 
* 4. Final springboot is operated according to SpringApplication.run 
* * / 
Import org.springframework.boot.SpringApplication;
 Import org.springframework.boot.autoconfigure.SpringBootApplication; 

// automatic loading inlet springboot class 
@SpringBootApplication
 public  class ApplicationRun {
     public static void main(String[] args) {
        SpringApplication.run(ApplicationRun.class,args);
    }
}

 

 

3.3 in the package, the package build controller, the controller establishing background

Package Penalty for com.aaa.zxf.springboot.Controller;
 Import org.springframework.web.bind.annotation.RequestMapping;
 Import org.springframework.web.bind.annotation.RestController; 

/ * 
* 1.RestController 
* the entire Controller, are added @ResponeBody comment. 
2.Controller * 
* direct return to the page, can not handle ajax requests need to be addressed, but also the ajax request, but also add ResponseBody Notes 
* * / 
@RestController 
public  class TestController { 
    @ RequestMapping ( "/ Demo" )
     public String the Test () {
         return "check the effect of springboot." ; 
    } 

}

 

 

3.4 to run the project, type localhost in the browser: 8080 / demo to test whether or not to take the data.

 

Fourth, the analytical principle?

 

4.1 In its own maven project, the introduction of spring-boot-starter-parent, this time under his own engineering project is Sringboot

A sub-project.

 

4.2 parent project introduced springbootdependcies, his subprojects.

 

 

4.3 jar package defined in your project time, is equivalent, and then rewrite the parent class project in a jar, no version number.

 

Guess you like

Origin www.cnblogs.com/ZXF6/p/11362006.html
Recommended