目录
1. Eclipse平台可以使用eclipse-java-google-style.xml配置
2. IDEA平台可以使用intellij-java-google-style.xml配置
统一代码格式化样式,使用谷歌风格(各种语言和IDE的样式统一风格均有,具体参考GitHub的README.md),谷歌风格样式github地址:https://github.com/google/styleguide;目前希望统一Java后端风格,建议大家每次编码完成去掉无效引用和代码格式化(均可通过快捷键或插件保存时自动格式化实现)
1. Eclipse平台可以使用eclipse-java-google-style.xml配置
1.1 平台配置
1).打开eclipse,选择Window–》Preferences;
2).在弹出的界面中选择,Java–》Code Style–》Formatter;
3).在Formatter中点击Import…并选择eclipse-java-google-style.xml文件;
4).在Active profiles下拉选择GoogleStyle,点击Edit…,在第一个选项卡Indentation中修改Indentation size为4(4个空格缩进)即可;
1.2 保存代码自动格式化设置
1).打开eclipse,选择Window–》Preferences;
2).在弹出的界面中选择,Java–》Editor–》Save Actions–》依次勾选Perform the selected actions on save、Format source code–》选择Format all lines、勾选Organize imports;
3).点击Apply;
2. IDEA平台可以使用intellij-java-google-style.xml配置
2.1 平台配置
1).打开idea,选择File-》Settings-》Plugins,导入离线Google格式化插件gjf.zip(google-java-format),重启idea; 2).重启idea后,选择File-》Settings-》 google-java-format Settings ,勾选Enable google-java-format,Code style 选择 Default Google Java style即可。
2.2 保存代码自动格式化设置
1).打开idea,选择File-》Settings-》Plugins,导入自动格式化插件intellij-plugin-save-actions.jar(网络上各种版本,具体根据自己本地的idea版本下载),重启idea; 2).重启idea后,选择File-》Settings-》 Save Actions ,勾选Formatting actions 前两项即可。在每次使用Ctrl+S保持代码文件时,文件代码格式会自动格式化。