Token导航 LogoToken导航

Agent Skill · 前端设计

best-java-structure(最佳 Java structure)

用于辅助 Java 项目开发、面向对象设计、Spring 生态、Maven 或 Gradle 依赖和后端工程实践。它适合让 Agent 分析类结构、设计接口、整理服务分层、生成测试或检查常见代码坏味道。使用时需要结合项目已有架构、包结构和依赖版本,不应只按通用教程改代码;涉及数据库、事务、并发或框架配置时,应先确认运行环境和回归测试范围。

best-java-structure 是前端设计类 Agent Skill,可用宿主为 Codex、Claude、Cursor、Gemini CLI,通过GitHub 仓库获取,权限为需要联网;许可证信息还不明确,第三方扫描已通过,按安装量在前端设计类的 10,216 个 Skill 里排第 6,094。

总安装 558周安装 23GitHub Stars 1下载 182核验 2026-05-01

安装说明

本站只整理中文说明,不托管安装包,也不代用户安装。
GitHub
许可证
unknown

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:best-java-structure(最佳 Java structure)
来源仓库:https://github.com/chasepassion/skills
仓库路径:skills/best-java-structure
安装命令:
npx skills add https://github.com/chasepassion/skills --skill best-java-structure
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/chasepassion/skills --skill best-java-structure

这个 Skill 是做什么的

前端设计类 Skill 关注页面结构、视觉规范和组件写法,输出通常是可运行的界面代码。

基于 Spring Boot 与 MyBatis-Plus 的五层架构设计指南,涵盖分层规范与 DTO 映射。适合 Java Web 项目开发、遗留系统重构或团队架构标准化场景。提供 Controller/Service/Dao 层的职责划分与事务管理建议。需根据实际业务复杂度调整分层粒度,避免过度设计。

best-java-structure 属于前端设计类 Skill,可作为该场景下的辅助能力补充。

来源仓库内路径:skills/best-java-structure

上手步骤

4 步
  1. 1

    确认自己的宿主工具

    公开资料标注支持 Codex、Claude、Cursor、Gemini CLI;先确认自己用的是其中之一,再按对应工具的 Skills 目录放置。

  2. 2

    拿到安装命令

    可以直接复制的命令是 npx skills add https://github.com/chasepassion/skills --skill best-java-structur…;命令里的占位符换成自己的路径或密钥再执行。

  3. 3

    安装后重启宿主

    命令执行完要完全退出宿主工具再打开,让新装的 Skill 被重新扫描到,否则列表里可能看不到。

  4. 4

    按最小权限试用

    它需要需要联网,先在测试目录或测试账号里跑,确认没问题再放到正式项目。

常见问题

6 条

best-java-structure 怎么安装?

在终端执行 npx skills add https://github.com/chasepassion/skills --skill best-java-structure。装完完全退出宿主工具再打开,让它重新扫描本地 Skill。

best-java-structure 支持哪些 AI 工具?

公开资料标注支持 Codex、Claude、Cursor、Gemini CLI。其他工具只要能读取本地 Skill 目录,一般也能手动放进去,但要自己确认触发方式是否一致。

best-java-structure 需要什么权限?

权限级别是需要联网。该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

best-java-structure 是免费的吗?

公开资料没有标注明确许可证,收费和商用限制都无法确认。正式使用前请到来源仓库核对授权说明。

best-java-structure 用的人多吗?

公开数据是累计安装 558 次,近一周安装 23 次,下载 182 次,GitHub 1 星。这些数字来自第三方目录统计,只能当作热度参考,不代表质量或安全性。

best-java-structure 安全吗?

第三方扫描结果为通过,但这只覆盖已知的静态检查项,不能替代自己读一遍源码和安装命令。

值得选的地方和要先想清楚的地方

值得选的地方

  • 同时适配 4 种工具,换客户端不用重新找替代品。
  • 第三方扫描已通过,常见的高风险行为没有命中。

先想清楚的地方

  • 许可证没有明确标注,能不能商用、能不能再分发都不确定。
  • 第三方目录整理,版本更新和行为细节以来源仓库为准。

适不适合你

更适合

  • 已经在用 Codex,想直接扩展它能力的人。
  • 需要处理前端设计类任务、又不想每次都手写提示词的人。

