Mybatis入门--多条件查询
Mappery.xml
传入HashMap集合后,下面的SQL语句就以” #{key} “形式获取对应的value值。
<select id="attrs" parameterType="java.util.HashMap" resultType="com.iteima.po.Customer"> <!--下面是#{key}这种形式 ,来取出HaspMap中对应的value值--> select * from t_customer where id=#{id} and username =#{username} </select>
Test.java
@Test public void Test06() { SqlSession sqlSession = MybatisUtils.getSession(); HashMap<String,Object> maps=new HashMap<String, Object>(); maps.put("id", 3); maps.put("username", "rros"); List<Customer> list = sqlSession.selectList("com.iteima.mapper.CustomerMapper.attrs", maps); for (Customer cu : list) { System.out.println(cu); } sqlSession.close(); }