1、下载 intellij 安装。
2、直接使用Spring Initializr创建Springboot
注意 Project SDK 需要配置 jdk
然后一路 next:
勾选 Web Web就可以了。
创建完成后 ,maven开始 下载相关的 jar文件,根据网速可能会下载 1个小时左右,完成后,
3、完成后,在 demo目录下 创建一个 HelloController 文件。
package com.example.demo;
import com.example.demo.bean.person;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Date;
@RestController
public class HelloController {
@RequestMapping("/hello")
public String hello(){
return "hello world~~!";
}
}
4,在demo目录下有个 DemoApplication 类,里面有main()方法。
进入该类 右键 run DemoApplication.main() 就启动spring Boot
内置的tomcat 并将helloworld 部署成功,
在浏览器中:
输入 :127.0.0.1/hello
就会显示出 hello world~~!。
如果显示的是 404 注意查看 控制台,报的错。根据错误来修改。如果显示 80 端口被占用,请查看你是否run 了两次
小知识:
在Application 类中
/**
@SpringBootApplication //等价于 下面三个 注解(被合并在一起了)
/*
@Configuration
@EnableAutoConfiguration
@ComponentScan(basePackages = {"com.mybatis","cn.zll"})//指定需要扫描的包。默认扫描 自己所在目录下的所有组件。
*/