(Mybatis)输入映射和输出映射

1、parameterType(输入映射)

      *  传递简单类型:





      

      *  传递pojo对象:



	
		select LAST_INSERT_ID()
	
	insert into user(username, sex, birthday, address)
		 value(#{username},#{sex},#{birthday},#{address})

	


	update user set sex = #{sex} where id = #{id}

 

      *  传递pojo包装对象:

         QueryVo:

package com.jadan.pojo;

public class QueryVo {

	private User user;

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}
}

         sql 语句:


         UserMapper.java 接口:

package com.jadan.mapper;

import java.util.List;
import com.jadan.pojo.QueryVo;
import com.jadan.pojo.User;

public interface UserMapper {

	// 多条件查询
	public List findUserByVo(QueryVo vo);
}

         测试:

// 多条件查询
@Test
public void testFindUserByVo() {
	SqlSession openSession = factory.openSession();
	// 通过getMapper方法来实例化接口
	UserMapper mapper = openSession.getMapper(UserMapper.class);
		
	User user = new User();
	user.setUsername("小");
	user.setSex("1");
		
	QueryVo vo = new QueryVo();
	vo.setUser(user);
		
	List list = mapper.findUserByVo(vo);
	System.out.println(list);	
}

 

2、resultType(输出映射):

      *  输出基本类型:



 

      *  输出pojo对象:


 

      *  输出pojo列表:


 

下一篇:动态Sql

你可能感兴趣的:(MyBatis)