\>
第十二章动态SQL操作之更新
1) 更新条件不确定,需要根据情况产生SQL语法,这种情况叫动态SQL 2) 参见<<动态SQL—更新.JPG>>
StudentDao.java /** *持久层 *@authorAdminTC */ publicclass StudentDao { /** *动态SQL--更新 */ publicvoid dynaSQLwithUpdate(Student student) throws Exception{ ; SqlSession sqlSession = MyBatisUtil.getSqlSession(); try{ sqlSession.update(\,student) }catch(Exception e){ e.printStackTrace(); sqlSession.rollback(); throw e;
} }finally{ sqlSession.commit(); MyBatisUtil.closeSqlSession(); } } publicstaticvoid main(String[] args) throws Exception{ StudentDao dao = new StudentDao(); dao.dynaSQLwithUpdate(new Student(10,null,5000D)); dao.dynaSQLwithUpdate(new Student(10,\哈哈\,null)); dao.dynaSQLwithUpdate(new Student(10,\哈哈\,6000D)); } StudentMapper.xml
第十三章动态SQL操作之删除
1) 根据ID删除学生
2) 参见<<动态SQL—删除.JPG>>
StudentDao.java /** *持久层
*@authorAdminTC */ publicclass StudentDao { /** } *动态SQL--删除 */ publicvoid dynaSQLwithDelete(int... ids) throws Exception{ SqlSession sqlSession = MyBatisUtil.getSqlSession(); try{ sqlSession.delete(\,ids); }catch(Exception e){ e.printStackTrace(); sqlSession.rollback(); throw e; }finally{ sqlSession.commit(); MyBatisUtil.closeSqlSession(); } } publicstaticvoid main(String[] ar