eclipse 自动格式化代码方法windows-->Preferences-->Java --> Editor-->Save Actions, 看到右边的选项,勾选“Perform the selected actions on save”,其他选项根据需要自己选择或者配置就可以了。