In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Spring iBATIS integration example analysis, in view of this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.
This is an entire example of Spring + iBATIS. In this example, two patterns are used for iBATIS integration with Spring.
Spring iBATIS Integration Mode 1
/ * UserDAO.java * Create Version: 4.2.0 * Author: PangLei * Create Date: 2005-04-21 * * Copyright (c) 2005 UTStarcom (China) Corporation. All Right Reserved. * / package net.chinaideal.samples.ibatis.dao; import java.sql.SQLException; import net.chinaideal.samples.ibatis.model.User; import com.ibatis.sqlmap.client.SqlMapClient / * SpringiBatis-UserDAO.java *-* @ version 2007-1-22 * @ author Panglei (bj02267) *-- -* Note: * UserDAO implementation * this implementation maintains the SqlMapClient of iBatis through Spring The specific call is done through the API of iBatis. * in this way, when Spring is not used, the API of iBatis is used, so it is portable. * * / public class UserDAOImpl implements UserDAO {protected SqlMapClient sqlMapClient; public User getUserByUsername (String username) {try {return (User) this.sqlMapClient.queryForObject ("getUserbyUsername", username);} catch (SQLException ex) {ex.printStackTrace ();} return null;} public SqlMapClient getSqlMapClient () {return sqlMapClient } public void setSqlMapClient (SqlMapClient sqlMapClient) {this.sqlMapClient = sqlMapClient;}}
Spring iBATIS Integration Mode 2
/ * UserDAOImpl2.java * Create Version: 4.2.0 * Author: PangLei * Create Date: 2005-04-21 * * Copyright (c) 2005 UTStarcom (China) Corporation. All Right Reserved. * / package net.chinaideal.samples.ibatis.dao; import net.chinaideal.samples.ibatis.model.User; import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport / * SpringiBatis-UserDAOImpl2.java *-* @ version 2007-1-22 * @ author Panglei (bj02267) *-- -* Note: * Mode 2:UserDAOImpl2 inherits SqlMapClientDaoSupport class * SqlMapClientDaoSupport this class provides many template methods for Spring's ibatis template class * ibatis template class Spring provides exception handling, which is easy to use. * for example: * queryForObject (statename, args) and so on. * * but this method uses SqlMapClientDaoSupport like Spring, so the support of Spring simplifies the coding process and is not portable enough. * / public class UserDAOImpl2 extends SqlMapClientDaoSupport implements UserDAO {/ * (non-Javadoc) * @ see net.chinaideal.samples.ibatis.dao.UserDAO#getUserByUsername (java.lang.String) * / public User getUserByUsername (String username) {return (User) getSqlMapClientTemplate () .queryForObject ("getUserbyUsername", username);}
Program download http://www.china-ideal.net/files/SpringiBatis.zip
So much for the answers to the sample analysis questions on Spring iBATIS integration. I hope the above content can be of some help to you. If you still have a lot of doubts to solve, you can follow the industry information channel for more related knowledge.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.