两种创建方式索引:
一、Spring Initializr工具创建
1.idea
新建一个新项目
2.点击Spring Initializr
3.填写GroupId
和项目名
4.选择Spring Web
模块,然后点击finish
----------------------这里项目已经建立好了---------------------------
5.删除无关文件夹,并创建helloWorld
的Controllor
类
package com.itcast.controllor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class helloWorldControllor {
@ResponseBody
@RequestMapping("/helloworld")
public String helloWorld(){
return "Hello World! Spring Boot !";
}
}
6.运行main
函数
出现以下显示说明项目创建成功
7.访问 http://localhost:8080/hello
出现相应内容Hello World! Spring Boot !
说明项目成功运行
二、Maven创建
1.idea创建maven新项目
2.填写GroupId和项目名
3.配置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>com.iamapsycho</groupId>
<artifactId>SpringBootTest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>billingBootTest-iamapsycho</name>
<description>Demo project for Spring Boot</description>
<!--
spring-boot-starter-parent是Spring Boot的核心启动器,
包含了自动配置、日志和YAML等大量默认的配置,大大简化了我们的开发。
引入之后相关的starter引入就不需要添加version配置,
spring boot会自动选择最合适的版本进行添加。
-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
</parent>
<dependencies>
<!-- spring-boot-starter-web包含了Spring Boot预定义的一些Web开发的常用依赖包
如: spring-webmvc,Tomcat.... -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
4.创建主函数的类Springboot01DemoApplication
@SpringBootApplication
public class Springboot01DemoApplication {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
5.创建helloWorld
的Controllor
类
6.运行main
函数
7.访问 http://localhost:8080/hello