1.student.xml
<select id="selectStuDy" parameterType="java.util.Map" resultType="com.pro.domain.Student">
select * from student where 1=1
<if test="stuName!=null">
and stuName=#{stuName}
</if>
<if test="age!=null">
and age=#{age}
</if>
</select>
<select id="selectStuDy2" parameterType="java.util.Map" resultType="com.pro.domain.Student">
select * from student
<where>
<if test="stuName!=null">
and stuName=#{stuName}
</if>
<if test="age!=null">
and age=#{age}
</if>
</where>
</select>
<select id="updateStuDy" parameterType="java.util.Map">
update student
<set>
<if test="stuName!=null">
stuName=#{stuName},
</if>
<if test="age!=null">
age=#{age}
</if>
</set>
where stuId=#{stuId}
</select>
2.
@Test
public void testSelectStuDy() {
sqlSession = sqlSessionFactory.openSession();
Map<String, Object> map = new HashMap<String, Object>();
map.put("stuName", "jzr");
map.put("age", 22);
Student stu = sqlSession.selectOne("xxx.selectStuDy", map);
System.out.println(stu);
}
@Test
public void testSelectStuDy2() {
sqlSession = sqlSessionFactory.openSession();
Map<String, Object> map = new HashMap<String, Object>();
map.put("stuName", "jzr");
map.put("age", 22);
Student stu = sqlSession.selectOne("xxx.selectStuDy2", map);
System.out.println(stu);
}
@Test
public void testUpdateStuDy() {
sqlSession = sqlSessionFactory.openSession();
Map<String, Object> map = new HashMap<String, Object>();
map.put("stuName", "jzr");
map.put("age", 33);
map.put("stuId", 1);
sqlSession.update("xxx.updateStuDy", map);
sqlSession.commit();
}