_007_根据map查询

代码一:

public class StudentDaoImpl implements IStudentDao {
@Override
public List<Student> selectStudentByCondition_1(Map<String,Object> map) {
// TODO Auto-generated method stub
List<Student> students = new ArrayList<>();
SqlSession sqlSession = null;
try {
sqlSession = MyBatisUtils.getSqlSession();
students=sqlSession.selectList("selectStudentByCondition_1",map);
sqlSession.commit();
} finally {
if(sqlSession!=null) {
sqlSession.close();
}
}
return students;
}
@Override
public List<Student> selectStudentByCondition(Map<String,Object> map) {
List<Student> students = new ArrayList<>();
SqlSession sqlSession = null;
try {
sqlSession = MyBatisUtils.getSqlSession();
students=sqlSession.selectList("selectStudentByCondition",map);
sqlSession.commit();
} finally {
if(sqlSession!=null) {
sqlSession.close();
}
}
return students;
}

}

------------------------------------

代码二:

    <select id="selectStudentByCondition" resultType="Student">
        select id,name,age,score from tb_student where score <![CDATA[ < ]]> #{stu.score}
    </select>
    
    <select id="selectStudentByCondition_1" resultType="Student">
        select id,name,age,score from tb_student where name like '%' #{name} '%' and age> #{age}

    </select>

------------------------

代码三:

@Test
public void testselectStudentByCondition() {
Student stu = new Student("hello",23,95);
Map<String,Object> map = new HashMap<String, Object>();
map.put("stu",stu);
List<Student> selectAllStudents = dao.selectStudentByCondition(map);
for(int i=0;i<selectAllStudents.size();i++) {
System.out.println(selectAllStudents.get(i));
}
}
//@Test
public void testselectStudentByCondition_1() {
Map<String,Object> map = new HashMap<String, Object>();
map.put("name", "张");
map.put("age",23);
List<Student> selectAllStudents = dao.selectStudentByCondition_1(map);
for(int i=0;i<selectAllStudents.size();i++) {
System.out.println(selectAllStudents.get(i));
}
}

猜你喜欢

转载自blog.csdn.net/poiuyppp/article/details/80542983
007
今日推荐