SpringBoot01

编写第一个SpringBoot程序

1.创建一个Maven项目

具体参考:Maven介绍
感谢分享!
2.在pom.xml中配置对应的参数



4.0.0

    org.springframework.boot
    spring-boot-starter-parent
    2.1.8.RELEASE
     

    com.ieStudy
    spring-boot01-helloWorld
    1.0-SNAPSHOT
love-xian
Demo project for Spring Boot

    
        org.springframework.boot
        spring-boot-starter-web
    


    
        nexus-aliyun
        Nexus aliyun
        http://maven.aliyun.com/nexus/content/groups/public
    


    
        
            org.springframework.boot
            spring-boot-maven-plugin
        
    
    
        
            src/main/resources
            
                ip2region/ip2region.db
            
            true
        
        
            src/main/resources
            
                ip2region/ip2region.db
            
            false
        
        
            src/main/java
            
                **/*.xml
                **/*.json
            
        
    


3.编写一个主程序,激动springBoot

import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringBootConfiguration;

@org.springframework.boot.autoconfigure.SpringBootApplication
public class SpringBootApplication {
    public static void main(String[] args) {
        SpringApplication.run(SpringBootApplication.class, args);//启动springboot项目
    }

}

4.创建一个controller,setvice层
创建一个controller类

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class HelloController {
    @ResponseBody
    @RequestMapping("/hello")//向服务器发送请求
    public String hello()//获取对应的数据
    {
        return "Hello" +
                "World!";
    }
}

5.启动项目:
SpringBoot01_第1张图片
发现启动了Tomcat服务器,在浏览器输入本机地址:详情ipconfig
或者输入:localhost:8080
在输入请求 localhost:8080/hello
得到回复:
SpringBoot01_第2张图片

你可能感兴趣的:(java,SpringBoot)