mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 00:58:24 +08:00
fixed: 修复添加 mapper.xml 会出现 NPE 的问题。 close #I6X59V
This commit is contained in:
parent
114d2ec963
commit
a8023de0a8
@ -585,6 +585,12 @@ public class FlexSqlSessionFactoryBean extends SqlSessionFactoryBean
|
|||||||
this.transactionFactory == null ? new SpringManagedTransactionFactory() : this.transactionFactory,
|
this.transactionFactory == null ? new SpringManagedTransactionFactory() : this.transactionFactory,
|
||||||
dataSource instanceof FlexDataSource ? dataSource : new FlexDataSource(FlexConsts.NAME, dataSource)));
|
dataSource instanceof FlexDataSource ? dataSource : new FlexDataSource(FlexConsts.NAME, dataSource)));
|
||||||
|
|
||||||
|
|
||||||
|
// 需先构建 sqlSessionFactory,再去初始化 mapperLocations
|
||||||
|
// 因为 xmlMapperBuilder.parse() 用到 FlexGlobalConfig, FlexGlobalConfig 的初始化是在 sqlSessionFactory 的构建方法里进行的
|
||||||
|
// fixed gitee https://gitee.com/mybatis-flex/mybatis-flex/issues/I6X59V
|
||||||
|
SqlSessionFactory sqlSessionFactory = this.sqlSessionFactoryBuilder.build(targetConfiguration);
|
||||||
|
|
||||||
if (this.mapperLocations != null) {
|
if (this.mapperLocations != null) {
|
||||||
if (this.mapperLocations.length == 0) {
|
if (this.mapperLocations.length == 0) {
|
||||||
LOGGER.warn(() -> "Property 'mapperLocations' was specified but matching resources are not found.");
|
LOGGER.warn(() -> "Property 'mapperLocations' was specified but matching resources are not found.");
|
||||||
@ -609,7 +615,8 @@ public class FlexSqlSessionFactoryBean extends SqlSessionFactoryBean
|
|||||||
LOGGER.debug(() -> "Property 'mapperLocations' was not specified.");
|
LOGGER.debug(() -> "Property 'mapperLocations' was not specified.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.sqlSessionFactoryBuilder.build(targetConfiguration);
|
|
||||||
|
return sqlSessionFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -20,6 +20,7 @@ import com.mybatisflex.core.query.QueryWrapper;
|
|||||||
import com.mybatisflex.core.row.Db;
|
import com.mybatisflex.core.row.Db;
|
||||||
import com.mybatisflex.core.row.Row;
|
import com.mybatisflex.core.row.Row;
|
||||||
import com.mybatisflex.test.mapper.AccountMapper;
|
import com.mybatisflex.test.mapper.AccountMapper;
|
||||||
|
import com.mybatisflex.test.mapper.MyAccountMapper;
|
||||||
import com.mybatisflex.test.model.Account;
|
import com.mybatisflex.test.model.Account;
|
||||||
import com.mybatisflex.test.service.AccountService;
|
import com.mybatisflex.test.service.AccountService;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
@ -35,6 +36,10 @@ public class AccountController {
|
|||||||
AccountMapper accountMapper;
|
AccountMapper accountMapper;
|
||||||
|
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
MyAccountMapper myAccountMapper;
|
||||||
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
AccountService accountService;
|
AccountService accountService;
|
||||||
|
|
||||||
@ -46,6 +51,13 @@ public class AccountController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@GetMapping("/account/select/{name}")
|
||||||
|
Account selectName(@PathVariable("name") String name){
|
||||||
|
return myAccountMapper.selectByName(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@GetMapping("/account/{id}")
|
@GetMapping("/account/{id}")
|
||||||
@Transactional
|
@Transactional
|
||||||
public Account selectOne(@PathVariable("id") Long id) {
|
public Account selectOne(@PathVariable("id") Long id) {
|
||||||
|
|||||||
@ -0,0 +1,10 @@
|
|||||||
|
package com.mybatisflex.test.mapper;
|
||||||
|
|
||||||
|
import com.mybatisflex.test.model.Account;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
public interface MyAccountMapper extends AccountMapper {
|
||||||
|
|
||||||
|
|
||||||
|
Account selectByName(@Param("name") String name);
|
||||||
|
}
|
||||||
@ -11,6 +11,9 @@ spring:
|
|||||||
init:
|
init:
|
||||||
schema-locations: classpath:schema.sql
|
schema-locations: classpath:schema.sql
|
||||||
data-locations: classpath:data.sql
|
data-locations: classpath:data.sql
|
||||||
|
mybatis-flex:
|
||||||
|
mapper-locations:
|
||||||
|
- classpath*:/mapper/*.xml
|
||||||
#mybatis-flex:
|
#mybatis-flex:
|
||||||
# datasource:
|
# datasource:
|
||||||
# ds1:
|
# ds1:
|
||||||
|
|||||||
@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||||
|
<mapper namespace="com.mybatisflex.test.mapper.MyAccountMapper">
|
||||||
|
|
||||||
|
<!-- selectByName -->
|
||||||
|
<select id="selectByName" resultType="com.mybatisflex.test.model.Account">
|
||||||
|
select * from `tb_account` where `user_name` = #{name}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
</mapper>
|
||||||
Loading…
x
Reference in New Issue
Block a user