mybatis 更新数据表、自动增长序列、
一、更新数据表
1.在映射文件中添加:
<update id="updateStudentById" parameterType="Student">
update student set name=#{name},age=#{age} where id=#{id}
</update>
2.在测试文件中添加(先查询出修改的对象,然后在修改)
String statement="com.huayu.mapper.studentMapper"+".selectStudentById";
// String statement1="com.huayu.mapper.studentMapper"+".updateStudentById";
// Student st=sqlSession.selectOne (statement,6);
// st.setName("huahua");
// st.setAge(20);
// sqlSession.update(statement1, st);
二、添加数据时,针对id设主键,避免唯一约束,如何实现自动增长
1.第一种方式:
在oracle中.
a、添加序列表
b、在映射文件中找到insert元素输入以下内
一、更新数据表
1.在映射文件中添加:
<update id="updateStudentById" parameterType="Student">
update student set name=#{name},age=#{age} where id=#{id}
</update>
2.在测试文件中添加(先查询出修改的对象,然后在修改)
String statement="com.huayu.mapper.studentMapper"+".selectStudentById";
// String statement1="com.huayu.mapper.studentMapper"+".updateStudentById";
// Student st=sqlSession.selectOne (statement,6);
// st.setName("huahua");
// st.setAge(20);
// sqlSession.update(statement1, st);
二、添加数据时,针对id设主键,避免唯一约束,如何实现自动增长
1.第一种方式:
在oracle中.
a、添加序列表
b、在映射文件中找到insert元素输入以下内