Application.java
package com.xdr.spring;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/*
* springboot 的启动类或引导类
*/
@SpringBootApplication //表明是springboot的引导类
public class Application {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("启动springboot");
SpringApplication.run(Application.class, args);
}
}
HelloController.java
package com.xdr.spring.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/*
* springboot的入门案例:实现基于springboot的springmvc配置
*/
@RestController
@RequestMapping("/springmvc")
public class HelloController {
@RequestMapping("hello")
public String sayHello() {
return "hello springboot";
}
}
pom.xml
<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>com.xdr</groupId>
<artifactId>01_springboot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
</project>
注意:
运行结果: