springboot系列教程(一)——第一个springboot程序
2017-12-21 16:26
627 查看
第一个springboot程序
springboot可以使我们快速开发一个web项目。本系列例子采用intellij idea开发打开Idea-> new Project ->Spring Initializr ->填写group、artifact ->钩上web(开启web功能)->点下一步就行了。
自动生成pom.xml
<?xml version="1.0" encoding="UTF-8"?> <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.example</groupId> <artifactId>study1</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>study1</name> <description>Demo project for Spring Boot</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.9.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
新建controller
package com.example.demo.controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; /** * @author :小虎 * @date :2017/12/21 */ @RestController public class HomeController { @RequestMapping("/") public String home(){ return "hello world"; } }
直接运行Study1Application这个java类
@SpringBootApplication public class Study1Application { public static void main(String[] args) { SpringApplication.run(Study1Application.class, args); } }
启动springboot 方式
cd到项目主目录: mvn clean mvn package mvn spring-boot: run 启动 cd 到target目录, java -jar 项目.jar
访问地址http://localhost:8080/
项目源码
https://github.com/itmybaby/springboot/tree/master/study1相关文章推荐
- SpringBoot系列二:搭建自己的第一个SpringBoot程序
- Springboot系列:Springboot与Thymeleaf模板引擎整合基础教程(附源码)
- Springboot系列:Springboot与Thymeleaf模板引擎整合基础教程(附源码)
- Springboot系列:Springboot与Thymeleaf模板引擎整合基础教程(附源码)
- Springboot系列:Springboot与Thymeleaf模板引擎整合基础教程(附源码)
- Spring Boot系列教程二:创建第一个web工程 hello world
- Springboot系列:Springboot与Thymeleaf模板引擎整合基础教程(附源码)
- Springboot系列:Springboot与Thymeleaf模板引擎整合基础教程(附源码)
- Springboot系列:Springboot与Thymeleaf模板引擎整合基础教程(附源码)
- Springboot系列:Springboot与Thymeleaf模板引擎整合基础教程(附源码)
- Springboot系列:Springboot与Thymeleaf模板引擎整合基础教程(附源码)
- Springboot系列:Springboot与Thymeleaf模板引擎整合基础教程(附源码)
- Springboot系列:Springboot与Thymeleaf模板引擎整合基础教程(附源码)
- Springboot系列:Springboot与Thymeleaf模板引擎整合基础教程(附源码)
- Spring Boot系列教程二:创建第一个web工程 hello world
- Springboot系列:Springboot与Thymeleaf模板引擎整合基础教程(附源码)
- Struts2系列教程1:第一个Struts2程序
- Springboot系列:Springboot与Thymeleaf模板引擎整合基础教程(附源码)
- (转)WCF教程系列(1)-创建第一个WCF程序
- SpringBoot非官方教程 | 第六篇:springboot整合mybatis