Get the App
SLTechnology News&Howtos  ›  Development  › 

Example Analysis of Spring iBATIS Integration

Shulou Source: shulou.com Published: 2022-06-02 23:01:01 10月12日 Update

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.

Tags: Integration patterns analysis methods templates questions examples more portability help migration solutions easy not enough examples content guys buddies are in Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux macOS Shulou Tech Info vpn NVidia