springboot项目搭建(二)——直接生成项目架构

spring-Boot是Spring的新东东,为了让人尽快的使用,它提供了一个非常好的辅助工具,直接为我们生成Maven架构的工程。下面,我们通过helloworld看


一、在浏览器中打开http://start.spring.io/,如图

springboot项目搭建(二)——直接生成项目架构

在Artifact中输入spring-boot-sample-helloworld,点击“Switch to the full version.”,勾选"web",然后点击“ Generate Project alt +”按钮,把文件保存到本地某个位置

二、下载文件导入eclips

1、解压下载的文件到某个文件夹;

2、在eclips中导入工程file->import->Import Existing Maven Projects-->Select Maven projects-->finish


3、在eclips中运行工程,正确则入图
springboot项目搭建(二)——直接生成项目架构

三、添加HelloController


1、在包com.example中点击右键,选择new->class,再在Name中输入HelloController,入下图

springboot项目搭建(二)——直接生成项目架构

在上图中点击"Finish"

2、在类上面条件声明@RestController


3、增加方法

package com.lcy.demo.tool;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SummerTest {

    @RequestMapping("/")
    String home() {
        return "Hello World!";
    }

    @RequestMapping("/hello/{myName}")
    String index(@PathVariable String myName) {
        return "Hello " + myName + "!!!";
    }
}

4、启动测试

在浏览器中依次输入

http://localhost:8080/


http://localhost:8080/hello/上帝
springboot项目搭建(二)——直接生成项目架构