1 pom.xml
首先引入两个xml节点
<!--这里面继承了springboot很多相关依赖--> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.6.RELEASE</version> </parent> <!--web相关依赖--> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies>
这两个节点的作用如注释
创建一个控制器 com.superman.springboot.Controller.HelloController
内容如下:
package com.superman.springboot.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; @Controller public class HelloController { @ResponseBody @RequestMapping("/hello") public String Hello(){ return "hello world"; } }
注意上述代码中的特性 @Controller @ResponseBody @RequestMapping
然后要创建一个网站启动的引导类
取名(随意):StartApplication
package com.superman.springboot; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class StartApplication { public static void main(String[] args) { SpringApplication.run(StartApplication.class,args); } }
注意特性 SpringBootApplication 和启动方法SpringApplication.run(StartApplication.class,args);
如果要生成jar包
在pom文件中加入节点
<!--可以将当前项目打成jar包进行运行--> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build>
就可以生成对应的jar 包 进入jar包所在目录 执行以下dos命令 即可启动程序