新建maven项目
配置maven环境
org.springframework.boot
spring-boot-starter-parent
2.5.10
org.springframework.boot
spring-boot-starter-web
org.projectlombok
lombok
${project.lombok.version}
注意:Main类要在其它类的上一级
启动springboot项目
@SpringBootApplication
public class Main {
public static void main(String[] args) {
SpringApplication.run(Main.class);
}
}
application.yml 总调度
#总调度配置, 激活application-dev.yml文件
spring:
profiles:
active: dev
application-dev.yml 开发环境
#开发环境
server:
port: 8099
application-prod.yml 生产环境
application-test.yml 测试环境
@Data
@NoArgsConstructor
@AllArgsConstructor
public class HttpResp {
private int code;
private String msg;
private Object result;
private Date time;
}
package com.dyit.springboot.controller;
import com.dyit.springboot.dto.HttpResp;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Date;
@RestController
@RequestMapping("/first")
public class HelloControlller {
@GetMapping("/hello")
public HttpResp hello(){
return new HttpResp(1000,"springboot-deatails",null,new Date());
}
}
Tools
包有两种jar (java)、war (javaee)
springboot用jar包
引入maven打包的插件
org.springframework.boot
spring-boot-maven-plugin
点开idea的右侧位置的maven
生成成功
把jar包拷贝到D盘
打开cmd窗口