Mybatis 多个参数的传入

Mybatis 在传入多个参数的时候,可以选择传map对象,也可以选择定义接口

1,传map对象:

	public int updateByExampleSelective(Section record, SectionCriteria example) {
		SqlSession session=sessionFactory.openSession();
		Map<String, Object> map=new HashMap<String, Object>();
		map.put("record", record);
		map.put("example", example);
		int result=session.update("SectionMapper.updateByExampleSelective",map);
	 		session.commit();
		session.close();
		
		return result;
	}

将两个对象record,example 放入map中即可。

2,定义接口

接口:

public interface SectionMapper {
 int updateByExampleSelective(@Param("record") Section record, @Param("example") SectionCriteria example);
}

注入接口:

	public int updateByExampleSelective(Section record, SectionCriteria example) {
		SqlSession session=sessionFactory.openSession();
				SectionMapper  sectionMapper=session.getMapper(SectionMapper.class);
		int  result=sectionMapper.updateByExampleSelective(record, example);
				session.commit();
		session.close();
		
		return result;
	}

 以上两种方式都能解决传入多个对象问题。

猜你喜欢

转载自it456.iteye.com/blog/1336578