springboot学习day01

94 阅读1分钟

创建springboo项目

idea创建maven工程

配置pom.xml坐标,添加

 * spring-boot-starter-parent
 * spring-boot-starter-web
<?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>org.example</groupId>  
<artifactId>test001</artifactId>  
<version>1.0-SNAPSHOT</version>  
  
<properties>  
<maven.compiler.source>17</maven.compiler.source>  
<maven.compiler.target>17</maven.compiler.target>  
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  
</properties>  
  
<parent>  
<groupId>org.springframework.boot</groupId>  
<artifactId>spring-boot-starter-parent</artifactId>  
<version>3.1.2</version>  
</parent>  
  
<dependencies>  
<dependency>  
<groupId>org.springframework.boot</groupId>  
<artifactId>spring-boot-starter-web</artifactId>  
</dependency>  
</dependencies>  
  
</project>

创建入口类型

package com.ivan;  
  
import org.springframework.boot.SpringApplication;  
import org.springframework.boot.autoconfigure.SpringBootApplication;  
  
@SpringBootApplication  
public class Main {  
    public static void main(String[] args){  
        SpringApplication.run(Main.class,args);  
    }  
}

入口类下创建控制器

package com.ivan.controller;  
  
import org.springframework.web.bind.annotation.RequestMapping;  
import org.springframework.web.bind.annotation.RestController;  
  
@RestController  
public class Hello {  
    @RequestMapping("/hello")  
    public String hello(){  
        return "jello";  
    }  
}