天天看点

SpringBoot入门Helloworld

启动类:(启动类要放在最外侧,包含所有的子包才能够成功的运行!!!)

@SpringBootApplication   //表明这是一个SpringBoot程序
public class HelloworldApplication {

    public static void main(String[] args) {
        SpringApplication.run(HelloworldApplication.class,args);

    }
}
           

maven:

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.6.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>


        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
           

controller

@Controller
public class HelloController {
    @ResponseBody  //说明返回字符串    如果没有的话就会返回相应的页面
    @RequestMapping("/hello")
    public String hello(){
        return "hello world!";
    }
}
           

继续阅读