日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Eclipse技巧:1.定制toString()模版

發布時間:2025/7/14 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Eclipse技巧:1.定制toString()模版 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

一直對一些問題沒有去深的研究,有人說Intellij好,有人說MyEclipse好,有人說Eclipse好,其實蘿卜青菜各有所愛,只是看大家使用的習慣或者說公司用什么,你不能左右的時候,請去適合周圍的環境,當我們說建立一個類的時候,最后去重寫其toString方法,但是我們是否考慮過生成自己喜歡的風格呢? 下面我就來介紹一下使用Eclipse定制生成toString模版

Eclipse官方文檔

這里我借鑒了 Eclipse官方文檔 文檔說明,稍后再來回顧

Eclipse定制toString模版圖解

  • 1.點擊toString方法

  • 2.點擊編輯按鈕

  • 3.點擊New按鈕設計新的規則

  • 4.定制生成Json格式的規則策略

    {"className":"{object.getClassName}","{member.name()}":"{member.value}","{otherMembers}"} 復制代碼

    點擊OK完成,之后需要在toString的頁面設置

  • 5.最后一步設置

  • 6.生成效果如下

    @Overridepublic String toString() {StringBuilder builder = new StringBuilder();builder.append("{\"");if (this.role_id != null) {builder.append("role_id\":\"");builder.append(this.role_id);builder.append("\",\"");}if (this.role_name != null) {builder.append("role_name\":\"");builder.append(this.role_name);builder.append("\",\"");}if (this.role_key != null) {builder.append("role_key\":\"");builder.append(this.role_key);builder.append("\",\"");}if (this.status != null) {builder.append("status\":\"");builder.append(this.status);}builder.append("\"}");return builder.toString();} 復制代碼

模版屬性簡單說明

${object.className}inserts the class name as a simple String
${object.getClassName}inserts a call to this.getClass.getName()
${object.superToString}inserts a call to super.toString()
${object.hashCode}inserts a call to this.hashCode()
${object.identityHashCode}inserts a call to System.identityHashCode(this)
${member.name}inserts the first member's name
${member.name()}inserts the first member's name followed by parenthesis in case of methods
${member.value}inserts the first member's value
${otherMembers}inserts the remaining members. For each member, the template fragment between the first and the last {member.*} and {otherMembers} must stand after the last ${member.*} variable).

總結

以上是生活随笔為你收集整理的Eclipse技巧:1.定制toString()模版的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。