commit 62d1c7a378c0b4c749371c47f03af50768699a2c Author: ZhouXY108 Date: Thu Apr 17 15:56:06 2025 +0800 20250417 diff --git a/datasource-config-yml.code-snippets b/datasource-config-yml.code-snippets new file mode 100644 index 0000000..789d981 --- /dev/null +++ b/datasource-config-yml.code-snippets @@ -0,0 +1,13 @@ +{ + "Jpa config yml": { + "prefix": "datasource-config", + "scope": "spring-boot-properties-yaml", + "body": [ + "datasource:", + "\turl: jdbc:${1|postgresql,mariadb|}://${2:localhost}:${3|5432,3306|}/${4:database}", + "\tusername: ${5|postgres,root|}", + "\tpassword: ${6:xxxxxx}", + ], + "description": "datasource-config", + } +} \ No newline at end of file diff --git a/http.code-snippets b/http.code-snippets new file mode 100644 index 0000000..08d4527 --- /dev/null +++ b/http.code-snippets @@ -0,0 +1,17 @@ +{ + "post-json": { + "scope": "http", + "prefix": "post-json", + "body": [ + "### description", + "POST http://${1:zhouxy.xyz/api} HTTP/1.1", + "Accept: application/json", + "Content-Type: application/json", + "$2", + "", + "{", + " \"${3:key}\": ${4:value}$5", + "}", + ] + }, +} diff --git a/java-enumeration.code-snippets b/java-enumeration.code-snippets new file mode 100644 index 0000000..76e7668 --- /dev/null +++ b/java-enumeration.code-snippets @@ -0,0 +1,32 @@ +{ + "Create a Enumeration": { + "scope": "java", + "prefix": "enumeration", + "isFileTemplate": true, + "body": [ + "import java.util.Collection;", + "", + "import xyz.zhouxy.plusone.commons.util.Enumeration;", + "", + "public final class ${1:$TM_FILENAME_BASE} extends Enumeration<${1:$TM_FILENAME_BASE}> {", + "", + "\tprivate ${1:$TM_FILENAME_BASE}(int id, String name) {", + "\t\tsuper(id, name);", + "\t}", + "", + "\tpublic static final ${1:$TM_FILENAME_BASE} ${2:EXAMPLE} = new ${1:$TM_FILENAME_BASE}(${3:0}, \"${4:正常}\");$5", + "", + "\tprivate static final ValueSet<${1:$TM_FILENAME_BASE}> VALUE_SET = ValueSet.of(${2:EXAMPLE}$6);", + "", + "\tpublic static ${1:$TM_FILENAME_BASE} of(int id) {", + "\t\treturn VALUE_SET.get(id);", + "\t}", + "", + "\tpublic static Collection<${1:$TM_FILENAME_BASE}> values() {", + "\t\treturn VALUE_SET.getValues();", + "\t}", + "}", + "" + ], + } +} \ No newline at end of file diff --git a/java.code-snippets b/java.code-snippets new file mode 100644 index 0000000..8d50b34 --- /dev/null +++ b/java.code-snippets @@ -0,0 +1,513 @@ +{ + "Import Java Utils": { + "scope": "java", + "prefix": "import_java_util", + "body": [ + "import java.util.${1|*,Objects,Collection,List,ArrayList,LinkedList,Map,HashMap,ConcurrentHashMap,Set,HashSet,Collections,Arrays|};", + ], + "description": "Import classes in package java.util." + }, + "Import Java Time": { + "scope": "java", + "prefix": "import_java_time", + "body": [ + "import java.time.${1|*,LocalDateTime,LocalDate,LocalTime,ZoneDateTime,ZoneId,ZoneOffset,ZoneRegion,Year,Month,MonthDay,DayOfWeek,YearMonth|};", + ], + "description": "Import classes in package java.time." + }, + "const": { + "scope": "java", + "prefix": "const", + "body": "${1|private ,protected ,public |}static final ${2:String} ${3:CONST_NAME} = $4;" + }, + "iterator": { + "scope": "java", + "prefix": "iterator", + "body": [ + "final Iterator<${2|Integer,Long,String|}> ${3:iterator} = $1.iterator();", + "while (${3:iterator}.hasNext()) {", + "\tfinal ${2|Integer,Long,String|} ${4:item} = ${3:iterator}.next();", + "\t$5", + "}", + ] + }, + "Throw exception": { + "scope": "java", + "prefix": "thr", + "body": "throw $0;" + }, + "Throw new exception": { + "scope": "java", + "prefix": ["thrownew", "thn"], + "body": "throw new ${1|IllegalArgumentException,IllegalStateException,NullPointerException,UnsupportedOperationException,ArithmeticException,ClassCastException,ArrayIndexOutOfBoundsException,NumberFormatException,RuntimeException,EnumConstantNotPresentException|}($2);", + "description": "Throw new exception" + }, + "Return result": { + "scope": "java", + "prefix": "ret", + "body": [ + "return ${1|this,result|};", + ], + "description": "Return result" + }, + "Return success": { + "scope": "java", + "prefix": "success", + "body": [ + "return UnifiedResponses.success($1);", + ], + "description": "return UnifiedResponses#success" + }, + "Charset": { + "scope": "java", + "prefix": "charset", + "body": "StandardCharsets.${1|UTF_8,UTF_16,UTF_16BE,UTF_16LE,US_ASCII,ISO_8859_1|}" + }, + "GetById": { + "scope": "java", + "prefix": "getById", + "body": [ + "@GetMapping(\"{${2:id}}\")", + "public UnifiedResponse ${1:findById}(@PathVariable(\"${2:id}\") Long ${2:id}) {", + "\tvar result = $4;", + "\treturn UnifiedResponses.success(${3:\"查询成功\"}, result);", + "}", + ] + }, + "Constructor": { + "scope": "java", + "prefix": "constructor", + "body": [ + "${1|public ,protected ,private |}${2:$TM_FILENAME_BASE}($3) {$4", + "}", + ] + }, + "Constructor for utility class": { + "scope": "java", + "prefix": "constructor-for-utility-class", + "body": [ + "$2", + "", + "private ${1:$TM_FILENAME_BASE}() {", + "\tthrow new IllegalStateException(\"Utility class\");", + "}", + ] + }, + "Field": { + "scope": "java", + "prefix": "field", + "body": "${1|private ,protected ,public |}${4|@Getter ,@Setter ,@Getter @Setter |}${2:String} ${3:username};" + }, + "Internal method": { + "scope": "java", + "prefix": "internal_method", + "body": [ + "/*$5 */", + "${1|private ,protected |}${2:void} ${3:method}Internal($4) {", + "\t", + "}" + ] + }, + "Static internal method": { + "scope": "java", + "prefix": "static_internal_method", + "body": [ + "/*$5 */", + "${1|private ,protected |}static ${2:void} ${3:method}Internal($4) {", + "\t", + "}" + ] + }, + "TODO": { + "scope": "java,javascript,typescript", + "prefix": ["TODO", "todo"], + "body": "// TODO [${1|修复,添加,优化,重构|}] ${2:msg}", + "description": "待办事项" + }, + "FIXME": { + "scope": "java,javascript,typescript", + "prefix": ["FIXME", "fixme"], + "body": "// FIXME $1", + "description": "修复" + }, + "XXX": { + "scope": "java,javascript,typescript", + "prefix": ["XXX", "xxx"], + "body": "// XXX $1", + "description": "待优化" + }, + "NOSONAR": { + "scope": "java,javascript,typescript", + "prefix": [ + "nosonar", + "sonarIgnore" + ], + "body": "// NOSONAR$1" + }, + "Slf4jLog": { + "scope": "java", + "prefix": "log-slf4j", + "body": "private static final Logger log = LoggerFactory.getLogger(${1:$TM_FILENAME_BASE}.class);" + }, + "log a var": { + "scope": "java", + "prefix": "log-var", + "body": "log.${1|info,debug,error|}(\"${2:var}: {}\", ${2:var});" + }, + "log a obj": { + "scope": "java", + "prefix": "log-obj", + "body": "log.${1|info,debug,error|}(\"{}\", ${2:var});" + }, + "List": { + "scope": "java", + "prefix": "list", + "body": "List<${1:T}> ${2:list} = new ${3|ArrayList,LinkedList|}<>($4);" + }, + "HashMap": { + "scope": "java", + "prefix": "map", + "body": "Map<${1:K}, ${2:V}> ${3:map} = new ${4|HashMap,ConcurrentHashMap|}<>($5);" + }, + "collect": { + "scope": "java", + "prefix": "collect", + "body": ".collect(Collectors.${1|toSet(),toList()|})" + }, + "toArray": { + "scope": "java", + "prefix": "toArray", + "body": ".toArray(${1|String,Integer,Long,SqlParameterSource|}[]::new)" + }, + "SuppressWarnings": { + "scope": "java", + "prefix": "suppressWarnings", + "body": "@SuppressWarnings(\"${1|all,boxing,cast,dep-ann,deprecation,fallthrough,finally,hiding,incomplete-switch,nls,null,rawtypes,restriction,serial,static-access,synthetic-access,unchecked,unqualified-field-access,unused|}\")", + }, + "TimeMillis' now": { + "scope": "java", + "prefix": "now", + "body": "${2|long,var|} ${1:now} = System.currentTimeMillis();" + }, + "Date's now": { + "scope": "java", + "prefix": "now", + "body": "${2|Date,var|} ${1:now} = new Date();" + }, + "LocalDateTime's now": { + "scope": "java", + "prefix": "now", + "body": "${2|LocalDateTime,var|} ${1:now} = LocalDateTime.now();" + }, + "ZonedDateTime's now": { + "scope": "java", + "prefix": "now", + "body": "${2|ZonedDateTime,var|} ${1:now} = ZonedDateTime.now();" + }, + "Instant's now": { + "scope": "java", + "prefix": "now", + "body": "${2|Instant,var|} ${1:now} = Instant.now();" + }, + "today": { + "scope": "java", + "prefix": "today", + "body": "${2|LocalDate,var|} ${1|now,today|} = LocalDate.now();" + }, + "Get Optional": { + "scope": "java", + "prefix": "optional_getter", + "body": [ + "public Optional<${1:Email}> get${2:Email}() {", + "\treturn Optional.ofNullable(${3:email});", + "}", + ] + }, + "lombok-pojo": { + "scope": "java", + "prefix": "lombok-pojo", + "body": [ + "@Getter", + "@Setter", + "@NoArgsConstructor", + "@ToString${1:(callSuper = true)}", + ] + }, + "Copyright Apache License 2.0": { + "scope": "java", + "prefix": "copyright-apache-license-2", + "body": [ + "/*", + " * Copyright ${1:$CURRENT_YEAR}-${2:$CURRENT_YEAR} ${3:the original author or authors}.", + " *", + " * Licensed under the Apache License, Version 2.0 (the \"License\");", + " * you may not use this file except in compliance with the License.", + " * You may obtain a copy of the License at", + " *", + " * https://www.apache.org/licenses/LICENSE-2.0", + " *", + " * Unless required by applicable law or agreed to in writing, software", + " * distributed under the License is distributed on an \"AS IS\" BASIS,", + " * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + " * See the License for the specific language governing permissions and", + " * limitations under the License.", + " */\n", + ] + }, + "JavaDoc for class": { + "scope": "java", + "prefix": "javadoc-class", + "body": [ + "/**", + " * ${1:$TM_FILENAME_BASE}", + " *", + " *

", + " * ${2:description}", + " *

", + " *", + " *

", + " * NOTE: ${3:content}.", + " *

", + " * @author ${4:${6:ZhouXY}}", + " * @since $7", + " * @see $8", + " */", + ], + "description": "JavaDoc for class" + }, + "inheritDoc": { + "scope": "java", + "prefix": ["javadoc-inheritDoc", "doc-inheritDoc"], + "body": "/** {@inheritDoc} */" + }, + "Jdbc Template": { + "scope": "java", + "prefix": "jdbc", + "body": "private final ${1|NamedParameterJdbcTemplate,JdbcTemplate|} ${2:jdbcTemplate};" + }, + "JUnit4 test class": { + "scope": "java", + "prefix": "test-class-junit4", + "isFileTemplate": true, + "body": [ + "import org.junit.Test;", + "", + "import static org.junit.Assert.*;", + "", + "public class ${1:$TM_FILENAME_BASE} {", + "", + "\t@Test", + "\tpublic void test$2() {", + "\t\t$3", + "\t}", + "}", + "", + ] + }, + "JUnit4 test case": { + "scope": "java", + "prefix": "test-case-junit4", + "body": [ + "@Test", + "public void test$1() {", + "\t$2", + "}" + ] + }, + "JUnit5 test class": { + "scope": "java", + "isFileTemplate": true, + "prefix": "test-class-junit5", + "body": [ + "import static org.junit.jupiter.api.Assertions.*;", + "", + "import org.junit.jupiter.api.Test;", + "", + "public class ${1:$TM_FILENAME_BASE} {", + "", + "\t@Test", + "\tvoid test$2() {", + "\t\t$3", + "\t}", + "}", + "" + ] + }, + "JUnit5 test case": { + "scope": "java", + "prefix": "test-case-junit5", + "body": [ + "@Test", + "void test$1() {", + "\t$2", + "}" + ] + }, + "ParameterizedTest": { + "prefix": "parameterized-test", + "body": [ + "@ParameterizedTest", + "@ValueSource(${2|strings,ints,shorts,bytes,longs,floats,doubles,chars,booleans,classes|} = { $3 })", + "void test$1(${4|String,int,short,byte,long,float,double,char,boolean,Class|} $5) {", + "\t$6", + "}" + ], + "description": "ParameterizedTest" + }, + "SerializableUID": { + "scope": "java", + "prefix": "serializableUID", + "body": [ + "private static final long serialVersionUID = ${1:${RANDOM/(0)//}$CURRENT_DATE$CURRENT_MONTH$CURRENT_YEAR_SHORT$CURRENT_SECOND$CURRENT_MINUTE$CURRENT_HOUR}L;" + ] + }, + "Exception": { + "scope": "java", + "prefix": "exception", + "body": [ + "class ${1:$TM_FILENAME_BASE} extends ${2|RuntimeException,Exception|} {", + "\tprivate static final long serialVersionUID = ${3:${RANDOM/(0)//}$CURRENT_DATE$CURRENT_MONTH$CURRENT_YEAR_SHORT$CURRENT_SECOND$CURRENT_MINUTE$CURRENT_HOUR}L;", + "", + "\t/**", + "\t * Constructs a new {@code ${1:$TM_FILENAME_BASE}} with null as its detail message.", + "\t * The cause is not initialized, and may subsequently be initialized by a call to initCause.", + "\t */", + "\t${4|public,protected|} ${1:$TM_FILENAME_BASE}() {", + "\t\tsuper();", + "\t}", + "", + "\t/**", + "\t * Constructs a new {@code ${1:$TM_FILENAME_BASE}} with the specified detail message.", + "\t * The cause is not initialized, and may subsequently be initialized by a", + "\t * call to {@link #initCause}.", + "\t *", + "\t * @param message the detail message. The detail message is saved for", + "\t * later retrieval by the {@link #getMessage()} method.", + "\t */", + "\t${4|public,protected|} ${1:$TM_FILENAME_BASE}(String message) {", + "\t\tsuper(message);", + "\t}", + "", + "\t/**", + "\t * Constructs a new {@code ${1:$TM_FILENAME_BASE}} with the specified cause and a", + "\t * detail message of {@code (cause==null ? null : cause.toString())}", + "\t * (which typically contains the class and detail message of {@code cause}).", + "\t * This constructor is useful for exceptions", + "\t * that are little more than wrappers for other throwables.", + "\t *", + "\t * @param cause the cause (which is saved for later retrieval by the", + "\t * {@link #getCause()} method). (A {@code null} value is", + "\t * permitted, and indicates that the cause is nonexistent or", + "\t * unknown.)", + "\t */", + "\t${4|public,protected|} ${1:$TM_FILENAME_BASE}(Throwable cause) {", + "\t\tsuper(cause);", + "\t}", + "", + "\t/**", + "\t * Constructs a new {@code ${1:$TM_FILENAME_BASE}} with the specified detail message and", + "\t * cause.

Note that the detail message associated with", + "\t * {@code cause} is not automatically incorporated in", + "\t * this exception's detail message.", + "\t *", + "\t * @param message the detail message (which is saved for later retrieval", + "\t * by the {@link #getMessage()} method).", + "\t * @param cause the cause (which is saved for later retrieval by the", + "\t * {@link #getCause()} method). (A {@code null} value is", + "\t * permitted, and indicates that the cause is nonexistent or", + "\t * unknown.)", + "\t */", + "\t${4|public,protected|} ${1:$TM_FILENAME_BASE}(String message, Throwable cause) {", + "\t\tsuper(message, cause);", + "\t}", + "}", + ], + }, + "#region": { + "scope": "java", + "prefix": "#regoin", + "body": [ + "// ================================", + "// #region - $1", + "// ================================", + "", + "$TM_SELECTED_TEXT", + "", + "// ================================", + "// #endregion - $1", + "// ================================", + ] + }, + "=if": { + "scope": "java", + "prefix": "=if", + "body": [ + "if ($1) {", + "\t${2:var} = ${3:value};", + "}", + ] + }, + "String line": { + "scope": "java", + "prefix": "line", + "body": "+ \"\\n\" + \"$1\"" + }, + "Static factory method": { + "scope": "java", + "prefix": ["staticFactoryMethod", "of"], + "body": [ + "@StaticFactoryMethod(${1:$TM_FILENAME_BASE}.class)", + "public static ${1:$TM_FILENAME_BASE} of($2) {", + "\treturn new ${1:$TM_FILENAME_BASE}($3);", + "}", + ] + }, + "Static factory method with type param": { + "scope": "java", + "prefix": ["staticFactoryMethodWithTypeParam", "of_T"], + "body": [ + "@StaticFactoryMethod(${1:$TM_FILENAME_BASE}.class)", + "public static <${2:T}> ${1:$TM_FILENAME_BASE}<${2:T}> of($3) {", + "\treturn new ${1:$TM_FILENAME_BASE}<>($4);", + "}", + ] + }, + // assert + "Import AssertTools": { + "scope": "java", + "prefix": "import_assert_tools", + "body": [ + "", + "import static xyz.zhouxy.plusone.commons.util.AssertTools.*;", + "", + ] + }, + "AssertTools.checkCondition": { + "scope": "java", + "prefix": "assert_checkCondition", + "body": [ + "AssertTools.checkCondition($3, () -> new ${1|IllegalArgumentException,IllegalStateException,NullPointerException,UnsupportedOperationException,ArithmeticException,ClassCastException,ArrayIndexOutOfBoundsException,NumberFormatException,RuntimeException,EnumConstantNotPresentException|}($2));" + ] + }, + "AssertTools.checkArgument": { + "scope": "java", + "prefix": "assert_checkArgument", + "body": [ + "AssertTools.checkArgument(${1|StringTools.isNotBlank,Objects.nonNull|}($2)${3:, \"$4\"});" + ] + }, + "Lock": { + "scope": "java", + "prefix": "lock", + "body": [ + "${1:lock}.lock();", + "try {", + "\t// access the resource protected by this lock", + "\t$2", + "}", + "finally {", + "\t${1:lock}.unlock();", + "}", + ] + } +} diff --git a/javadoc.code-snippets b/javadoc.code-snippets new file mode 100644 index 0000000..31e9563 --- /dev/null +++ b/javadoc.code-snippets @@ -0,0 +1,9 @@ +{ + "code": { + "prefix": "@code", + "body": [ + "{@code $TM_SELECTED_TEXT}" + ], + "scope": "java" + } +} diff --git a/jdk_config.code-snippets b/jdk_config.code-snippets new file mode 100644 index 0000000..062ce85 --- /dev/null +++ b/jdk_config.code-snippets @@ -0,0 +1,42 @@ +{ + "JdkConfigWin": { + "scope": "jsonc", + "prefix": "jdk_config-win", + "body": [ + "\"maven.terminal.customEnv\": [", + "\t{", + "\t\t\"environmentVariable\": \"JAVA_HOME\",", + "\t\t\"value\": \"${2:$}{env:JDK_${1:8}}\",", + "\t},", + "],", + "\"terminal.integrated.env.windows\": {", + "\t\"JAVA_HOME\": \"${2:$}{env:JDK_${1:8}}\",", + "\t\"path\": \"${2:$}{env:JDK_${1:8}}/bin;${2:$}{env:path}\",", + "}," + ], + "description": "Config JDK version in settings.json of VS Code." + }, + "JdkConfigLinux": { + "scope": "jsonc", + "prefix": "jdk_config-linux", + "body": [ + "\"java.configuration.runtimes\": [", + "\t{", + "\t\t\"name\": \"JavaSE-1.8\",", + "\t\t\"path\": \"/home/zhouxy/softwares/jdk/jdk-8\"", + "\t}", + "],", + "\"maven.terminal.customEnv\": [", + "\t{", + "\t\t\"environmentVariable\": \"JAVA_HOME\",", + "\t\t\"value\": \"/home/zhouxy/softwares/jdk/jdk-8\",", + "\t},", + "],", + "\"terminal.integrated.env.linux\": {", + "\t\"JAVA_HOME\": \"/home/zhouxy/softwares/jdk/jdk-8\",", + "\t\"PATH\": \"/home/zhouxy/softwares/jdk/jdk-8/bin:$$0{env:PATH}\",", + "},", + ], + "description": "Config JDK version in settings.json of VS Code." + } +} diff --git a/jpa-config-yml.code-snippets b/jpa-config-yml.code-snippets new file mode 100644 index 0000000..0ba5741 --- /dev/null +++ b/jpa-config-yml.code-snippets @@ -0,0 +1,24 @@ +{ + // Place your snippets for spring-boot-properties-yaml here. Each snippet is defined under a snippet name and has a prefix, body and + // description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are: + // $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the + // same ids are connected. + // Example: + "Jpa config yml": { + "prefix": "jpa-config-yml", + "scope": "yaml", + "body": [ + "spring:", + "\tdatasource:", + "\t\turl: jdbc:mariadb://${1:localhost}:3306/${2:database}", + "\t\tusername: ${3:root}", + "\t\tpassword: ${4:zhouxy108}", + "\t\tdriver-class-name: org.mariadb.jdbc.Driver", + "\tjpa:", + "\t\tshow-sql: true", + "\t\thibernate:", + "\t\t\tddl-auto: update", + ], + "description": "jpa-config-yml" + } +} \ No newline at end of file diff --git a/map-pojo.code-snippets b/map-pojo.code-snippets new file mode 100644 index 0000000..b64a1a8 --- /dev/null +++ b/map-pojo.code-snippets @@ -0,0 +1,22 @@ +{ + "Getter of MapPojo's field": { + "scope": "java", + "prefix": "getterOfMapPojo", + "body": [ + "public ${3:String} get${2:FieldName}() {", + " return (${3:String}) this.fields.get(\"${1:field_name}\");", + "}", + ], + "description": "Getter of MapPojo's field." + }, + "Setter of MapPojo's field": { + "scope": "java", + "prefix": "setterOfMapPojo", + "body": [ + "public ${5:Pojo} set${3:FieldName}(String ${2:fieldName}) {", + " this.fields.put(\"${1:field_name}\", ${2:fieldName});${4:\n return this;}", + "}", + ], + "description": "Setter of MapPojo's field." + }, +} diff --git a/maven-aliyun-mirror.code-snippets b/maven-aliyun-mirror.code-snippets new file mode 100644 index 0000000..7a62a51 --- /dev/null +++ b/maven-aliyun-mirror.code-snippets @@ -0,0 +1,33 @@ +{ + "Print to console": { + "scope": "xml", + "prefix": "aliyun-mirror", + "body": [ + "", + "\t", + "\t\taliyun", + "\t\thttps://maven.aliyun.com/repository/public", + "\t\t", + "\t\t\ttrue", + "\t\t", + "\t\t", + "\t\t\tfalse", + "\t\t", + "\t", + "", + "", + "\t", + "\t\taliyun-plugin", + "\t\thttps://maven.aliyun.com/repository/public", + "\t\t", + "\t\t\ttrue", + "\t\t", + "\t\t", + "\t\t\tfalse", + "\t\t", + "\t", + "", + ], + "description": "pom.xml 中配置阿里云镜像" + } +} \ No newline at end of file diff --git a/multi-types-exception.code-snippets b/multi-types-exception.code-snippets new file mode 100644 index 0000000..f927f36 --- /dev/null +++ b/multi-types-exception.code-snippets @@ -0,0 +1,86 @@ +{ + "Multi-types Exception": { + "scope": "java", + "prefix": "multi-types-exception", + "body": [ + "public final class ${2:$TM_FILENAME_BASE}", + "\t\textends ${3|RuntimeException,Exception,BizException,SysException|}", + "\t\timplements MultiTypesException<${2:$TM_FILENAME_BASE}, ${2:$TM_FILENAME_BASE}.Type> {", + "\tprivate static final long serialVersionUID = ${4:${RANDOM/(0)//}$CURRENT_DATE$CURRENT_MONTH$CURRENT_YEAR_SHORT$CURRENT_SECOND$CURRENT_MINUTE$CURRENT_HOUR}L;", + "", + "\tprivate final ${1|@NonNull ,@Nonnull |}Type type;", + "", + "\tprivate ${2:$TM_FILENAME_BASE}(${1|@NonNull ,@Nonnull |}Type type) {", + "\t\tsuper(type.getDefaultMessage());", + "\t\tthis.type = type;", + "\t}", + "", + "\tprivate ${2:$TM_FILENAME_BASE}(${1|@NonNull ,@Nonnull |}Type type, @Nullable String msg) {", + "\t\tsuper(msg);", + "\t\tthis.type = type;", + "\t}", + "", + "\tprivate ${2:$TM_FILENAME_BASE}(${1|@NonNull ,@Nonnull |}Type type, @Nullable Throwable cause) {", + "\t\tsuper(cause);", + "\t\tthis.type = type;", + "\t}", + "", + "\tprivate ${2:$TM_FILENAME_BASE}(${1|@NonNull ,@Nonnull |}Type type, @Nullable String msg, @Nullable Throwable cause) {", + "\t\tsuper(msg, cause);", + "\t\tthis.type = type;", + "\t}", + "", + "\t@Override", + "\tpublic ${1|@NonNull ,@Nonnull |}Type getType() {", + "\t\treturn type;", + "\t}", + "", + "\tpublic enum Type implements ExceptionType<${2:$TM_FILENAME_BASE}> {", + "\t\tDEFAULT(\"00\", \"$5\"),", + "\t\t// TODO other types", + "\t\t;", + "", + "\t\tprivate final ${1|@NonNull ,@Nonnull |}String code;", + "\t\tprivate final ${1|@NonNull ,@Nonnull |}String defaultMessage;", + "", + "\t\tType(${1|@NonNull ,@Nonnull |}String code, ${1|@NonNull ,@Nonnull |}String defaultMessage) {", + "\t\t\tthis.code = code;", + "\t\t\tthis.defaultMessage = defaultMessage;", + "\t\t}", + "", + "\t\t@Override", + "\t\tpublic ${1|@NonNull ,@Nonnull |}String getCode() {", + "\t\t\treturn code;", + "\t\t}", + "", + "\t\t@Override", + "\t\tpublic ${1|@NonNull ,@Nonnull |}String getDefaultMessage() {", + "\t\t\treturn defaultMessage;", + "\t\t}", + "", + "\t\t@Override", + "\t\tpublic ${1|@NonNull ,@Nonnull |}${2:$TM_FILENAME_BASE} create() {", + "\t\t\treturn new ${2:$TM_FILENAME_BASE}(this);", + "\t\t}", + "\t", + "\t\t@Override", + "\t\tpublic ${1|@NonNull ,@Nonnull |}${2:$TM_FILENAME_BASE} create(@Nullable String message) {", + "\t\t\treturn new ${2:$TM_FILENAME_BASE}(this, message);", + "\t\t}", + "\t", + "\t\t@Override", + "\t\tpublic ${1|@NonNull ,@Nonnull |}${2:$TM_FILENAME_BASE} create(@Nullable Throwable cause) {", + "\t\t\treturn new ${2:$TM_FILENAME_BASE}(this, cause);", + "\t\t}", + "\t", + "\t\t@Override", + "\t\tpublic ${1|@NonNull ,@Nonnull |}${2:$TM_FILENAME_BASE} create(@Nullable String message, @Nullable Throwable cause) {", + "\t\t\treturn new ${2:$TM_FILENAME_BASE}(this, message, cause);", + "\t\t}", + "\t}", + "}", + "", + ], + "description": "Exception with multiple types." + } +} diff --git a/mybatis-mapper.code-snippets b/mybatis-mapper.code-snippets new file mode 100644 index 0000000..e2b065d --- /dev/null +++ b/mybatis-mapper.code-snippets @@ -0,0 +1,607 @@ +{ + "Mybatis mapper template": { + "scope": "xml", + "prefix": "mybatis-mapper", + "isFileTemplate": true, + "body": [ + "", + "", + "", + "\t", + "\t", + "\t", + "\t\tINSERT INTO ${4:module_short_name}_${6:entity}", + "\t\t(", + "\t\t\temail, phone_num, username, password, salt, avatar, sex, nickname, remarks, status,", + "\t\t\t# TODO: other columns", + "\t\t\tcreated_by, created_time, updated_by, updated_time, version", + "\t\t)", + "\t\tVALUES", + "\t\t(", + "\t\t\t#{email}, #{phoneNum}, #{username}, #{password}, #{salt}, #{avatar}, #{sex}, #{nickname}, #{remarks}, #{status},", + "\t\t\t# TODO: other properties", + "\t\t\t#{createdBy}, #{createdTime}, #{updatedBy}, #{updatedTime}, #{version}", + "\t\t)", + "\t", + "", + "\t", + "\t", + "\t", + "\t\tUPDATE ${4:module_short_name}_${6:entity}", + "\t\tSET deleted = id,", + "\t\t\tversion = version + 1", + "\t\tWHERE deleted = 0 AND id = #{id} AND version = #{version}", + "\t", + "", + "\t", + "\t", + "\t", + "\t\tUPDATE ${4:module_short_name}_${6:entity}", + "\t\tSET email\t\t= #{email},", + "\t\t\tphone_num\t= #{phoneNum},", + "\t\t\tusername\t = #{username},", + "\t\t\tpassword\t = #{password},", + "\t\t\tsalt\t\t = #{salt},", + "\t\t\tavatar\t = #{avatar},", + "\t\t\tsex\t\t = #{sex},", + "\t\t\tnickname\t = #{nickname},", + "\t\t\tremarks\t = #{remarks},", + "\t\t\tstatus\t = #{status},", + "\t\t\t# TODO: other columns", + "\t\t\t# created_by = #{createdBy},", + "\t\t\t# created_time = #{createdTime},", + "\t\t\tupdated_by = #{updatedBy},", + "\t\t\tupdated_time = #{updatedTime},", + "\t\t\tversion = version + 1", + "\t\tWHERE deleted = 0 AND id = #{id} AND version = #{version}", + "\t", + "", + "\t", + "", + "\t", + "\t\tSELECT", + "\t\t\t${8:a}.id\t\t AS ${8:a}_id,", + "\t\t\t${8:a}.email\t\tAS ${8:a}_email,", + "\t\t\t${8:a}.phone_num\tAS ${8:a}_phone_num,", + "\t\t\t${8:a}.username\t AS ${8:a}_username,", + "\t\t\t${8:a}.password\t AS ${8:a}_password,", + "\t\t\t${8:a}.salt\t\t AS ${8:a}_salt,", + "\t\t\t${8:a}.avatar\t AS ${8:a}_avatar,", + "\t\t\t${8:a}.sex\t\t AS ${8:a}_sex,", + "\t\t\t${8:a}.nickname\t AS ${8:a}_nickname,", + "\t\t\t${8:a}.remarks\t AS ${8:a}_remarks,", + "\t\t\t${8:a}.status\t AS ${8:a}_status,", + "\t\t\t# TODO: other columns", + "\t\t\t${8:a}.created_by AS ${8:a}_created_by,", + "\t\t\t${8:a}.created_time AS ${8:a}_created_time,", + "\t\t\t${8:a}.updated_by AS ${8:a}_updated_by,", + "\t\t\t${8:a}.updated_time AS ${8:a}_updated_time,", + "\t\t\t${8:a}.version\t AS ${8:a}_version", + "\t\tFROM ${4:module_short_name}_${6:entity} AS ${8:a}", + "\t", + "", + "\t", + "\t\t", + "\t\t", + "\t\t", + "\t\t", + "\t\t", + "\t\t", + "\t\t", + "\t\t", + "\t\t", + "\t\t", + "\t\t", + "\t\t", + "\t\t", + "\t\t", + "\t\t", + "\t\t", + "\t\t", + "\t", + "", + "\t", + "\t", + "", + "\t", + "\t", + "", + "\t", + "\t", + "", + "\t", + "\t", + "", + "\t", + "\t", + "", + "\t", + "\t", + "\t\tDELETE FROM ${4:module_short_name}_${6:entity}_${11:entity2} WHERE ${6:entity}_id = #{id}", + "\t", + "", + "\t", + "\t", + "\t\tINSERT INTO ${4:module_short_name}_${6:entity}_${11:entity2}(${6:entity}_id, ${11:entity2}_id)", + "\t\tVALUES", + "\t\t", + "\t\t\t(#{id}, #{${11:entity2}_id})", + "\t\t", + "\t", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + ], + "description": "Mybatis mapper 模板" + } +} \ No newline at end of file diff --git a/popular-dependencies.code-snippets b/popular-dependencies.code-snippets new file mode 100644 index 0000000..4085995 --- /dev/null +++ b/popular-dependencies.code-snippets @@ -0,0 +1,191 @@ +{ + "guava": { + "scope": "xml", + "prefix": "guava", + "body": [ + "", + " com.google.guava", + " guava", + " ${1:${2|${guava.version},33.2.1-jre|}}${3:\n\ttrue}", + "" + ], + }, + "apache-commons": { + "scope": "xml", + "prefix": "apache-commons", + "body": [ + "", + " org.apache.commons", + " ${1|commons-lang3,commons-collections4,commons-math3,commons-pool2|}", + " ${${1|commons-lang3,commons-collections4,commons-math3,commons-pool2|}.version}", + "", + ], + }, + "commons-io": { + "scope": "xml", + "prefix": "commons-io", + "body": [ + "", + " commons-io", + " commons-io", + " ${commons-io.version}", + "", + ], + }, + "Apache Commons Crypto": { + "scope": "xml", + "prefix": "commons-crypto", + "body": [ + "", + " org.apache.commons", + " commons-crypto", + " 1.2.0", + "", + ], + }, + "mica-xss": { + "scope": "xml", + "prefix": "mica-xss", + "body": [ + "", + " net.dreamlu", + " mica-xss", + " ${1|${mica-xss.version},2.7.18.6,3.3.2|}", + "", + ], + }, + "mybatis-spring-boot-starter": { + "scope": "xml", + "prefix": "mybatis-spring-boot-starter", + "body": [ + "", + " org.mybatis.spring.boot", + " mybatis-spring-boot-starter", + " ${mybatis-starter.version}", + "", + ], + }, + "mapstruct": { + "scope": "xml", + "prefix": "mapstruct", + "body": [ + "", + " org.mapstruct", + " mapstruct", + " ${mapstruct.version}", + "", + "", + " org.mapstruct", + " mapstruct-processor", + " ${mapstruct.version}", + "", + ], + }, + "hutool": { + "scope": "xml", + "prefix": "hutool", + "body": [ + "", + " cn.hutool", + " ${1|hutool-core,hutool-crypto,hutool-captcha,hutool-json,hutool-poi,hutool-jwt,hutool-aop,hutool-bloomFilter,hutool-cache,hutool-cron,hutool-db,hutool-dfa,hutool-extra,hutool-http,hutool-log,hutool-script,hutool-setting,hutool-system,hutool-socket|}", + " ${hutool.version}", + "", + ], + }, + "JUnit4": { + "scope": "xml", + "prefix": "junit4", + "body": [ + "", + "\tjunit", + "\tjunit", + "\t4.11", + "\ttest", + "", + ] + }, + "JUnit5": { + "scope": "xml", + "prefix": "junit5", + "body": [ + "", + "\torg.junit.jupiter", + "\tjunit-jupiter-api", + "\t5.9.2", + "\ttest", + "", + "", + "\torg.junit.jupiter", + "\tjunit-jupiter-engine", + "\t5.9.2", + "\ttest", + "", + "", + "\torg.junit.jupiter", + "\tjunit-jupiter-params", + "\t5.9.2", + "\ttest", + "", + ] + }, + "jsr305": { + "scope": "xml", + "prefix": "jsr305", + "body": [ + "", + "\tcom.google.code.findbugs", + "\tjsr305", + "\t${1:3.0.2}$2", + "", + ] + }, + "gson": { + "scope": "xml", + "prefix": "gson", + "body": [ + "", + "\tcom.google.code.gson", + "\tgson", + "\t${1:2.11.0}$2", + "", + ] + }, + "joda-time": { + "scope": "xml", + "prefix": "joda-time", + "body": [ + "", + "\tjoda-time", + "\tjoda-time", + "\t${1:2.12.7}", + "", + ] + }, + "maven-shade-plugin": { + "scope": "xml", + "prefix": "maven-shade-plugin", + "body": [ + "", + "\torg.apache.maven.plugins", + "\tmaven-shade-plugin", + "\t${1:3.2.4}", + "\t", + "\t\t", + "\t\t\tpackage", + "\t\t\t", + "\t\t\t\tshade", + "\t\t\t", + "\t\t\t", + "\t\t\t\t", + "\t\t\t\t\t", + "\t\t\t\t\t\t${2:com.example.App}", + "\t\t\t\t\t", + "\t\t\t\t", + "\t\t\t", + "\t\t", + "\t", + "", + ] + } +} diff --git a/repository.code-snippets b/repository.code-snippets new file mode 100644 index 0000000..ead44fc --- /dev/null +++ b/repository.code-snippets @@ -0,0 +1,143 @@ +{ + "Repository": { + "scope": "java", + "prefix": "repository", + "body": [ + "package ${1:base package}.${2:context}.domain.model.${3:aggregateroot};", + "", + "import java.util.List;", + "", + "import xyz.zhouxy.plusone.domain.IRepository;", + "", + "public interface ${4:AggregateRoot}Repository extends IRepository<${4:AggregateRoot}, ${5:ID}> {", + "", + " List<${4:AggregateRoot}> findAll();", + "}", + ] + }, + "RepositoryImplTemplate": { + "scope": "java", + "prefix": "repoImplTemplate", + "body": [ + "@Repository", + "public class ${1:Entity}RepositoryImpl extends JdbcRepositorySupport<${1:Entity}, Long> implements ${1:Entity}Repository {", + "", + "\t// private final ${1:Entity}RoleRefDAO ${3:entity}RoleDAO;", + "", + "\tpublic ${1:Entity}RepositoryImpl(@Nonnull NamedParameterJdbcTemplate namedParameterJdbcTemplate) {", + "\t\tsuper(namedParameterJdbcTemplate);", + "\t\t// this.${3:entity}RoleDAO = new ${1:Entity}RoleRefDAO(namedParameterJdbcTemplate);", + "\t}", + "", + "\t/**", + "\t * @DefinedIn {@link JdbcRepositorySupport}", + "\t */", + "\t@Override", + "\tprotected final void doDelete(@Nonnull ${1:Entity} entity) {", + "\t\tint i = update(\"\"\"", + "\t\t\t\tUPDATE ${2:table_name} SET deleted = id, \"version\" = \"version\" + 1", + "\t\t\t\tWHERE id = :id AND deleted = 0 AND \"version\" = :version", + "\t\t\t\t\"\"\",", + "\t\t\t\tnew MapSqlParameterSource()", + "\t\t\t\t\t\t.addValue(\"id\", entity.getId().orElseThrow())", + "\t\t\t\t\t\t.addValue(\"version\", entity.getVersion()));", + "\t\tassertUpdateOneRow(i);", + "\t}", + "", + "\t/**", + "\t * @DefinedIn {@link JdbcRepositorySupport}", + "\t */", + "\t@Override", + "\tprotected final Optional<${1:Entity}> doFindById(@Nonnull Long id) {", + "\t\treturn queryForObject(\"\"\"", + "\t\t\t\tSELECT", + "\t\t\t\t\tid, ..., \"version\"", + "\t\t\t\tFROM ${2:table_name}", + "\t\t\t\tWHERE id = :id AND deleted = 0", + "\t\t\t\t\"\"\",", + "\t\t\t\t\"id\", id);", + "\t}", + "", + "\t/**", + "\t * @DefinedIn {@link IRepository}", + "\t */", + "\t@Override", + "\tpublic boolean exists(Long id) {", + "\t\treturn queryForBool(\"SELECT EXISTS (SELECT 1 FROM ${2:table_name} WHERE id = :id AND deleted = 0 LIMIT 1)\",", + "\t\t\t\t\"id\", id);", + "\t}", + "", + "\t/**", + "\t * @DefinedIn {@link JdbcRepositorySupport}", + "\t */", + "\t@Override", + "\tprotected final ${1:Entity} doInsert(@Nonnull ${1:Entity} entity) {", + "\t\tlong id = IdUtil.getSnowflakeNextId();", + "\t\tint i = update(\"\"\"", + "\t\t\t\tINSERT INTO ${2:table_name}", + "\t\t\t\t\t(id, ... created_by, create_time)", + "\t\t\t\tVALUES", + "\t\t\t\t\t(:id, ..., :createdBy, :createTime)", + "\t\t\t\t\"\"\",", + "\t\t\t\tgenerateParamSource(id, entity));", + "\t\tassertUpdateOneRow(i);", + "\t\t// this.${3:entity}RoleDAO.insert${1:Entity}RoleRefs(id, entity.getRoleIds());", + "\t\treturn find(id).orElseThrow();", + "\t}", + "", + "\t/**", + "\t * @DefinedIn {@link JdbcRepositorySupport}", + "\t */", + "\t@Override", + "\tprotected final ${1:Entity} doUpdate(@Nonnull ${1:Entity} entity) {", + "\t\tint i = update(\"\"\"", + "\t\t\t\tUPDATE ${2:table_name}", + "\t\t\t\tSET ...", + "\t\t\t\t\t\"updated_by\" = :updatedBy,", + "\t\t\t\t\t\"update_time\" = :updateTime,", + "\t\t\t\t\t\"version\" = \"version\" + 1", + "\t\t\t\tWHERE id = :id AND deleted = 0 AND \"version\" = :version", + "\t\t\t\t\"\"\",", + "\t\t\t\tgenerateParamSource(entity));", + "\t\tassertUpdateOneRow(i);", + "\t\t// this.${3:entity}RoleDAO.save${1:Entity}RoleRefs(entity);", + "\t\treturn find(entity.getId().orElseThrow()).orElseThrow();", + "\t}", + "", + "\t/**", + "\t * @DefinedIn {@link JdbcEntityDaoSupport}", + "\t */", + "\t@Override", + "\tprotected final ${1:Entity} mapRow(ResultSet rs) throws SQLException {", + "\t\tlong id = rs.getLong(\"id\");", + "", + "\t\treturn new ${1:Entity}(", + "\t\t\t\tid,", + "\t\t\t\t...", + "\t\t\t\trs.getLong(\"created_by\"),", + "\t\t\t\trs.getLong(\"updated_by\"),", + "\t\t\t\trs.getLong(\"version\"));", + "\t}", + "", + "\t/**", + "\t * @DefinedIn {@link JdbcRepositorySupport}", + "\t */", + "\t@Override", + "\tprotected final SqlParameterSource generateParamSource(Long id, @Nonnull ${1:Entity} entity) {", + "\t\tLocalDateTime now = LocalDateTime.now();", + "\t\t", + "\t\treturn new MapSqlParameterSource()", + "\t\t\t\t.addValue(\"id\", id)", + "\t\t\t\t...", + "\t\t\t\t.addValue(\"createdBy\", entity.getCreatedBy())", + "\t\t\t\t.addValue(\"createTime\", now)", + "\t\t\t\t.addValue(\"updatedBy\", entity.getUpdatedBy())", + "\t\t\t\t.addValue(\"updateTime\", now)", + "\t\t\t\t.addValue(\"version\", entity.getVersion());", + "\t}", + "", + "}", + "", + ] + } +} \ No newline at end of file diff --git a/spring-boot-dependencies.code-snippets b/spring-boot-dependencies.code-snippets new file mode 100644 index 0000000..96b6cfc --- /dev/null +++ b/spring-boot-dependencies.code-snippets @@ -0,0 +1,16 @@ +{ + "SpringBoot Dependencies": { + "prefix": "spring-boot-dependencies", + "body": [ + "", + "\torg.springframework.boot", + "\tspring-boot-dependencies", + "\t${spring-boot.version}", + "\tpom", + "\timport", + "", + ], + "description": "Import SpringBoot Dependencies", + "scope": "xml" + } +} \ No newline at end of file diff --git a/spring-cloud-alibaba-dependencies.code-snippets b/spring-cloud-alibaba-dependencies.code-snippets new file mode 100644 index 0000000..c94b6ad --- /dev/null +++ b/spring-cloud-alibaba-dependencies.code-snippets @@ -0,0 +1,27 @@ +{ + "Spring Cloud Alibaba Dependencies": { + "prefix": "spring-cloud-alibaba-dependencies", + "body": [ + "", + "\tcom.alibaba.cloud", + "\tspring-cloud-alibaba-dependencies", + "\t${spring-cloud-alibaba.version}", + "\tpom", + "\timport", + "", + ], + "description": "Import Spring Cloud Alibaba Dependencies", + "scope": "xml" + }, + "Spring Cloud Alibaba Nacos Discovery": { + "prefix": "spring-cloud-starter-alibaba-nacos-discovery", + "body": [ + "", + "\tcom.alibaba.cloud", + "\tspring-cloud-starter-alibaba-nacos-discovery", + "", + ], + "description": "Import Spring Cloud Alibaba Nacos Discovery", + "scope": "xml" + } +} \ No newline at end of file diff --git a/spring-cloud-dependencies.code-snippets b/spring-cloud-dependencies.code-snippets new file mode 100644 index 0000000..462827a --- /dev/null +++ b/spring-cloud-dependencies.code-snippets @@ -0,0 +1,16 @@ +{ + "Spring Cloud Alibaba Dependencies": { + "prefix": "spring-cloud-dependencies", + "body": [ + "", + "\torg.springframework.cloud", + "\tspring-cloud-dependencies", + "\t${spring-cloud.version}", + "\tpom", + "\timport", + "", + ], + "description": "Import Spring Cloud Dependencies", + "scope": "xml" + } +} \ No newline at end of file diff --git a/spring-cloud-starter-alibaba-nacos-discovery.code-snippets b/spring-cloud-starter-alibaba-nacos-discovery.code-snippets new file mode 100644 index 0000000..08b958d --- /dev/null +++ b/spring-cloud-starter-alibaba-nacos-discovery.code-snippets @@ -0,0 +1,13 @@ +{ + "Spring Cloud Alibaba Dependencies": { + "prefix": "spring-cloud-starter-alibaba-nacos-discovery", + "body": [ + "", + "\tcom.alibaba.cloud", + "\tspring-cloud-starter-alibaba-nacos-discovery", + "", + ], + "description": "Import Spring Cloud Alibaba Nacos Discovery", + "scope": "xml" + } +} \ No newline at end of file diff --git a/spring-context.code-snippets b/spring-context.code-snippets new file mode 100644 index 0000000..4f9ce0d --- /dev/null +++ b/spring-context.code-snippets @@ -0,0 +1,26 @@ +{ + "Spring XML Context": { + "prefix": "spring-xml-context", + "scope": "xml", + "body": [ + "", + "", + "", + "\t$1", + "", + ], + "description": "Spring xml context template" + } +} \ No newline at end of file