SpringBoot入门学习(一): Idea 创建 SpringBoot 的 HelloWorld
2024-09-28 02:03:02
创建项目:
项目结构:
程序启动入口:
正式开始:
package com.example.demo; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan; @SpringBootApplication
@ComponentScan("com.example.helloweb") //扫描所需要的包
public class DemoApplication { public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
HelloWorld:
package com.example.helloweb; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController; @Controller
public class HelloWord { /**
* @Controller 和 @ResponseBody 配合相当于 @RestController,
* 返回前端页面的都是 json 格式数据。
* @return
*/
@RequestMapping("/hello")
public @ResponseBody String index () {
System.out.println("欢迎进入SpringBoot");
return "Hello World!";
}
}
控制台显示:
欢迎进入SpringBoot |
页面显示:
搞定!
最新文章
- 中文字符匹配js正则表达式
- lucene-查询query->;RangeQuery在某一范围内搜索
- Divide and Conquer:Cable Master(POJ 1064)
- jsoup 简介
- 最小生成树(HDOJ 1863)
- HTML5 :b/strong加粗,i/em倾斜区别
- linux驱动程序之电源管理之标准linux休眠和唤醒机制分析(二)
- QT中嵌入SDL
- 第一篇:NSOperation的概念
- 微软Surface Book推送Windows 10新固件更新:增强系统和电池
- 自己实现ArrayList
- Go语言数组
- TMS-规划图
- windows下安装ElasticSearch的Head插件
- 使用监听器解决路径问题,例如在jsp页面引入js,css的web应用路径
- python socket 详细介绍
- U盘装系统:安装GHOST Win7系统教程
- python2.7入门---函数
- Git命令行中文显示错误
- hadoop中使用的Unsafe.java