You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在IntelliJ IDEA中设置类型的Javadoc模板?(已会Eclipse操作)

Hey there! Since you already know your way around setting up Javadoc templates in Eclipse, getting this sorted in IntelliJ IDEA is totally straightforward. Let me walk you through the steps to configure class/type-level Javadoc templates—both for auto-generating when you create new types and for quick insertion in existing code:

1. Auto-generate Javadoc when creating new classes/interfaces

This sets up IntelliJ to automatically add a Javadoc comment whenever you create a new class, interface, enum, or other type:

  • Open the Settings window: Use the shortcut Ctrl+Alt+S (Windows/Linux) or Cmd+, (Mac), or go to File > Settings (Windows/Linux) / IntelliJ IDEA > Settings (Mac).
  • Navigate to Editor > File and Code Templates.
  • Switch to the Files tab. Here you'll see templates for all file types, including Class, Interface, Enum, etc.
  • Select the type you want to configure (e.g., Class). In the right-hand editor, you'll see the default template structure.
  • Insert your custom Javadoc block right above the class definition. For example:
    /**
     * ${description}
     * @author ${USER}
     * @since ${DATE}
     */
    
    You can click the Insert Variable button on the right to browse and add more built-in variables (like project name, package, etc.).
  • Hit Apply then OK to save your changes. Next time you create a new class, your custom Javadoc will be added automatically.

2. Quick Javadoc insertion for existing types (via /** shortcut)

If you want to generate a Javadoc comment for an existing class/interface quickly (by typing /** and pressing Enter), here's how to customize that template:

  • Open Settings again and go to Editor > Live Templates.
  • Expand the java group in the left list, then select the doc template (this is the one triggered by /**).
  • Click the Edit variables button on the right.
  • You can tweak the template text and set default values for variables. For example, modify the template to:
    /**
     * $description$
     * @author $user$
     * @since $date$
     $param$
     $return$
     */
    
    For class-level comments, you might want to remove $param$ and $return$ since they're more relevant for methods. Use the Expression dropdown for each variable to set dynamic values (e.g., user() for your username, date() for the current date).
  • Make sure the Applicable in section includes Java: class, Java: interface, and other types you care about—this ensures the template triggers when you're working with those types.
  • Save your settings, and now typing /** above any class/interface will generate your custom Javadoc.

A quick pro tip: If you want a consistent header across all files, you can edit the File Header.java template under the Includes tab in File and Code Templates, but for type-specific Javadoc, sticking to the Files tab templates is the way to go.

内容的提问来源于stack exchange,提问作者lapots

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 07:59:35