[toc]
看图说话,手把手教你在IDEA中搭建一个SpringBoot项目
点击 File -> New -> Project

选择 Spring Initializr

填写 Group、Artifact 等信息

Tip:Artifact 名称不能包含大写
这和 java 包名的命名规范有相通之处,java 包名不能包含大写字母
选择 Web -> Spring Web

选择项目目录

创建完毕

编写 HelloworldController
1 | package com.liuchuanv.hellworld; |
2 | |
3 | import org.springframework.stereotype.Controller; |
4 | import org.springframework.web.bind.annotation.GetMapping; |
5 | import org.springframework.web.bind.annotation.RequestMapping; |
6 | import org.springframework.web.bind.annotation.ResponseBody; |
7 | |
8 | /** |
9 | * description |
10 | * |
11 | * @author LiuChuanWei |
12 | * @date 2019-11-28 16:00 |
13 | */ |
14 | |
15 | ("/helloworld") |
16 | public class HelloworldController { |
17 | |
18 | ("/sayHello") |
19 | |
20 | public String sayHello() { |
21 | return "Hello Baby!"; |
22 | } |
23 | } |
Tip:方法 sayHello 的注解 @ResponseBody 作用是将方法返回值写入到response的body里,从而将数据直接返回给浏览器;如果没有加该注解,底层会将方法的返回值封装为ModelAndView对象然后返回。
运行 HelloworldApplication

访问 http://localhost:8080/helloworld/sayHello