不太适合

  • 需要明确授权才能用到公司项目里的场景。
  • 需要厂商级技术支持和 SLA 的生产系统。

前端设计类 Skill 对比

6 个同类
Skill总安装GitHub 星权限许可证扫描
frontend-design

前端设计 · Codex、Claude

8,823,360126,072只读MIT通过
vercel-composition-patterns

Vercel 组合模式 · Codex、Claude

3,858,81625,893需要联网MIT通过
vercel-react-native-skills

Vercel React native skills 前端 · Codex、Claude

2,468,66425,878只读MIT通过
adapt

adapt 搜索 · Codex、Claude

2,027,04023,125操作浏览器未明确通过
bolder

bolder 分析 · Codex、Claude

2,004,28823,130只读未明确通过
best-java-structure

最佳 Java structure · 本页

5581需要联网未明确通过

按安装量取同分类前几名;数字来自第三方目录统计,只作热度参考,不代表质量结论。

SKILL.md 原文

Java Layered Architecture Design Pattern (Spring Boot + MyBatis-Plus)

A practical guide to implementing a classic five-layer architecture with Spring Boot and MyBatis-Plus.

When to Apply

Use this skill in the following scenarios:

  • Creating a new Java Web project
  • Refactoring an existing project architecture
  • Designing a multi-module Java system
  • Checking architectural compliance during code reviews
  • Defining architectural standards for team development
  • Database migration or technology stack migration

Assumptions

  • Spring Boot 3.x
  • MyBatis-Plus for data access
  • DTO/VO separation at API boundaries

Quick Reference

PriorityCategoryImpact AreaPrefix
1Separation of ConcernsArchitectural clarity-principle-
2Unidirectional DependencyDependency management-dependency-
3Interface AbstractionReplaceability-abstraction-
4Data TransferAPI consistency-data-
5Exception HandlingError handling-exception-
6Cross-Layer InvocationArchitectural compliance-crosslayer-
7Reverse DependencyArchitectural compliance-reverse-
8Entity ExposureSecurity-entity-exposure-

Core Principles

1. Separation of Concerns (SoC)

Each layer should solve one category of problems and must not take on responsibilities belonging to other layers.

// Correct: clear responsibilities per layer
// Presentation layer: HTTP handling only
@RestController
public class ProjectController {
    private final ProjectService projectService;
    public ProjectController(ProjectService projectService) {
        this.projectService = projectService;
    }
    @GetMapping("/{id}")
    public ApiReturn<ProjectVo> getProject(@PathVariable Long id) {
        Project project = projectService.getProject(id);
        ProjectVo vo = new ProjectVo();
        BeanUtils.copyProperties(project, vo);
        return ApiReturn.of(vo);
    }
}
// Business logic layer: business rules only
@Service
public class ProjectService {
    private final ProjectMapper projectMapper;
    public ProjectService(ProjectMapper projectMapper) {
        this.projectMapper = projectMapper;
    }
    public Project getProject(Long id) {
        Project project = projectMapper.selectById(id);
        if (project == null) {
            throw new BusinessException(404, "Project does not exist");
        }
        return project;
    }
}
// Data access layer: data interfaces only
public interface ProjectMapper extends BaseMapper<Project> {
}

2. Unidirectional Dependency

Upper layers may call lower layers, but lower layers must not depend on upper layers.

// Correct: depend on a lower layer abstraction
@Service
public class ProjectService {
    private final ProjectMapper projectMapper;
    public ProjectService(ProjectMapper projectMapper) {
        this.projectMapper = projectMapper;
    }
}
// Incorrect: cross-layer invocation
@RestController
public class ProjectController {
    private final ProjectMapper projectMapper;
    public ProjectController(ProjectMapper projectMapper) {
        this.projectMapper = projectMapper;
    }
}

3. Interface Abstraction

Layers should interact via interfaces, not concrete implementations.

// Correct: mapper interface managed by MyBatis-Plus
public interface ProjectMapper extends BaseMapper<Project> {
}
// Incorrect: depending on a non-existent implementation class
public class ProjectService {
    private ProjectMapperImpl projectMapperImpl;
}

Architecture Layers

Classic Five-Layer Architecture

