Spring boot 环境搭建之hello word

   使用eclipse工具新建一个maven项目,在项目的pom.xml文件加入spring-boot-starter-web依赖
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <version>2.0.1.RELEASE</version>
</dependency>

  这样marvn会自动帮我们下载好相关的依赖包
 接下编定一个简单的控制器
 
import java.util.Calendar;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
@Controller
public class SpringController {

@RequestMapping(value="/helloword")

public  helloword() {
return "hello word!";

}
}

当用户访问 localhost:8080/helloword时会返回一个hello word


 编写spring boot 启动类

package com.ch14.springtest;


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;


/**
 * Hello world!
 *
 */

@SpringBootApplication


public class App 
{
    public static void main( String[] args ) {
  
        new SpringApplicationBuilder(App.class).run(args);
        
    }
}

使用了@SpringBootApplication注解来标识这是一个spring boot的启动类. 直接在ele工具中运行就开始启动了spring boot
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值