<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<environments default="development">
<environment id="development">
<transactionManager type="JDBC" />
<dataSource type="POOLED">
<property name="driver" value="oracle.jdbc.driver.OracleDriver" />
<property name="url" value="jdbc:oracle:thin:@//localhost:1521/orcl" />
<property name="username" value="sa" />
<property name="password" value="123456" />
</dataSource>
</environment>
</environments>
<mappers>
<mapper resource="mapper/DistrictMapper.xml" />
</mappers>
</configuration>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="dao.DistrictDao">
<select id="select" resultType="entity.District">
select * from District
</select>
<select id="selectById" parameterType="int" resultType="entity.District">
select *
from District where id = #{id}
</select>
<select id="add">
INSERT INTO District (id,name)
VALUES (#{0},#{1})
</select>
<select id="del" parameterType="int">
delete District where id = #{id}
</select>
</mapper>
public class TestSession {
public static void main(String[] args) {
try {
InputStream config=Resources.getResourceAsStream("mybatis.xml");
SqlSessionFactory factory=new SqlSessionFactoryBuilder().build(config);
SqlSession session=factory.openSession();
DistrictDao dao=session.getMapper(DistrictDao.class);
dao.add(3001, "安徽1");
session.commit();
session.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
通过session.commit(true)是可以提交的
<select id="add">
INSERT INTO District (id,name)
VALUES (#{0},#{1})
</select>
这些插入的标签该用<insert id="add">INSERT INTO ...</insert>吧?
commit前没有 update/insert/delete操作?
不是有增加吗