1、手动配置,三个文件
打开创建maven,创建这三个文件从上到下依次复制即可
配置文件(重要)(否则后面会报错)
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>cn.ly</groupId><artifactId>springboot01</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>
HelloWorldMainApplication
package cn;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;/*** @SpringBootApplication 来标注一个主程序类,说明这是一个Spring Boot应用*/@SpringBootApplication
public class HelloWorldMainApplication {public static void main(String[] args) {// Spring应用启动起来SpringApplication.run(HelloWorldMainApplication.class,args);}
}
HelloController
package cn.ly;import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;@RestController
public class HelloController {@RequestMapping("/hello")public String hello(){return "Hello KKK12345K!";}
}
运行主程序
运行浏览器
第二种:
直接创建Spring initializr
创建时勾选spring web
穿件完后就不需要写
pom.xml和主类了
只要写下controller逻辑层的代码就行,依然可以运行