码迷,mamicode.com
首页 > 编程语言 > 详细

spring boot hello world 搭建

时间:2017-07-23 19:38:47      阅读:269      评论:0      收藏:0      [点我收藏+]

标签:tap   href   local   developer   代码   lips   path   img   新建   

 

1.下载地址:

Eclipse:http://www.eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/neonr

Spring Tool Suite:https://spring.io/tools/sts/all

 

2.使用版本为:

Eclipse:eclipse-jee-neon-R-win32-x86_64.zip

Spring Tool Suite:springsource-tool-suite-3.9.0.RELEASE-e4.6.3-updatesite.zip

 

2.插件安装:

  采用离线安装,安装方式类似svn的安装。

 

3.新建工程:

技术分享

 

注意,过程中选择相应的组件,如web,mybatis,redis 等。

 

4.hello World 代码的编写

 共两个类。

类1:

package com.example.first;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;  
import org.springframework.web.bind.annotation.PathVariable;  
import org.springframework.web.bind.annotation.RequestMapping;  
import org.springframework.web.bind.annotation.RestController;  
  
@RestController  
@EnableAutoConfiguration  
public class Example {  
      
    @RequestMapping("/")  
    String home() {  
        return "Hello World!";  
    }  
      
    @RequestMapping("/hello/{myName}")  
    String index(@PathVariable String myName) {  
        return "Hello "+myName+"!!!";  
    }  
}  


类 2:

@SpringBootApplication  
public class Application {  
  
    public static void main(String[] args) {  
        SpringApplication.run(Application.class, args);  
    }  
}  

 

5.启动方式

  右键项目名称,run as application ,选择上面的Application 类。

 浏览器输入 http://localhost:8080/   即可看到  Hello World!

 

spring boot hello world 搭建

标签:tap   href   local   developer   代码   lips   path   img   新建   

原文地址:http://www.cnblogs.com/xzzq/p/7225470.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!