Skip to content

Commit

Permalink
update for IC edition
Browse files Browse the repository at this point in the history
  • Loading branch information
chuntungho committed Mar 3, 2021
1 parent 2fa27af commit 02d4736
Show file tree
Hide file tree
Showing 29 changed files with 34 additions and 2,523 deletions.
52 changes: 5 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,49 +1,7 @@
基于<https://gitee.com/wuzhizhan/free-mybatis-plugin>升级,支持2020.2.4版本。
# free-mybatis-plugin

[中文](README.md) |
[ENGLISH](README_EN.md)
## Changes:

## Description
A idea plugin for mybatis .
free-mybatis-plugin 是一款增强idea对mybatis支持的插件,主要功能如下:
- 生成mapper xml文件
- 快速从代码跳转到mapper及从mapper返回代码
- mybatis自动补全及语法错误提示

## 使用方法
free-mybatis-plugin是一个提高mybatis编码的插件。实现了dao代码跳转到mapper,mapper跳转回dao,mapper文件、statement查询自动生成功能。
### 灵活使用alt+enter和ctrl+B实现提示和跳转
- 生成mapper文件
- alter+enter弹出
![](https://images.gitee.com/uploads/images/2020/0121/151849_26a01dec_131460.png)
![](https://images.gitee.com/uploads/images/2020/0121/151849_59d74c18_131460.jpeg)
- 生成statement语句
- alter+enter弹出
![](https://images.gitee.com/uploads/images/2020/0121/151849_594bfd4d_131460.jpeg)
- dao跳转到mapper(也可以ctrl+B跳入)
- ![](https://images.gitee.com/uploads/images/2020/0121/151850_9821ea07_131460.jpeg)
- mapper跳转回dao(也可以ctrl+b跳入)
- ![](https://images.gitee.com/uploads/images/2020/0121/151850_6ff9859f_131460.jpeg)
<br><br><br>
## mybatis generator gui使用方法
- 配置数据库<br>
![](https://images.gitee.com/uploads/images/2020/0121/151850_7decd93e_131460.png)
![](https://images.gitee.com/uploads/images/2020/0121/151849_3b35abd0_131460.png)
- 在需要生成代码的表上右键,选择mybatis generator,打开预览界面。 <br>
![](https://images.gitee.com/uploads/images/2020/0121/151849_6552ab20_131460.png)
- 配置生成参数<br>
![](https://images.gitee.com/uploads/images/2020/0121/151849_7fd4ada5_131460.png)
- 注意:当数据库用mysql8,在URL上定义时区,推荐使用'?serverTimezone=GMT',配置中勾选上mysql8选项。<br>

## TODO
- 根据数据库字段生产bean
- 快捷生成CURD操作

## 参考
- better-mybatis-generator https://github.com/kmaster/better-mybatis-generator
- mybatis-generator-gui https://github.com/zouzg/mybatis-generator-gui
- MyBatisCodeHelper-Pro https://github.com/gejun123456/MyBatisCodeHelper-Pro
## 我的微信公众号 - it新技术
更多内容,欢迎关注公众号 【it新技术】
- ![](https://images.gitee.com/uploads/images/2020/0121/151850_6e6ac5da_131460.jpeg)
![](https://images.gitee.com/uploads/images/2020/0121/151850_003d690f_131460.jpeg)
- Compatible with Intellij IC edition.
- Not to warn static method or the method with mybatis provider annotation.
- Remove MyBatis Generator.
44 changes: 0 additions & 44 deletions README_EN.md

This file was deleted.

24 changes: 4 additions & 20 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ plugins {
}

group = 'cn.wuzhizhan.idea.mybatis'
version = '2020.12.09'
version = '2021.03.03'

apply plugin: 'java'
sourceCompatibility = 1.8
Expand All @@ -21,7 +21,6 @@ repositories {
}

dependencies {
compile fileTree(dir: 'lib', includes: ['*jar'])
compile group: 'com.softwareloop', name: 'mybatis-generator-lombok-plugin', version: '1.0'
compile group: 'uk.com.robust-it', name: 'cloning', version: '1.9.2'
testCompile group: 'junit', name: 'junit', version: '4.12'
Expand All @@ -30,31 +29,16 @@ buildPlugin {
buildSearchableOptions.enabled = false
}
intellij {
version "2020.2.4"
type "IU"
version "IC-2018.1"
pluginName = 'free-mybatis-plugin'
plugins = ['coverage', 'Spring', 'DatabaseTools', 'java']
intellij.updateSinceUntilBuild false
}
patchPluginXml {
changeNotes """
<h4>2020.12.09</h4>
<ul>
<li>修改过期的方法</li>
<li>修正笔误</li>
<li>Compatible with IC edition.</li>
<li>Not to warn static method or the method with mybatis provider annotation.</li>
</ul>
<h4>2020.12.08</h4>
<ul>
<li>修复新版API不兼容问题</li>
</ul>
<h4>2019.12.18</h4>
<ul>
<li>feature:移除jdbc依赖,不用再次输入密码</li>
<li>bugfix:修复返回类型检测错误</li>
<li>bugfix:mybatis generator修复oracle错误</li>
<li>bugfix:mybatis generator修复postgres数据库</li>
<li>bugfix:mybatis generator修复xml mapper重复创建</li>
</ul>
"""
}

Expand Down
2 changes: 1 addition & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ fi
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`

JAVACMD=`cygpath --unix "$JAVACMD"`

# We build the pattern for arguments to be converted via cygpath
Expand Down
21 changes: 3 additions & 18 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
if "%ERRORLEVEL%" == "0" goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Expand All @@ -54,7 +54,7 @@ goto fail
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto init
if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
Expand All @@ -64,29 +64,14 @@ echo location of your Java installation.

goto fail

:init
@rem Get command-line arguments, handling Windows variants

if not "%OS%" == "Windows_NT" goto win9xME_args

:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2

:win9xME_args_slurp
if "x%~1" == "x" goto execute

set CMD_LINE_ARGS=%*

:execute
@rem Setup the command line

set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar


@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*

:end
@rem End local scope for the variables with windows NT shell
Expand Down
Binary file removed lib/gene-plugin-1.0-SNAPSHOT.jar
Binary file not shown.
Binary file removed lib/mybatis-generator-core-1.4.0.jar
Binary file not shown.

This file was deleted.

44 changes: 5 additions & 39 deletions src/main/java/com/wuzhizhan/mybatis/alias/BeanAliasResolver.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
package com.wuzhizhan.mybatis.alias;

import com.google.common.collect.Sets;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
import com.intellij.spring.CommonSpringModel;
import com.intellij.spring.SpringManager;
import com.intellij.spring.model.SpringBeanPointer;
import com.intellij.spring.model.utils.SpringPropertyUtils;
import com.intellij.spring.model.xml.beans.SpringPropertyDefinition;
import com.wuzhizhan.mybatis.util.JavaUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Collection;
import java.util.Optional;
import java.util.Set;

/**
Expand All @@ -27,48 +18,23 @@ public class BeanAliasResolver extends PackageAliasResolver {
private static final String MAPPER_ALIAS_PACKAGE_CLASS = "org.mybatis.spring.SqlSessionFactoryBean";
private static final String MAPPER_ALIAS_PROPERTY = "typeAliasesPackage";
private ModuleManager moduleManager;
private SpringManager springManager;

public BeanAliasResolver(Project project) {
super(project);
this.moduleManager = ModuleManager.getInstance(project);
this.springManager = SpringManager.getInstance(project);
}

@NotNull
@Override
public Collection<String> getPackages(@Nullable PsiElement element) {
Set<String> res = Sets.newHashSet();
for (Module module : moduleManager.getModules()) {
for (CommonSpringModel springModel : springManager.getCombinedModel(module).getRelatedModels()) {
addPackages(res, springModel);
}
}
// for (Module module : moduleManager.getModules()) {
// for (CommonSpringModel springModel : springManager.getCombinedModel(module).getRelatedModels()) {
// addPackages(res, springModel);
// }
// }
return res;
}

private void addPackages(Set<String> res, CommonSpringModel springModel) {
Optional sqlSessionFactoryClazzOpt = JavaUtils.findClazz(project, MAPPER_ALIAS_PACKAGE_CLASS);
if (sqlSessionFactoryClazzOpt.isPresent()) {
Collection domBeans = springModel.getAllCommonBeans();
PsiClass sqlSessionFactoryClazz = (PsiClass) sqlSessionFactoryClazzOpt.get();

for (Object domBean : domBeans) {
SpringBeanPointer pointer = (SpringBeanPointer) domBean;
PsiClass beanClass = pointer.getBeanClass();
if (beanClass != null && beanClass.equals(sqlSessionFactoryClazz)) {
SpringPropertyDefinition basePackages = SpringPropertyUtils.findPropertyByName(pointer.getSpringBean(), MAPPER_ALIAS_PROPERTY);
if (basePackages != null) {
final String value = basePackages.getValueElement().getStringValue();
if (value != null) {
res.add(value);
}
}
}
}

}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ public class Annotation implements Cloneable {

public static final Annotation RESOURCE = new Annotation("@Resource", "javax.annotation.Resource");

public static final Set<Annotation> STATEMENT_SYMMETRIES = ImmutableSet.of(SELECT, UPDATE, INSERT, DELETE);
public static final Annotation SelectProvider = new Annotation("@SelectProvider", "org.apache.ibatis.annotations.SelectProvider");
public static final Annotation InsertProvider = new Annotation("@InsertProvider", "org.apache.ibatis.annotations.InsertProvider");
public static final Annotation DeleteProvider = new Annotation("@DeleteProvider", "org.apache.ibatis.annotations.DeleteProvider");
public static final Annotation UpdateProvider = new Annotation("@UpdateProvider", "org.apache.ibatis.annotations.UpdateProvider");

public static final Set<Annotation> STATEMENT_SYMMETRIES = ImmutableSet.of(SELECT, UPDATE, INSERT, DELETE,
SelectProvider, InsertProvider, DeleteProvider, UpdateProvider);

private final String label;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public MapperDefinitionSearch() {
}

@Override
public void processQuery(@NotNull PsiElement queryParameters, @NotNull Processor<? super XmlElement> consumer) {
if (!(queryParameters instanceof PsiTypeParameterListOwner)) return;
public void processQuery(@NotNull PsiElement queryParameters, @NotNull Processor<XmlElement> consumer) {
if (!(queryParameters instanceof PsiTypeParameterListOwner)) return;

Processor<DomElement> processor = domElement -> consumer.process(domElement.getXmlElement());

Expand Down
Loading

0 comments on commit 02d4736

Please sign in to comment.