diff --git a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/config/GlobalConfig.java b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/config/GlobalConfig.java index 6bc7aeac..3f31ef8f 100644 --- a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/config/GlobalConfig.java +++ b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/config/GlobalConfig.java @@ -1065,6 +1065,20 @@ public class GlobalConfig { getServiceImplConfig().setSupperClass(serviceImplSupperClass); } + /** + * @see ServiceImplConfig#isCacheExample() + */ + public boolean isServiceImplCacheExample() { + return getServiceImplConfig().isCacheExample(); + } + + /** + * @see ServiceImplConfig#setCacheExample(boolean) + */ + public void setServiceImplCacheExample(boolean cacheExample) { + getServiceImplConfig().setCacheExample(cacheExample); + } + /** * @see ControllerConfig#isOverwriteEnable() */ diff --git a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/config/ServiceImplConfig.java b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/config/ServiceImplConfig.java index 0c0d5523..27d440b6 100644 --- a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/config/ServiceImplConfig.java +++ b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/config/ServiceImplConfig.java @@ -15,6 +15,7 @@ */ package com.mybatisflex.codegen.config; +import com.mybatisflex.spring.service.impl.CacheableServiceImpl; import com.mybatisflex.spring.service.impl.ServiceImpl; /** @@ -46,6 +47,11 @@ public class ServiceImplConfig { */ private boolean overwriteEnable; + /** + * 是否生成缓存样例代码。 + */ + private boolean cacheExample; + public String buildSuperClassImport() { return supperClass.getName(); } @@ -114,4 +120,19 @@ public class ServiceImplConfig { return this; } + /** + * 是否生成缓存例子。 + */ + public boolean isCacheExample() { + return CacheableServiceImpl.class.equals(supperClass) && cacheExample; + } + + /** + * 设置生成缓存例子。 + */ + public ServiceImplConfig setCacheExample(boolean cacheExample) { + this.cacheExample = cacheExample; + return this; + } + } \ No newline at end of file diff --git a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/entity/Table.java b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/entity/Table.java index 0a229ca0..520a10e0 100644 --- a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/entity/Table.java +++ b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/entity/Table.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). - *
- * 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 - *
- * http://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. +/* + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *
+ * 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 + *
+ * http://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.
*/
package com.mybatisflex.codegen.entity;
@@ -48,6 +48,15 @@ public class Table {
this.comment = comment;
}
+ public String getPrimaryKey() {
+ // 这里默认表中一定会有字段,就不做空判断了
+ return columns.stream()
+ .filter(Column::isPrimaryKey)
+ .findFirst()
+ .map(Column::getProperty)
+ .orElse(null);
+ }
+
public Set