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

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


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


在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中运行工程,正确则入图


三、添加HelloController


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



在上图中点击"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/上帝




  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值