Foreword
To create a hello world chant
step
Of course, it is to open our IDEA to create a Maven project Kazakhstan
Create a project
1. File->New->Project
2.Maven-> JDK version choose -> Next
3. Groupld->Artifactld->Next
4. location->Finsh
5. Open Auto Import
Import dependence
Import-related dependence of SpringBoot into SpringBoot official website clicks Quick start
in the Spring Lnitializr
after fill in specific information, we can click on Explore- Ctrl + Space
to generate a pom.xml
file, simply copy the configuration to cover the project.
Main program
Write a main program used to start SpringBoot applications, please pay attention to self-created position.
1. Create a class file
2. mark the main program
3. The main program code as follows
package com.wangyang;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
/**
* @SpringBootApplication 标注一个主程序类,说明这是一个Spring Boot应用
*/
//DataSourceAutoConfiguration禁止自动加载,不然会产生报错
@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})
public class HelloWorldMainApplication {
public static void main(String[] args) {
//启动Spring应用
SpringApplication.run(HelloWorldMainApplication.class,args);
}
}
Write business code
1. Create a controller controller
2. Business Code
package com.wangyang.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class HelloWorldController {
@ResponseBody
@RequestMapping("/")
public String hello(){
return "hello world";
}
}
Run the main method
Returns to the main program, the main method can be run directly