Springboot+Maven项目创建(idea)

xiaoxiao2022-07-06  27

1.通过web页面初始化Springboot项目

访问:http://start.spring.io/

导入到你的工程:

a.菜单中选择File–>New–>Project from Existing Sources... b.选择解压后的项目文件夹,点击OK c.点击Import project from external model并选择Maven,点击Next到底为止。

 

2.通过IDEA初始化Springboot项目

new-project

 

3.IDEA常用操作翻译

Jump to Navigation Bar:文件所在目录列表

Declaration:打开该方法的接口文件(一般没实在意义,只是简单一句)

Implementation:是打开具体实现该方法的类文件(具体逻辑的处理地方,方法的主要实现的地方);

Type Declaration:

Super Menthod:

Test:

 

4.微服务启动报错,端口被占用

Verify the connector's configuration, identify and stop any process that's listening on port 18070, or configure this application to listen on another port.

 

5.Lombok代码插件

File---Setting---Plugins----lombok安装,重启IDEA

lombok的作用是简化代码,使用注解@Data,就可以不用写setter,getter方法了,还有equals、canEqual、hashCode、toString方法也不用写了。

@Data集合了@ToString、@EqualsAndHashCode、@Getter/@Setter、@RequiredArgsConstructor的所有特性

import lombok.Data; @Configuration @Data public class UserConfiguration { @Value("${jwt.token-header}") private String userTokenHeader; } 等同于 public class UserConfiguration { @Value("${jwt.token-header}") private String userTokenHeader; publicString getUserTokenHeader() { return this.userTokenHeader; } public void setUserTokenHeader(String userTokenHeader) { this.userTokenHeader= userTokenHeader; } }

优点:

能通过注解的形式自动生成构造器、getter/setter、equals、hashcode、toString等方法,提高了一定的开发效率让代码变得简洁,不用过多的去关注相应的方法属性做修改时,也简化了维护为这些属性所生成的getter/setter方法等

缺点:

不支持多种参数构造器的重载虽然省去了手动创建getter/setter方法的麻烦,但大大降低了源代码的可读性和完整性,降低了阅读源代码的舒适度
转载请注明原文地址: https://www.6miu.com/read-4968483.html

最新回复(0)