User Tools

Site Tools


java:best-practice

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
java:best-practice [2021/08/11 10:56] – external edit 127.0.0.1java:best-practice [2022/06/21 10:29] (current) – [用构造函数代码@Autowired] morgan0329
Line 1: Line 1:
  
 +====== BigDecimal转String ======
 +不要使用 toString()方法,会转成科学计数法的形式。 要用 toPlainString()
 +
 +====== 关于swaggerAPI地址规范 ======
 +<code>
 +/web开头的是 给前端网站使用的
 +/admin开头的是 给内部用户使用的
 +/api开头的是暴露给外部用户使用的(卖给客户的api)
 +
 +然后比如: /web/user (第二层表示 模块名)  
 +
 +/web/user/updatePassword  第三层表示 真正的功能名字
 +
 +</code>
 +
 +
 +====== 用构造函数代码@Autowired ======
 +<code java>
 +  //以前是:
 +  @Autowired
 +  private Environment env;
 +  
 +  //现在是:
 +  private final Environment env;
 +  public UserController(Environment env) {
 +    this.env = env;
 +  }
 +  //优化好的形式:
 +  @RequiredArgsConstructor
 +  public class UserController {
 +    private final Environment env;
 +  }
 +</code>
 +F.Y.I.: https://www.cnblogs.com/acm-bingzi/p/springAutowired.html

Except where otherwise noted, content on this wiki is licensed under the following license: 沪ICP备12046235号-2
Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki