spring boot 的helloworld

用 IDEA,直接使用 Spring Initializr 快速搞定

新建Spring Boot项目

  1. 打开IDEA,创建新项目,使用Spring Initializr

1579489449818

  1. 填写信息

1579489506330

  1. 选择依赖(可以默认直接下一步,后期在pom里手动添加依赖)

1579489539520

  1. 这里选一个Spring Boot最基本的依赖,其他后期加入
    在这里插入图片描述

  2. 项目名和位置

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-giS51ORC-1582266548477)(https://raw.githubusercontent.com/renshen052/gitnote-images/master/typora/20200203113023-369460.png)]

  1. 创建完成

生成的结构如下

1579659379999

src 源代码

​ main 项目正式代码

​ java ,放java类代码

​ resources 资源文件夹

​ static 静态资源(css,js,image等)

​ templates html文件

​ application.properties 配置文件

​ test 测试代码

target 输出目录

  1. HelloController
package com.renshen052.community.controller;

import jdk.nashorn.internal.objects.annotations.Getter;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class HelloController {

    @GetMapping("/hello")
    public String hello(@RequestParam(name="name") String name, Model model){
        model.addAttribute("name",name);
        return "hello";
    }

}

  1. hello.html
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>Getting Started: Serving Web Content</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<p th:text="'Hello, ' + ${name} + '!'" />
</body>
</html>
  1. 运行

访问 localhost:8080/hello?name=zhang

浏览器返回 zhang

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值