Ibatis的简单配置和使用(学习中的笔记)
1、将支持包ibatis-2.3.0.677.jar拷贝到lib下
4、修改News.xml
package cn.mldn.ibatis.service.impl;import java.sql.SQLException;import java.util.List;import cn.mldn.ibatis.dao.NewsDAO;import cn.mldn.ibatis.dao.impl.NewsDAOImpl;import cn.mldn.ibatis.dbc.SqlMapSessionFactory;import cn.mldn.ibatis.service.NewsService;import cn.mldn.ibatis.vo.News;public class NewsServiceImpl implements NewsService {private NewsDAO newsdao = new NewsDAOImpl();public boolean doCreate(News news) {boolean flag = false;try {SqlMapSessionFactory.getSession().startTransaction();flag = this.newsdao.doCreate(news);SqlMapSessionFactory.getSession().commitTransaction();} catch (Exception e) {e.printStackTrace();try {SqlMapSessionFactory.getSession().endTransaction();} catch (SQLException e1) {}} finally {SqlMapSessionFactory.closeSession();}return flag;}public boolean doDelete(int id) {boolean flag = false;try {SqlMapSessionFactory.getSession().startTransaction();flag = this.newsdao.doDelete(id);SqlMapSessionFactory.getSession().commitTransaction();} catch (Exception e) {e.printStackTrace();try {SqlMapSessionFactory.getSession().endTransaction();} catch (SQLException e1) {}} finally {SqlMapSessionFactory.closeSession();}return flag;}public boolean doUpdate(News news) {boolean flag = false;try {SqlMapSessionFactory.getSession().startTransaction();flag = this.newsdao.doUpdate(news);SqlMapSessionFactory.getSession().commitTransaction();} catch (Exception e) {e.printStackTrace();try {SqlMapSessionFactory.getSession().endTransaction();} catch (SQLException e1) {}} finally {SqlMapSessionFactory.closeSession();}return flag;}public List<News> findAll() {List all = null;try {all = this.newsdao.findAll();} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();} finally {SqlMapSessionFactory.closeSession();}return all;}public News findById(int id) {News news = null;try {news = this.newsdao.findById(id);} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();} finally {SqlMapSessionFactory.closeSession();}return news;}??
?