<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.0.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies>
建立package learningops.urlshortener
java
package learningops.urlshortener; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.ComponentScan; /** * @author learningops * @date 01/03/2018 */ @SpringBootApplication @ComponentScan public class Application implements CommandLineRunner { @Override public void run(String... args) throws Exception { } public static void main(String[] args) { SpringApplication.run(Application.class, args); } }
建立一個package learningops.urlshortener.controller
web
package learningops.urlshortener.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; /** * @author learningops * @date 22/03/2018 */ @Controller public class IndexController { @RequestMapping("/") @ResponseBody String home() { return "Hello World!"; } }
mvn spring-boot:run
spring