一.设置格式化模板
java文件,打开eclipse-->“window”--->“preferences”--->“java”-->“Code Style”-->“Formater”,选择写好的模板.xml文件导入即可。
js文件,打开eclipse-->“window”-->“preferences”-->“javascript”-->“Code Style”-->“Formater””,选择写好的模板.xml文件导入即可。
二.保存时自动格式化代码
打开eclipse,选择 window-->Preferences-->JAVA-->Editor-->Save Actions。右边选中:Perform the selected actions on save、Format source code、Format all lines、Organize imports,保存后重启eclipse即可,如下图所示:
对于保存时自动格式化js代码,和以上一样,如下图所示: