-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9da6eef
commit 7840566
Showing
11 changed files
with
230 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
* fix: 修复Aop增强Mapper层导致的转换错误. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...-plus/src/test/java/com/baomidou/mybatisplus/test/h2/issues/repositoryscan/AppConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
|
||
package com.baomidou.mybatisplus.test.h2.issues.repositoryscan; | ||
|
||
import com.baomidou.mybatisplus.core.MybatisConfiguration; | ||
import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean; | ||
import org.apache.ibatis.session.SqlSessionFactory; | ||
import org.h2.Driver; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.jdbc.datasource.SimpleDriverDataSource; | ||
|
||
import javax.sql.DataSource; | ||
|
||
/** | ||
* @author nieqiurong | ||
*/ | ||
@Configuration | ||
@ComponentScan("com.baomidou.mybatisplus.test.h2.issues.repositoryscan") | ||
public class AppConfig { | ||
|
||
@Bean | ||
public DataSource dataSource() { | ||
SimpleDriverDataSource dataSource = new SimpleDriverDataSource(); | ||
dataSource.setDriver(new Driver()); | ||
dataSource.setUrl("jdbc:h2:mem:testa;MODE=mysql;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE"); | ||
dataSource.setUsername("sa"); | ||
dataSource.setPassword(""); | ||
return dataSource; | ||
} | ||
|
||
@Bean | ||
public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception { | ||
MybatisSqlSessionFactoryBean mybatisSqlSessionFactoryBean = new MybatisSqlSessionFactoryBean(); | ||
mybatisSqlSessionFactoryBean.setDataSource(dataSource); | ||
mybatisSqlSessionFactoryBean.setConfiguration(new MybatisConfiguration()); | ||
return mybatisSqlSessionFactoryBean.getObject(); | ||
} | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
.../java/com/baomidou/mybatisplus/test/h2/issues/repositoryscan/AppConfigWithMapperScan.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
|
||
package com.baomidou.mybatisplus.test.h2.issues.repositoryscan; | ||
|
||
import com.baomidou.mybatisplus.core.MybatisConfiguration; | ||
import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean; | ||
import org.apache.ibatis.session.SqlSessionFactory; | ||
import org.h2.Driver; | ||
import org.mybatis.spring.annotation.MapperScan; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.jdbc.datasource.SimpleDriverDataSource; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import javax.sql.DataSource; | ||
|
||
/** | ||
* @author nieqiurong | ||
*/ | ||
@Configuration | ||
@ComponentScan("com.baomidou.mybatisplus.test.h2.issues.repositoryscan") | ||
@MapperScan(value = "com.baomidou.mybatisplus.test.h2.issues.repositoryscan.mapper", annotationClass = Repository.class) | ||
public class AppConfigWithMapperScan { | ||
|
||
@Bean | ||
public DataSource dataSource() { | ||
SimpleDriverDataSource dataSource = new SimpleDriverDataSource(); | ||
dataSource.setDriver(new Driver()); | ||
dataSource.setUrl("jdbc:h2:mem:testa;MODE=mysql;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE"); | ||
dataSource.setUsername("sa"); | ||
dataSource.setPassword(""); | ||
return dataSource; | ||
} | ||
|
||
@Bean | ||
public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception { | ||
MybatisSqlSessionFactoryBean mybatisSqlSessionFactoryBean = new MybatisSqlSessionFactoryBean(); | ||
mybatisSqlSessionFactoryBean.setDataSource(dataSource); | ||
mybatisSqlSessionFactoryBean.setConfiguration(new MybatisConfiguration()); | ||
return mybatisSqlSessionFactoryBean.getObject(); | ||
} | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
...ava/com/baomidou/mybatisplus/test/h2/issues/repositoryscan/RepositoryDefaultScanTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.baomidou.mybatisplus.test.h2.issues.repositoryscan; | ||
|
||
import com.baomidou.mybatisplus.test.h2.issues.repositoryscan.entity.Demo; | ||
import com.baomidou.mybatisplus.test.h2.issues.repositoryscan.service.IDemoRepositoryService; | ||
import org.apache.ibatis.jdbc.SqlRunner; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.context.junit.jupiter.SpringExtension; | ||
|
||
import javax.sql.DataSource; | ||
import java.sql.SQLException; | ||
import java.util.List; | ||
|
||
/** | ||
* @author nieqiurong | ||
*/ | ||
@ExtendWith(SpringExtension.class) | ||
@ContextConfiguration(classes = {AppConfig.class}) | ||
public class RepositoryDefaultScanTest { | ||
|
||
@Autowired | ||
private IDemoRepositoryService demoService; | ||
|
||
@Autowired | ||
private DataSource dataSource; | ||
|
||
@Test | ||
void test() throws SQLException { | ||
new SqlRunner(dataSource.getConnection()).run( | ||
""" | ||
CREATE TABLE IF NOT EXISTS demo ( | ||
id BIGINT NOT NULL AUTO_INCREMENT, | ||
name VARCHAR(30) NULL DEFAULT NULL , | ||
PRIMARY KEY (id) | ||
); | ||
""" | ||
); | ||
demoService.save(new Demo()); | ||
demoService.saveBatch(List.of(new Demo())); | ||
} | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
...java/com/baomidou/mybatisplus/test/h2/issues/repositoryscan/RepositoryMapperScanTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.baomidou.mybatisplus.test.h2.issues.repositoryscan; | ||
|
||
import com.baomidou.mybatisplus.test.h2.issues.repositoryscan.entity.Demo; | ||
import com.baomidou.mybatisplus.test.h2.issues.repositoryscan.service.IDemoRepositoryService; | ||
import org.apache.ibatis.jdbc.SqlRunner; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.context.junit.jupiter.SpringExtension; | ||
|
||
import javax.sql.DataSource; | ||
import java.sql.SQLException; | ||
import java.util.List; | ||
|
||
/** | ||
* @author nieqiurong | ||
*/ | ||
@ExtendWith(SpringExtension.class) | ||
@ContextConfiguration(classes = {AppConfigWithMapperScan.class}) | ||
public class RepositoryMapperScanTest { | ||
|
||
@Autowired | ||
private IDemoRepositoryService demoService; | ||
|
||
@Autowired | ||
private DataSource dataSource; | ||
|
||
@Test | ||
void test() throws SQLException { | ||
new SqlRunner(dataSource.getConnection()).run( | ||
""" | ||
CREATE TABLE IF NOT EXISTS demo ( | ||
id BIGINT NOT NULL AUTO_INCREMENT, | ||
name VARCHAR(30) NULL DEFAULT NULL , | ||
PRIMARY KEY (id) | ||
); | ||
""" | ||
); | ||
demoService.save(new Demo()); | ||
demoService.saveBatch(List.of(new Demo())); | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
...lus/src/test/java/com/baomidou/mybatisplus/test/h2/issues/repositoryscan/entity/Demo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.baomidou.mybatisplus.test.h2.issues.repositoryscan.entity; | ||
|
||
import lombok.Data; | ||
|
||
/** | ||
* @author nieqiurong | ||
*/ | ||
@Data | ||
public class Demo { | ||
|
||
private Long id; | ||
|
||
private String name; | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
...a/com/baomidou/mybatisplus/test/h2/issues/repositoryscan/mapper/DemoRepositoryMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.baomidou.mybatisplus.test.h2.issues.repositoryscan.mapper; | ||
|
||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; | ||
import com.baomidou.mybatisplus.test.h2.issues.repositoryscan.entity.Demo; | ||
import org.springframework.stereotype.Repository; | ||
|
||
/** | ||
* @author nieqiurong | ||
*/ | ||
@Repository | ||
public interface DemoRepositoryMapper extends BaseMapper<Demo> { | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
...om/baomidou/mybatisplus/test/h2/issues/repositoryscan/service/IDemoRepositoryService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.baomidou.mybatisplus.test.h2.issues.repositoryscan.service; | ||
|
||
import com.baomidou.mybatisplus.extension.service.IService; | ||
import com.baomidou.mybatisplus.test.h2.issues.repositoryscan.entity.Demo; | ||
|
||
/** | ||
* @author nieqiurong | ||
*/ | ||
public interface IDemoRepositoryService extends IService<Demo> { | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
...dou/mybatisplus/test/h2/issues/repositoryscan/service/impl/DemoRepositoryServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.baomidou.mybatisplus.test.h2.issues.repositoryscan.service.impl; | ||
|
||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | ||
import com.baomidou.mybatisplus.test.h2.issues.repositoryscan.entity.Demo; | ||
import com.baomidou.mybatisplus.test.h2.issues.repositoryscan.mapper.DemoRepositoryMapper; | ||
import com.baomidou.mybatisplus.test.h2.issues.repositoryscan.service.IDemoRepositoryService; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* @author nieqiurong | ||
*/ | ||
@Service | ||
public class DemoRepositoryServiceImpl extends ServiceImpl<DemoRepositoryMapper, Demo> implements IDemoRepositoryService { | ||
|
||
} |