Skip to content

Commit

Permalink
多数据源2
Browse files Browse the repository at this point in the history
  • Loading branch information
hhj0719 committed Dec 4, 2020
1 parent 0b1b515 commit 53dbefd
Show file tree
Hide file tree
Showing 7 changed files with 270 additions and 126 deletions.
2 changes: 2 additions & 0 deletions Week_05/bean/.idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Week_05/bean/.idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Week_05/bean/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

381 changes: 259 additions & 122 deletions Week_05/bean/.idea/workspace.xml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.example.demo.model.User;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface UserMapper {

Expand All @@ -11,7 +13,7 @@ public interface UserMapper {
*
* @return
*/
User queryInfo();
List<User> queryInfo();

/**
* 保存信息
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Service
Expand All @@ -17,8 +18,8 @@ public class UserServiceImpl implements UserService {

@Override
public void query() {
User user = userMapper.queryInfo();
log.info("获取了用户信息 {}", user);
List<User> users = userMapper.queryInfo();
log.info("获取了用户信息 {}", users);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void testQuery() {

@Test
public void testSave(){
testService.saveInfo(2,"2");
testService.saveInfo(2,"张三");
}

}

1 comment on commit 53dbefd

@menghaoranss
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

整体思路是正确的,注意几个问题

  1. 包名不要大写,编码规范问题
  2. 使用注解来实现主从数据源的定义,使用AOP实现动态切换
  3. 参考shardingsphere读写分离源码
    继续加油
    可以参考作业:
    https://github.com/soph-hub/geek-university-java/tree/main/Week_07

Please sign in to comment.