mybatis中的多条件查询问题——使用map作为参数

注:#{}中能放什么内容:
1、参数对象的属性
2、随意内容,此时的#{}为占位符
3、参数为map时的key
4、参数为map时,若key所对应的value为对象,则可将该对象的属性放入

1、mapper.xml





	
	

2、IStudentDao

package com.dao;


import java.util.List;
import java.util.Map;

import com.beans.Student;

public interface IStudentDao {

	List selectStudentByName(Map map);
	
}

3、MyTest

package com.test;



import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;
import org.junit.After;
import org.junit.Test;

import com.beans.Student;
import com.dao.IStudentDao;
import com.utils.SqlSessionUtils;

public class MyTest {
	
	private IStudentDao dao;
	private SqlSession sqlSession;
	
	@org.junit.Before
	public void before() {
		sqlSession = SqlSessionUtils.getSqlSession();
		dao = sqlSession.getMapper(IStudentDao.class);
	}
	
	@After
	public void After() {
		if (sqlSession != null) {
			sqlSession.close();
		}
	}
	
	
	@Test
	public void test08() {
		
		Student newStudent = new Student("田七", 23, 95);
		
		Map map = new HashMap();
		map.put("nameCon", "王");
		map.put("ageCon", 25);
		map.put("stu", newStudent);
		List students = dao.selectStudentByName(map);
		for (Student student : students) {
			System.out.println(student);
		}
	}
}

你可能感兴趣的:(mybatis中的多条件查询问题——使用map作为参数)