一个简单的Springboot项目

来源:互联网 发布:清除下载器数据 编辑:程序博客网 时间:2024/05/16 13:41

创建一个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.et</groupId>  <artifactId>SbLesson</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><!-- springboot每一个框架的集成都是一个starterspring-boot-starter-web加载javaee  内嵌tomcat -->    <dependency>        <groupId>org.springframework.boot</groupId>        <artifactId>spring-boot-starter-web</artifactId>    </dependency></dependencies></project>

Controller层的一个类:

package cn.et;import java.util.HashMap;import java.util.Map;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;@SpringBootApplication@RestControllerpublic class SbController {@RequestMapping("/hello")public Map hello(){Map map = new HashMap();map.put("id", 1);map.put("name", "zs");return map;}public static void main(String[] args) { SpringApplication.run(SbController.class, args);}}

运行main 通过浏览器访问http://localhost:8080/hello