- 目录
- 概 述
- 测试问题:
- 小结
- 参考资料和推荐阅读
目录 概 述LD is tigger forever,CG are not brothers forever, throw the pot and shine forever.
Modesty is not false, solid is not naive, treacherous but not deceitful, stay with good people, and stay away from poor people.
talk is cheap, show others the code and KPI, Keep progress,make a better result.
Survive during the day and develop at night。
下载mybatis 源码
测试问题:1.创建CreateDB的.sql:
create table users (
id int,
name varchar(20)
);
insert into users (id, name) values(1, ‘User1’);
insert into users (id, name) values(2, ‘User2’);
insert into users (id, name) values(3, ‘User3’);
insert into users (id, name) values(4, ‘User4’);
insert into users (id, name) values(5, ‘User5’);
insert into users (id, name) values(6, ‘User6’);
接口文件:
public interface Mapper {
User getUser(User user);
int countByUserList(List users);
int countByBestFriend(List users);
String selectWithNullItemCheck(List users);
int typoInItemProperty(List users);
int itemVariableConflict(@Param("id") Integer id, @Param("ids") List ids, @Param("ids2") List ids2);
int indexVariableConflict(@Param("idx") Integer id, @Param("idxs") List ids, @Param("idxs2") List ids2);
}
Mapper.xml文件:
select count(*) from users where id in #{id}, #{id} or id = #{id} select count(*) from users where id in #{idx}, #{idx} + 2 or id = #{idx}insert into users (id, name) values (#{item.idd}, #{item.name})
对应在这里插入代码片的加载配置文件:
对应的List-mapper 文件:
private Integer id; private String name; private User bestFriend; private ListfriendList;
获取一个指定的ID:
@Test
void shouldGetAUser() {
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
Mapper mapper = sqlSession.getMapper(Mapper.class);
User testProfile = new User();
testProfile.setId(2);
User friendProfile = new User();
friendProfile.setId(6);
List friendList = new ArrayList<>();
friendList.add(friendProfile);
testProfile.setFriendList(friendList);
User user = mapper.getUser(testProfile);
Assertions.assertEquals("User6", user.getName());
}
}
select count(*) from users where id in or id = #{idx} #{idx}, #{idx} + 2
ID增加:测试:
@Test
void shouldRemoveIndexVariableInTheContext() {
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
Mapper mapper = sqlSession.getMapper(Mapper.class);
int result = mapper.indexVariableConflict(4, Arrays.asList(6, 7), Arrays.asList(8, 9));
Assertions.assertEquals(4, result);
}
}
小结
参考资料和推荐阅读
1.链接: link.



