4 changed files with 77 additions and 0 deletions
@ -0,0 +1,14 @@ |
|||
3. AI 架构审计(MVC 三层检查) |
|||
发送给 AI 的指令模板: |
|||
作为 Java 架构审计师,请检查我的 MVC 三层划分是否存在越权行为? |
|||
|
|||
我的项目结构: |
|||
· Model:Article(数据实体)、Storage(数据存取) |
|||
· View:ConsoleView(控制台输入输出) |
|||
· Controller:CommandController(解析命令、调用 Model) |
|||
|
|||
请从以下角度审计: |
|||
1. View 是否直接调用了 Model 层?(越权) |
|||
2. Controller 是否做了 View 的工作?(职责混淆) |
|||
3. Model 层是否包含了业务逻辑而非仅仅是数据存取? |
|||
4. 各层之间的依赖方向是否正确?(View → Controller → Model) |
|||
@ -0,0 +1,27 @@ |
|||
import java.util.Date; |
|||
|
|||
public class Article { |
|||
private String title; |
|||
private String content; |
|||
private String url; |
|||
private String author; // 新增
|
|||
private Date publishDate; // 新增
|
|||
|
|||
// 构造器
|
|||
public Article(String title, String content, String url, String author, Date publishDate) { |
|||
this.title = title; |
|||
this.content = content; |
|||
this.url = url; |
|||
this.author = author; |
|||
this.publishDate = publishDate; |
|||
} |
|||
|
|||
// Getters and Setters
|
|||
public String getAuthor() { return author; } |
|||
public void setAuthor(String author) { this.author = author; } |
|||
|
|||
public Date getPublishDate() { return publishDate; } |
|||
public void setPublishDate(Date publishDate) { this.publishDate = publishDate; } |
|||
|
|||
// 原有字段的 getter/setter...
|
|||
} |
|||
@ -0,0 +1,8 @@ |
|||
public class Controller { |
|||
private HistoryCommand history = new HistoryCommand(); |
|||
|
|||
public void executeCommand(String command) { |
|||
history.addCommand(command); // 记录每一条命令
|
|||
// ... 原有命令处理逻辑
|
|||
} |
|||
} |
|||
@ -0,0 +1,28 @@ |
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
|
|||
public class HistoryCommand { |
|||
private List<String> commandHistory = new ArrayList<>(); |
|||
|
|||
// 添加命令到历史
|
|||
public void addCommand(String command) { |
|||
commandHistory.add(command); |
|||
} |
|||
|
|||
// 获取所有历史命令
|
|||
public List<String> getHistory() { |
|||
return new ArrayList<>(commandHistory); // 返回副本,保护原数据
|
|||
} |
|||
|
|||
// 打印历史记录
|
|||
public void printHistory() { |
|||
for (int i = 0; i < commandHistory.size(); i++) { |
|||
System.out.println((i + 1) + ". " + commandHistory.get(i)); |
|||
} |
|||
} |
|||
|
|||
// 清空历史
|
|||
public void clear() { |
|||
commandHistory.clear(); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue