如何新建一个spring boot项目——我自己创建的如下
org.springframework.boot spring-boot-starter-parent 1.5.9.RELEASE org.springframework.boot spring-boot-starter-web
<?xml version="1.0" encoding="UTF-8"?>4.0.0 org.example anxinfu 1.0-SNAPSHOT war anxinfu Maven Webapp http://www.example.com UTF-8 1.7 1.7 org.springframework.boot spring-boot-starter-parent 1.5.9.RELEASE org.springframework.boot spring-boot-starter-web junit junit 4.11 test anxinfu maven-clean-plugin 3.1.0 maven-resources-plugin 3.0.2 maven-compiler-plugin 3.8.0 maven-surefire-plugin 2.22.1 maven-war-plugin 3.2.2 maven-install-plugin 2.5.2 maven-deploy-plugin 2.8.2
SpringBootStart
package com.test; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.ComponentScan; @SpringBootApplication @ComponentScan(basePackages = {"com.test.controller*"}) public class SpringBootStart { public static void main(String[] args) { SpringApplication.run(SpringBootStart.class, args); } }
StartMainController
package com.test.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; @Controller public class StartMainController { @RequestMapping("/12") @ResponseBody public String home12() { return "hello---12"; } @RequestMapping("/123") @ResponseBody public String home123() { return "hello---123"; } }
=====================================================================
http://localhost:8080/12
http://localhost:8080/123