Skip to content

Commit

Permalink
升级 1.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
青苗 committed Aug 16, 2016
1 parent 9842592 commit 57dddc0
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 52 deletions.
2 changes: 1 addition & 1 deletion mybatis-plus/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus</artifactId>
<version>1.3.11</version>
<version>1.4.0</version>
<packaging>jar</packaging>

<name>mybatis-plus</name>
Expand Down
2 changes: 1 addition & 1 deletion mybatis-plus/readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

# Mbatis-Plus 使用文档
# Mybatis-Plus 使用文档

> 更多文档查看 /mybatis-plus/src/test/resources/wiki
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,32 +118,26 @@ public int selectCount(T entity) {
}

public List<T> selectList(T entity, String sqlSelect, String sqlSegment, String orderByField) {
StringBuffer segment = new StringBuffer();
if (null != sqlSegment) {
segment.append(sqlSegment);
}
if (null != orderByField) {
segment.append(" ORDER BY ").append(orderByField);
}
return baseMapper.selectList(new EntityWrapper<T>(entity, sqlSelect, segment.toString()));
return baseMapper.selectList(new EntityWrapper<T>(entity, sqlSelect, this.convertSqlSegmet(sqlSegment, orderByField, true)));
}

public Page<T> selectPage(Page<T> page, String sqlSelect, T entity, String sqlSegment) {
page.setRecords(baseMapper.selectPage(page, new EntityWrapper<T>(entity, sqlSelect, this.convertSqlSegmet(page, sqlSegment))));
EntityWrapper<T> ew = new EntityWrapper<T>(entity, sqlSelect, this.convertSqlSegmet(page.getOrderByField(), sqlSegment, page.isAsc()));
page.setRecords(baseMapper.selectPage(page, ew));
return page;
}

/**
* 转换 SQL 片段 + 排序
*/
protected String convertSqlSegmet(Page<T> page, String sqlSegment) {
protected String convertSqlSegmet(String sqlSegment, String orderByField, boolean isAsc) {
StringBuffer segment = new StringBuffer();
if (null != sqlSegment) {
segment.append(sqlSegment);
}
if (null != page.getOrderByField()) {
segment.append(" ORDER BY ").append(page.getOrderByField());
if (!page.isAsc()) {
if (null != orderByField) {
segment.append(" ORDER BY ").append(orderByField);
if (!isAsc) {
segment.append(" DESC");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void setEntity(T entity) {
}

public String getSqlSelect() {
if (sqlSelect == null) {
if (sqlSelect == null || "".equals(sqlSelect)) {
return null;
}
return stripSqlInjection(sqlSelect);
Expand All @@ -81,7 +81,7 @@ public void setSqlSelect(String sqlSelect) {
}

public String getSqlSegment() {
if (null == sqlSegment) {
if (null == sqlSegment || "".equals(sqlSegment)) {
return null;
}
StringBuffer andOr = new StringBuffer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@
* @author hubin
* @Date 2016-07-07
*/
@Intercepts({
@Signature(type = Executor.class, method = "query", args = { MappedStatement.class, Object.class,
RowBounds.class, ResultHandler.class }),
@Intercepts({@Signature(type = Executor.class, method = "query", args = { MappedStatement.class, Object.class, RowBounds.class, ResultHandler.class }),
@Signature(type = Executor.class, method = "update", args = { MappedStatement.class, Object.class }) })
public class PerformanceInterceptor implements Interceptor {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,14 @@ public static void main( String[] args ) {
for ( int i = 0 ; i < rowList.size() ; i++ ) {
print(rowList.get(i));
}

/*
* 用户列表
*/
paginList = userMapper.selectList(new EntityWrapper<User>(null, null, null));
for ( int i = 0 ; i < rowList.size() ; i++ ) {
print(rowList.get(i));
}

/**
* 自定义方法,删除测试数据
Expand Down
5 changes: 4 additions & 1 deletion mybatis-plus/src/test/resources/mysql-config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@
<plugin interceptor="com.baomidou.mybatisplus.plugins.PerformanceInterceptor">
<property name="maxTime" value="100" />
</plugin>

<!-- SQL 执行分析拦截器 stopProceed 发现全表执行 delete update 是否停止运行 -->
<plugin interceptor="com.baomidou.mybatisplus.plugins.SqlExplainInterceptor">
<property name="stopProceed" value="false" />
</plugin>
</plugins>

<!-- 环境配置 -->
Expand Down
4 changes: 4 additions & 0 deletions mybatis-plus/src/test/resources/wiki/plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,9 @@
<plugin interceptor="com.baomidou.mybatisplus.plugins.PerformanceInterceptor">
<property name="maxTime" value="100" />
</plugin>
<!-- SQL 执行分析拦截器 stopProceed 发现全表执行 delete update 是否停止运行 -->
<plugin interceptor="com.baomidou.mybatisplus.plugins.SqlExplainInterceptor">
<property name="stopProceed" value="false" />
</plugin>
</plugins>
```
36 changes: 5 additions & 31 deletions mybatis-plus/src/test/resources/wiki/spring-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
-->
</typeAliases>
<!-- 插件配置, spring 中配置,此处就可以不用配置。 -->
<!--
<!--
<plugins>
| 分页插件配置
| 插件提供二种方言选择:1、默认方言 2、自定义方言实现类,两者均未配置则抛出异常!
Expand All @@ -100,40 +100,14 @@
<plugin interceptor="com.baomidou.mybatisplus.plugins.PerformanceInterceptor">
<property name="maxTime" value="100" />
</plugin>
<!-- SQL 执行分析拦截器 stopProceed 发现全表执行 delete update 是否停止运行 -->
<plugin interceptor="com.baomidou.mybatisplus.plugins.SqlExplainInterceptor">
<property name="stopProceed" value="false" />
</plugin>
</plugins>
| -->
</configuration>
```



# spring 根据不同环境加载不同配置支持

1、spring 根据不同配置运行模式,加载对应配置内容。
2、运行模式参数 key 配置 configEnv 默认 sysRunmode
3、online 线上 , dev 开发 , test 测试
4、首先环境变量中获取,变量名:sysRunmode 变量值:dev
5、如果不存在 JVM -D选项 参数中获取,例如:-DsysRunmode=dev

>例如:设置不同环境的数据库密码配置:
```
jdbc.password_dev_mode=1230600
jdbc.password_test_mode=2001006
jdbc.password_online_mode=#!Esd30210
```

>spring 配置:
```
<bean id="placeholder" class="com.baomidou.mybatisplus.spring.MutilPropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:jdbc.properties</value>
<value>classpath*:*-placeholder.properties</value>
</list>
</property>
</bean>
```


0 comments on commit 57dddc0

Please sign in to comment.