大致学完SSM有一段时间了,虽然对于底层源码之类的还了解,但是掌握了基本的运用,本来是还想先复习Java基础和学习spring源码的,但是最近突然发现,很多招人的企业都要会springboot,只能匆匆上路,先入门一下
这是跟着尚硅谷的视频走的,可惜视频是springboot1.5,我的是2.5,中间有很多区别,边学习边记录
-----------
1.创建springboot
使用IDEA,创建springboot,只选一个spring web,然后next,finish
2.写controller
注意Helloworld01Application的位置,
package com.example.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class HelloController {
@RequestMapping("/hello")
@ResponseBody
public String hello(){
return "hello World!";
}
}
3.进入Helloworld01Application执行程序
4.成功后打开浏览器,http://localhost:8080/hello,出现hello world!
5.打包
在pom中添加插件
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
点击右边的Maven Projects
点击package,就会自动打成jar包
包在target目录下,将之复制到桌面
cmd执行jar包
在浏览器刷新http://localhost:8080/hello
还是可以访问,出现hello world!