-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
12 changed files
with
283 additions
and
37 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,13 +1,11 @@ | ||
package dao; | ||
|
||
import com.baomidou.mybatisplus.mapper.BaseMapper; | ||
import entity.User; | ||
import org.apache.ibatis.annotations.Param; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Created by xuweijie on 2017/3/7. | ||
*/ | ||
public interface ShiroUserDao { | ||
public User queryByName(String username); | ||
public interface ShiroUserDao extends BaseMapper<User> { | ||
User queryByName(String username); | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package util.datasource; | ||
|
||
/** | ||
* Created by xuweijie on 17-3-26. | ||
*/ | ||
public enum DBTypeEnum { | ||
one("dataSourceOne"),tow("dataSourceTwo"); | ||
private String value; | ||
|
||
DBTypeEnum(String value) { | ||
this.value = value; | ||
} | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
} |
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,32 @@ | ||
package util.datasource; | ||
|
||
import com.baomidou.mybatisplus.enums.DBType; | ||
|
||
/** | ||
* Created by xuweijie on 17-3-26. | ||
*/ | ||
public class DbContextHolder { | ||
|
||
private static final ThreadLocal contextHolder = new ThreadLocal<>(); | ||
|
||
/** | ||
* 设置数据源 | ||
*/ | ||
public static void setDbType(DBTypeEnum dbTypeEnum) { | ||
contextHolder.set(dbTypeEnum.getValue()); | ||
} | ||
|
||
/** | ||
* 取得当前数据源 | ||
*/ | ||
public static String getDbType() { | ||
return (String) contextHolder.get(); | ||
} | ||
|
||
/** | ||
* 清除上下文数据 | ||
*/ | ||
public static void clearDbType() { | ||
contextHolder.remove(); | ||
} | ||
} |
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,18 @@ | ||
package util.datasource; | ||
|
||
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource; | ||
|
||
/** | ||
* Created by xuweijie on 17-3-26. | ||
*/ | ||
public class DynamicDataSource extends AbstractRoutingDataSource { | ||
|
||
/** | ||
* 取得当前使用哪个数据源 | ||
* @return | ||
*/ | ||
protected Object determineCurrentLookupKey() { | ||
return DbContextHolder.getDbType(); | ||
} | ||
} | ||
|
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
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
Oops, something went wrong.