Lombok
- 简化JavaBean的开发,可以自动生成get set tostring方法,搜索和安装Lombok
<dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> </dependency>
- 2
@Data 产生get、set方法
@ToString 产生tostring方法
package spring.main.spring.Bean; import lombok.Data; import lombok.ToString; @Data @ToString public class User { private String name; private Integer age; public User() { } public User(String name, Integer age) { this.name = name; this.age = age; } }
- 3
@AllArgsConstructor 产生全参构造器 (这里如果有其他类作为参数,应该自己写上有参构造器)
@NoArgsConstructor 产生无参构造器
最终的POJO类如下
package spring.main.spring.Bean; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import lombok.ToString; @Data @ToString @AllArgsConstructor @NoArgsConstructor public class User { private String name; private Integer age; }
- 4 @Slf4j 日志
@Slf4j @RestController //就是controller和Requestbody的合体 public class springcontrol { @Autowired //自动注入 Car car; @RequestMapping("/Car") public Car car() { return car; } @RequestMapping("/hello") public String handle01() { log.info("请求已进入!!!"); return "hellow Spring boot"; } }
dev-tools 重启程序 (Ctrl+F9)
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
Spring Initaiizr (创建目录结构,以及依赖 )
快速创建springboot项目
static 放css js等
templates 放页面