你愿意天天重复敲getter、setter?

2gua

☑编程 ☑读书 ☑美食
写Java,有些简单的代码我就用VS Code了。经常要用到Entity类,但老是重复getter、setter也是很辛苦。
今天忍不住了,给VS Code添加了一段Snippet,专门生成Entity类的:“ 文件 |-> 首选项 |-> 用户代码片段(S) ”打开snippet选择窗口,然后键入“Java”,打开Java对应的snippet设置文件 java.json 。
在 java.json 中添加如下代码:
"Print Entity Class": {
"prefix": "entity",
"body": [
"public class ${1:ClassName} implements Serializable {",
"\tprivate ${2:Type} ${3:PropertyName};",
"\tpublic ${1:ClassName}() {",
"\t}",
"\tpublic ${1:ClassName}(${2:Type} ${3:PropertyName}) {",
"\t\tthis.${3:PropertyName} = ${3:PropertyName};",
"\t}",
"\tpublic ${2:Type} get$4${3:PropertyName}() {",
"\t\treturn this.${3:PropertyName};",
"\t}",
"\tpublic void set$4${3:PropertyName}(${2:Type} ${3:PropertyName}) {",