SSM获取SqlSessionFactory

1、实现类获取session

//根据id 修改阈值
public int altThers(threshold threshold) {

SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
try {
Reader reader = Resources.getResourceAsReader("/mybatis-config.xml");
SqlSessionFactory factory = builder.build(reader);
SqlSession session = factory.openSession(true);
session.getMapper(thresholdMapper.class).updateByPrimaryKeySelective(threshold);
session.commit();
session.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

return 0;
}

2、mybatis配置文件


"http://mybatis.org/dtd/mybatis-3-config.dtd">






















转载于:https://www.cnblogs.com/itxiaoxia/p/11446897.html

你可能感兴趣的:(java,数据库)