常用的輪子-工作記錄

不得不說,正確的使用各種輪子對工作效率真的有一種質的提升,終於可以不用加班,不用脫髮。

簡單放一點工作裏用的代碼,詳情請參考官網

  • tkmybatis
    tkmybatis-github官網文檔地址
    可以替代90%的增刪改查,不用在xml裏寫各種sql了,直接用已經寫好的mapper調用就行,作者都幫我們封裝好了。

    public ZwContribution selectDataById(Long id) {
        ZwContribution zwContribution = ZwContribution.builder().id(id).build();
        return zwContributionMapper.selectOne(zwContribution);
    }
    
  • pageHelper
    官網文檔地址
    可以代替分頁,

    Page<Object> startPage = PageHelper.startPage(pageNum, pageSize);
    
  • swagger、swagger-bootstrap-ui
    https://swagger.io/
    https://doc.xiaominfo.com/guide/
    真的方便自己測試,同時可以不用和前端緊密的溝通,直接doc.html網址丟過去就行,自己看就能看得懂,而且都postman都不用了,簡直寶藏輪子。

    實體類:

    @NotBlank(message = "文章內容不能爲空")
    @ApiModelProperty(value = "文章內容", required = true)
    private String articleContent;
    
    @Size(min = 5, max = 26, message = "標題字數需在5-26個字之間")
    @NotBlank(message = "文章標題不能爲空")
    @ApiModelProperty(value = "文章標題", required = true)
    private String articleTitle;
    
    @NotBlank(message = "文章字數不能爲空")
    @ApiModelProperty(value = "文章字數", required = true)
    private String articleNumber;
    

    方法上:

    @ApiOperation(value = "【康羽】前臺-徵文內容保存")
    @PostMapping("/saveData")
    @ApiOperationSupport(order = 1, author = "康羽")
    public ApiResponse<?> saveData(@RequestBody @Validated ZwContributionContentReq zwContributionContentReq) {
        return zwContributionContentService.saveData(zwContributionContentReq);
    }
    
  • lombok
    https://projectlombok.org/
    代碼看起來整潔又易於於維護,通過短短的幾行註解簡直讓人放開了雙手啊。

    @Data
    @Builder
    @Accessors(chain = true)
    @AllArgsConstructor
    @NoArgsConstructor
    @Table(name = "zw_help_user")
    

希望自己以後也能造個好用的輪子,誰有知道呢?

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章