<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.xiaobu.mapper.CountryMapper">
<select id="findList" resultType="com.xiaobu.entity.Country">
select * from country where id in (#{ids} )
</select>
<select id="findList2" resultType="com.xiaobu.entity.Country">
select * from country where id in (${ids} )
</select>
<select id="findListByForEach" parameterType="List" resultType="com.xiaobu.entity.Country">
select * from country where id in
<foreach collection="list" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</select>
</mapper>
@Test
public void countTotal(){
//统计总数 SELECT COUNT(Id) FROM country
Example example = new Example(City.class);
int count =countryMapper.selectCountByExample(example);
System.out.println("count = " + count);
//按条件查询 SELECT COUNT(Id) FROM country
Country country = new Country();
//country.setCountryname("1234");
int conunt2 = countryMapper.selectCount(country);
System.out.println("conunt2 = " + conunt2);
}
@Test
public void findList(){
//Preparing: select * from country where id in ( '1,2,3')
List<Country> countries = countryMapper.findList("1,2,3");
//countries = [Country(countryname=Angola, countrycode=AO)]
System.out.println("countries = " + countries);
//报错 There is no getter for property named 'ids' in 'class java.lang.String
List<Country> countries2 = countryMapper.findList2("1,2,3");
System.out.println("countries2 = " + countries2);
}
@Test
public void findListByForeach(){
//Preparing: select * from country where id in ( ? , ? , ? )
//Parameters: 1(Integer), 2(Integer), 3(Integer)
List<Integer> list = new ArrayList<>(3);
list.add(1);
list.add(2);
list.add(3);
List<Country> countries2 = countryMapper.findListByForEach(list);
System.out.println("countries2 = " + countries2);
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.xiaobu.mapper.CountryMapper">
<select id="findList" resultType="com.xiaobu.entity.Country">
select * from country where id in (#{ids} )
</select>
<select id="findList2" resultType="com.xiaobu.entity.Country">
select * from country where id in (${ids} )
</select>
<select id="findListByForEach" parameterType="List" resultType="com.xiaobu.entity.Country">
select * from country where id in
<foreach collection="list" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</select>
</mapper>
@Test
public void countTotal(){
//统计总数 SELECT COUNT(Id) FROM country
Example example = new Example(City.class);
int count =countryMapper.selectCountByExample(example);
System.out.println("count = " + count);
//按条件查询 SELECT COUNT(Id) FROM country
Country country = new Country();
//country.setCountryname("1234");
int conunt2 = countryMapper.selectCount(country);
System.out.println("conunt2 = " + conunt2);
}
@Test
public void findList(){
//Preparing: select * from country where id in ( '1,2,3')
List<Country> countries = countryMapper.findList("1,2,3");
//countries = [Country(countryname=Angola, countrycode=AO)]
System.out.println("countries = " + countries);
//报错 There is no getter for property named 'ids' in 'class java.lang.String
List<Country> countries2 = countryMapper.findList2("1,2,3");
System.out.println("countries2 = " + countries2);
}
@Test
public void findListByForeach(){
//Preparing: select * from country where id in ( ? , ? , ? )
//Parameters: 1(Integer), 2(Integer), 3(Integer)
List<Integer> list = new ArrayList<>(3);
list.add(1);
list.add(2);
list.add(3);
List<Country> countries2 = countryMapper.findListByForEach(list);
System.out.println("countries2 = " + countries2);
}