springboot第一个项目hello word (1)

版权声明:随便看,喜欢的话加我qq,一起讨论。 https://blog.csdn.net/qq_43687284/article/details/84306309

我用的是idea版的
新建一个项目,我就不具体说了。主要说重要的。
打开pom.xml 配置依赖

<?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>pringbooth</groupId>
    <artifactId>pringbooth</artifactId>
    <version>1.0-SNAPSHOT</version>
    <parent><!--SpringBoot配置-->
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.2.RELEASE</version>
    </parent>
    <dependencies>
        <dependency><!--Web的基本配置-->
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin><!--plugin配置-->
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

然后新建一个类,写上主方法,运行即可

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@EnableAutoConfiguration
public class Ha {
    @RequestMapping("/hello")//接受浏览器的hello请求
    @ResponseBody//spring的用法
    String home(){
        return"Hello Word";
    }
    public static void main(String[] args) {
        SpringApplication.run(Ha.class, args);
    }
}

启动主程序,打开浏览器访问http://localhost:8080/hello,就可以看到效果了

猜你喜欢

转载自blog.csdn.net/qq_43687284/article/details/84306309