日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) >

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

發(fā)布時(shí)間:2025/7/14 45 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Eclipse技巧:1.定制toString()模版 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

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

Eclipse官方文檔

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

Eclipse定制toString模版圖解

  • 1.點(diǎn)擊toString方法

  • 2.點(diǎn)擊編輯按鈕

  • 3.點(diǎn)擊New按鈕設(shè)計(jì)新的規(guī)則

  • 4.定制生成Json格式的規(guī)則策略

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

    點(diǎn)擊OK完成,之后需要在toString的頁(yè)面設(shè)置

  • 5.最后一步設(shè)置

  • 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();} 復(fù)制代碼

模版屬性簡(jiǎn)單說明

${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).

總結(jié)

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

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。