吉佳 发表于 2016-11-25 09:00:24

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();
SectionMappersectionMapper=session.getMapper(SectionMapper.class);
intresult=sectionMapper.updateByExampleSelective(record, example);
session.commit();
session.close();
return result;
}
  以上两种方式都能解决传入多个对象问题。
页: [1]
查看完整版本: Mybatis 多个参数的传入