-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
wuzhihao
committed
Aug 10, 2019
1 parent
9e53090
commit 79eca36
Showing
1 changed file
with
11 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,16 @@ | ||
# bean | ||
# 数据库规范 | ||
|
||
> 数据库表 -> entity | ||
## 命名规范 | ||
|
||
> 网络传输对象 -> dto | ||
1. 测试表、临时表、备份表都要加上test_、temp_、backup_的前缀,并且要注释说明该表的作用,使用完之后应立即删除表。这些命名规则的表,不应该上到生产环境,加上前缀方便测试环境区分。 | ||
|
||
> dto转换: | ||
# CI | ||
|
||
```java | ||
@PostMapping | ||
public User addUser(UserInputDTO userInputDTO){ | ||
User user = convertFor(userInputDTO); | ||
|
||
return userService.addUser(user); | ||
} | ||
|
||
private User convertFor(UserInputDTO userInputDTO){ | ||
|
||
User user = new User(); | ||
BeanUtils.copyProperties(userInputDTO,user); | ||
return user; | ||
} | ||
``` | ||
|
||
> 抽象接口定义 | ||
```java | ||
public interface DTOConvert<S,T> { | ||
T convert(S s); | ||
} | ||
|
||
public class UserInputDTOConvert implements DTOConvert { | ||
@Override | ||
public User convert(UserInputDTO userInputDTO) { | ||
User user = new User(); | ||
BeanUtils.copyProperties(userInputDTO,user); | ||
return user; | ||
} | ||
} | ||
``` | ||
|
||
> 接口应该返回dto | ||
```java | ||
@PostMapping | ||
public UserOutputDTO addUser(UserInputDTO userInputDTO){ | ||
User user = new UserInputDTOConvert().convert(userInputDTO); | ||
User saveUserResult = userService.addUser(user); | ||
UserOutputDTO result = new UserOutDTOConvert().convertToUser(saveUserResult); | ||
return result; | ||
} | ||
``` | ||
|
||
> 代码聚合 | ||
```java | ||
@Data | ||
public class UserInputDTO { | ||
private String username; | ||
private int age; | ||
|
||
public User convertToUser(){ | ||
UserInputDTOConvert userInputDTOConvert = new UserInputDTOConvert(); | ||
User convert = userInputDTOConvert.convert(this); | ||
return convert; | ||
} | ||
|
||
private static class UserInputDTOConvert implements DTOConvert<UserInputDTO,User> { | ||
@Override | ||
public User convert(UserInputDTO userInputDTO) { | ||
User user = new User(); | ||
BeanUtils.copyProperties(userInputDTO,user); | ||
return user; | ||
} | ||
} | ||
} | ||
//使用 | ||
@PostMapping | ||
public UserOutputDTO addUser(UserInputDTO userInputDTO){ | ||
User user = userInputDTO.convertToUser(); | ||
User saveUserResult = userService.addUser(user); | ||
UserOutputDTO result = new UserOutDTOConvert().convertToUser(saveUserResult); | ||
return result; | ||
} | ||
``` | ||
(1)根据gradle的项目结构约定(Maven也有自己的约定),在命令行中创建目录即gradle脚本文件。 | ||
(2)在gradle中引入idea插件,该插件用来生成IntelliJ IDEA的工程文件,我使用的IntelliJ IDEA而没有使用eclipse。 | ||
(3)运行一个命令"gradlew idea",生成一个*.ipr文件 | ||
(4)在IntelliJ IDEA中,直接打开该ipr文件。 | ||
(5)现在就可以编辑代码了。gradle也为eclipse提供相应的插件 | ||
(6)要编译项目,别再IDE里面进行,使用gradle或者Maven来构建 | ||
(7)这样一步一步向前迈,你会发现你越来越趋向于持续集成了。 | ||
|