Presentation Layer → Business Logic Layer → Data Access Layer → Persistence Layer → Database Layer
LayerSpring StackCommon NamesCore Responsibilities
Presentation Layer@ControllerController, APIHandle HTTP requests and responses
Business Logic Layer@ServiceServiceImplement business rules and workflows
Data Access Layer@MapperMapper, DAODefine DB access interfaces
Persistence LayerMyBatis XML, EntityMapper XML, EntitySQL mapping and entity definitions
Database LayerMySQLDatabaseStore and retrieve data

Layer Definitions

Presentation Layer

Responsibilities:

  • Handle HTTP requests and responses
  • Receive and validate parameters
  • Routing and dispatching
  • Data format transformation (DTO ↔ Entity ↔ VO)
  • Exception handling and HTTP status mapping Template:
@RestController
@RequestMapping("/api/projects")
public class ProjectController {
    private final ProjectService projectService;
    public ProjectController(ProjectService projectService) {
        this.projectService = projectService;
    }
    @GetMapping("/{id}")
    public ApiReturn<ProjectVo> getProject(@PathVariable Long id) {
        Project project = projectService.getProject(id);
        ProjectVo vo = new ProjectVo();
        BeanUtils.copyProperties(project, vo);
        return ApiReturn.of(vo);
    }
    @PostMapping
    public ApiReturn<ProjectVo> createProject(@Valid @RequestBody ProjectCreateRequest request) {
        Project project = new Project();
        BeanUtils.copyProperties(request, project);
        Project created = projectService.createProject(project);
        ProjectVo vo = new ProjectVo();
        BeanUtils.copyProperties(created, vo);
        return ApiReturn.of(vo);
    }
}

Design notes:

  • Keep it thin: HTTP-related logic only
  • Use DTO/VO for data transfer
  • Centralize validation with Bean Validation and global exception handling
  • No business logic
  • No direct database access

Business Logic Layer

Responsibilities:

  • Implement business rules and workflows
  • Data validation and business checks
  • Authorization and access control
  • Transaction management (boundary here)
  • Coordinate multiple services and mappers
  • Call the data access layer Template:
@Service
public class ProjectService {
    private final ProjectMapper projectMapper;
    public ProjectService(ProjectMapper projectMapper) {
        this.projectMapper = projectMapper;
    }
    public Project getProject(Long id) {
        if (id == null || id <= 0) {
            throw new BusinessException(400, "Invalid project ID");
        }
        Project project = projectMapper.selectById(id);
        if (project == null) {
            throw new BusinessException(404, "Project does not exist");
        }
        return project;
    }
    @Transactional
    public Project createProject(Project project) {
        if (project.getCustomerId() == null) {
            throw new BusinessException(400, "Customer ID must not be null");
        }
        project.setCreatedTime(LocalDateTime.now());
        project.setStatus(ProjectStatus.CREATED);
        projectMapper.insert(project);
        return project;
    }
}

Design notes:

  • Contains core business logic
  • Use @Transactional for transactions
  • Perform business validations
  • Orchestrate multiple services and mappers
  • No HTTP concerns
  • No direct DB connection handling
  • Service should not return DTO (DTO is an input model). Return Entity/Domain or VO consistently.

Data Access Layer (MyBatis-Plus)

Responsibilities:

  • Define DB access interfaces
  • Provide CRUD abstractions
  • Encapsulate persistence details
  • Provide aggregate query interfaces when needed Template:
public interface ProjectMapper extends BaseMapper<Project> {
}

Design notes:

  • Interfaces only; no concrete implementations
  • Method names clearly express intent
  • No SQL statements here (use XML for complex SQL)
  • No business logic
  • No transaction management
  • Must not depend on the Service layer

Persistence Layer

Responsibilities:

  • SQL mapping and result mapping
  • Entity definitions
  • Database-specific SQL fragments (when needed) Template (MyBatis-Plus XML):
<mapper namespace="com.example.mapper.ProjectMapper">
    <select id="selectActive" resultType="com.example.entity.Project">
        SELECT * FROM project WHERE status = 'CREATED'
    </select>
</mapper>

Design notes:

  • Focus on SQL authoring and optimization
  • Result mapping and type conversion
  • Use SQL fragments for reusability
  • No business logic
  • No business validations
  • Connection management and transaction boundaries are handled by Spring and DataSource

Database Layer

Responsibilities:

  • Persistent storage
  • Data integrity constraints
  • Indexes and performance optimization
  • Transaction support Template (MySQL):
