IDEA如何生成UML类图
很多学习Java的人都可以根据UML类图写出对应的代码。但是有时要让你根据代码写UML类图就会觉得异常麻烦
当然网上有很多帮助你写UML类图的软件,不过咱们使用IDEA的伙伴不用那么麻烦的。IDEA自带生成UML类图的功能
源代码:
package Account;
/**
* @Description:
* @ProjectNmae: gitTest
* @PackageName: Account
* @ClassName: Account
* @Author: Y-peak
* @Date: 2021.08.19 18:09 星期四
*/
public class Account {
private int id; //账号
private double balance; //余额
private double annualInterestRate; //年利率
public Account(int id, double balance, double annualInterestRate) {
this.id = id;
this.balance = balance;
this.annualInterestRate = annualInterestRate;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public double getBalance() {
return balance;
}
public void setBalance(double balance) {
this.balance = balance;
}
public double getAnnualInterestRate() {
return annualInterestRate;
}
public void setAnnualInterestRate(double annualInterestRate) {
this.annualInterestRate = annualInterestRate;
}
public void withdraw(double amount) //取钱
{
this.balance -= amount;
}
public void deposit(double amount) //存钱
{
this.balance += amount;
}
}
效果图:
0x1 File --> Setting
![在这里插入图片描述](https://img-blog.csdnimg.cn/4d75e5ddcf874b309bbe51b1b7ccbd26.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1lfcGVhaw==,size_16,color_FFFFFF,t_70)
0x2 Tools --> Diagrams
![在这里插入图片描述](https://img-blog.csdnimg.cn/a066a0f583984dcf86e85593b3e9a0b3.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1lfcGVhaw==,size_16,color_FFFFFF,t_70)
0x3 勾选生成类图的成员
一般的话勾选前三个就可以了 ![在这里插入图片描述](https://img-blog.csdnimg.cn/663525e6e83e4059900cb907288f86ce.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1lfcGVhaw==,size_16,color_FFFFFF,t_70)
0x4 生成类图
在文件的文本框内右击点击, Diagrams旁边的两个选项均可生成。也可在右侧右击文件或者包名,然后再点击Diagrams生成UML类图。当然也可以按快捷键Ctrl + Shift + Alt + U或Ctrl + Alt + U生成 ![在这里插入图片描述](https://img-blog.csdnimg.cn/6ceb3f540aba49fea0947dc89473330e.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1lfcGVhaw==,size_16,color_FFFFFF,t_70)
0x5 生成的UML类图
![在这里插入图片描述](https://img-blog.csdnimg.cn/00eb882791744520a372bac43ba07d88.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1lfcGVhaw==,size_16,color_FFFFFF,t_70)
|