springboot的HelloWorld~~~

Mature directory structure Demo:

 

 

One:

  First springboot dependent on the introduction of the jar package maven project, then pom.xml configuration file:

<? xml Version = "1.0" encoding = "UTF-8"?> 
<Project xmlns = "http://maven.apache.org/POM/4.0.0"
xmlns: xsi = "HTTP: //www.w3 .org / 2001 / "the XMLSchema-instance
http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">: the xsi the schemaLocation = "
<modelVersion> 4.0.0 </ modelVersion>

<the groupId> com.aaa.fx </ the groupId>
<the artifactId> NewSpring </ the artifactId>
<version> the SNAPSHOT-1.0 </ version>

<-! spring provides a default version dependency library (springboot by its very nature is an integrated collection of a large number of commonly used spring spring package),
is to override the default jar package depends on this spring collection when writing such specific springbootjar package dependencies, without adding a version number ->
<parent >
<the groupId> org.springframework.boot </ the groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<Version> 1.5.22.RELEASE </ Version>
</ parent>

<Dependencies>
<dependency>
<the groupId> org.springframework.boot </ the groupId>
<the artifactId> Starter-Spring-Boot-Web </ the artifactId>
</ dependency>

<-! mybatis not been integrated in springboot, we are guided into this mybatis-springboot integration package is mybatis own integration ->
      <! - Note, if only to test the main method is commented out mybatisjar, otherwise not being given configuration data display source ->
<dependency>
<the groupId> org.mybatis.spring.boot </ the groupId>
<the artifactId> MyBatis-Spring-Boot-Starter </ the artifactId>
<Version> 1.3.0 </ Version >
</ dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
</dependency>
</dependencies>
</project>

 Method for springboot main jar package after complete introduction written:

com.aaa.fx.springboot Package; 


Import org.springframework.boot.Banner; 
Import org.springframework.boot.SpringApplication; 
Import org.springframework.boot.autoconfigure.SpringBootApplication; 

/ * * 
 * This class ApplicationRun inlet of class springboot the method upon which the entire springboot project launched 
 one of the main methods of keeping ApplicationRun * // this class must be placed on all the services normally performed 
 * at least this method into springboot directory 
 * @SpringBootApplication automatically loads all the required springboot configuration, and the ApplicationRun class (i.e. the added annotation category identifier) as the start springboot class 
 * / 

@SpringBootApplication 
public  class ApplicationRun { 

    public  static  void main (String [] args) {
 //         SpringApplication.run (ApplicationRun. class, args);
 //        Close banner display presentation file, first create a SpringApplication object class of the incoming reflected pseudo Application class type 
        SpringApplication springApplication = new new SpringApplication (ApplicationRun. Class );
         // Next banner file set in a closed state 
        springApplication.setBannerMode (Banner.Mode. OFF);
 //         run this SpringApplication newly created object 
        springApplication.run (args); 

    } 
}

Run the main method can be successful, then come to integrate the mybatis:

Create a new file in the resources package config, which creates a file named application.yml, configuration data source in this file:

# Configure tomcat, otherwise an error will integrate mybatis 
# Note 1 configuration need to add space before the configured value! ! ! 
# When looking tomcat configuration file will look first to the next config resources, if not find the resources to seek 

Server: 
  Port: 8081 # tomcat port number configuration 
  context -path: / Yuer # Configure tomcat map if you do not configure the default root path to " / " 
  # data source configuration: 
Spring: 
  DataSource: 
    Driver - class - name: com.mysql.jdbc.Driver 
    URL: JDBC: MySQL: // localhost: 3306 / TH 
    DATA- username: the root 
    data -password: the root

The configuration is complete access to our test Controller class, note that this need under the main method we have just written:

com.aaa.fx.springboot.controller Package; 

Import org.springframework.web.bind.annotation.RequestMapping; 
Import org.springframework.web.bind.annotation.RestController; 

/ * * 
 * @Controller 
 * direct return to the page, can not handle ajax request, if you need to handle ajax requests to add @ResponseBody comment 
 * @RestController 
 * are added directly to the notes under the @ResponseBody entire controller. 
 * / 
@RestController 
public  class the Controller { 

    @RequestMapping ( " / Test " )
     public String Test () {
         return  " This has Come INTO Change Effect! " ; 
    } 
}

OK configured, then start the main methods to open the browser to test

 

调控banner则在resources目录下创建banner.txt   对其进行书写。

 

Guess you like

Origin www.cnblogs.com/fanqiexin/p/11362753.html