CREATE TABLE project (
    id BIGINT PRIMARY KEY AUTO_INCREMENT,
    created_time DATETIME DEFAULT CURRENT_TIMESTAMP,
    updated_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    customer_id BIGINT NOT NULL,
    status VARCHAR(50) DEFAULT 'CREATED'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

Data Transfer Patterns

Using DTO, VO, and Entity

Frontend → Controller → Service → Mapper → Database
           DTO        Entity    Entity
           VO         Entity

Conversion Example

@PostMapping("/projects")
public ApiReturn<ProjectVo> createProject(@Valid @RequestBody ProjectCreateRequest request) {
    Project project = new Project();
    BeanUtils.copyProperties(request, project);
    Project created = projectService.createProject(project);
    ProjectVo vo = new ProjectVo();
    BeanUtils.copyProperties(created, vo);
    return ApiReturn.of(vo);
}

Exception Handling

Centralized Exception Handling

public class BusinessException extends RuntimeException {
    private final int code;
    public BusinessException(int code, String message) {
        super(message);
        this.code = code;
    }
    public int getCode() {
        return code;
    }
}

@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(BusinessException.class)
    public ApiReturn<Void> handleBusinessException(BusinessException e) {
        return ApiReturn.error(e.getCode(), e.getMessage());
    }
    @ExceptionHandler(Exception.class)
    public ApiReturn<Void> handleException(Exception e) {
        return ApiReturn.error(500, "Internal server error");
    }
}

Transaction Guidelines

  • Transaction boundaries belong to Service methods.
  • Use @Transactional(readOnly = true) for read-only queries.
  • Rollback on RuntimeException by default; document checked-exception rollbacks if needed.
  • Avoid transactions in Controller, Mapper, or XML.

Common Pitfalls

Pitfall 1: Cross-Layer Calls

// Incorrect: Controller directly calls Mapper
@RestController
public class ProjectController {
    private final ProjectMapper projectMapper;
    public ProjectController(ProjectMapper projectMapper) {
        this.projectMapper = projectMapper;
    }
    public List<Project> getProjects() {
        return projectMapper.selectList(null);
    }
}

Pitfall 2: Reverse Dependency

// Incorrect: Service depends on Controller
@Service
public class ProjectService {
    private ProjectController projectController;
}

Pitfall 3: Business Logic in SQL

<!-- Incorrect: business logic embedded in SQL -->
<select id="getById" resultMap="BaseResultMap">
    SELECT * FROM project
    WHERE id = #{id}
      AND is_deleted = 0
      AND has_permission(#{currentUserId}, id) = 1
</select>

Pitfall 4: Returning Entity Directly from Controller

// Incorrect: Controller returns Entity directly
@GetMapping("/projects/{id}")
public Project getProject(@PathVariable Long id) {
    return projectService.getProject(id);
}

Project Structure Template (Recommended)

src/main/java/com/xdyai/backend/
  controller/
    internal/
    request/
  service/
    common/
    context/
    integration/
  mapper/
  entity/
    enumeration/

src/main/resources/
  application.yml
  application-dev.yml
  mapper/
  db/
  validation/
  integration/

Best Practices Summary

Presentation Layer

  • Keep it thin: HTTP logic only
  • Use DTO/VO for data transfer
  • Centralized exception handling
  • No business logic
  • No direct Mapper access

Business Logic Layer

  • Contains core business logic
  • Use @Transactional to manage transactions
  • Orchestrate multiple services
  • No HTTP concerns
  • No direct database connection handling

Data Access Layer

  • Interfaces only
  • Clear method naming
  • CRUD via MyBatis-Plus
  • No SQL statements here
  • No business logic

Persistence Layer

  • Focus on SQL authoring
  • Use SQL fragments
  • Use dynamic SQL for complex queries
  • No business logic
  • No business validations

Cross-Layer Communication

  • Controller ← DTO
  • Service ← Entity
  • Mapper ← Entity
  • Controller ← VO
  • Avoid cross-layer calls
  • Avoid reverse dependencies

平台分布

Codex

35.45%
按下载量换算65

Claude

28.88%
按下载量换算53

Cursor

19.45%
按下载量换算35

Gemini CLI

9.54%
按下载量换算17

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。目前只有一个公开来源,建议同时核对源仓库。

继续浏览同类 Skills