测试代码ifforeachSQL语句片段抽取
测试代码public class MapperTest {
@Test
public void test1() throws IOException {
InputStream resourceAsStream = Resources.getResourceAsStream("SqlMapConfig.xml");
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(resourceAsStream);
SqlSession sqlSession = sqlSessionFactory.openSession();
UserMapper mapper = sqlSession.getMapper(UserMapper.class);
// if测试
//模拟user
User condition = new User();
condition.setId(1);
condition.setUsername("zhangsan");
condition.setPassword("123");
List user = mapper.findByConditon(condition);
System.out.println(user);
// foreach测试
//模拟Ids的数据
List ids = new ArrayList();
ids.add(1);
ids.add(2);
ids.add(3);
List userList = mapper.findByIds(ids);
System.out.println(userList);
}
}
if
UserMapper.xml配置文件里面的数据库查询拼接语句如果where里面没有为真的语句则where也不会创建
foreachselect * from user and id=#{id} and username=#{username} and password=#{password}
open表示开始的位置close表示结束item表示遍历的元素赋值给谁separator表示分隔符
SQL语句片段抽取
select * from user



