你的位置:首页 > Java教程

[Java教程]Springboot helloworld入门最经典例子

一、建立maven java项目

 导入springboot包

 

二、配置pom.

 

<project ="http://maven.apache.org/POM/4.0.0" ="http://www.w3.org/2001/ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 >> <modelVersion>4.0.0</modelVersion> <groupId>com.ij34.example</groupId> <artifactId>Bootproject</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>Bootproject</name> <url></url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties><parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.6.RELEASE</version></parent><dependencies> <dependency>  <groupId>org.springframework.boot</groupId>  <artifactId>spring-boot-starter-web</artifactId> </dependency></dependencies></project>

 

 

三、代码测试

 

package hello;import java.util.Date;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.EnableAutoConfiguration;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.ResponseBody;/** * @author Admin* @date 创建时间:2017年8月28日 下午4:14:54 * @version 1.0*@type_name SampleController*/@Controller@EnableAutoConfigurationpublic class SampleController {  @RequestMapping("/") @ResponseBody String home(){  return "Hello World:"+new Date(); } public static void main(String[] args) {  // TODO Auto-generated method stub  SpringApplication.run(SampleController.class, args); }}