I have been studying the integration of ibatis and spring for the past two days. I am dizzy with a small demo, but once the program runs, suddenly there is a kind of open-minded, I feel a wonderful life !, Maybe, this is what the code of that line brings us different enjoyment. No more nonsense.
Here, I would like to reference a few other people's documents...
DAOiBATISSqlMapClientiBATISspringSqlMapClient
HibernateSpring
. This article does not process transactions.
(
Person serialVersionUID = -517413165963030507L Person( id,String name,.id =.name =.sex = setId(.id = .name = setSex(.sex =
IAction. java
insertPerson(Person person); deleteById( id); updatePerson(Person person); Person queryById( id); List<Person> queryAllPerson(); }
Iii. DAO implementation class
ActionImpl. java class inherits SqlMapClientSupport to implement IAction Interface
ActionImpl SqlMapClientDaoSupport getSqlMapClientTemplate().insert("insertPerson" deleteById( getSqlMapClientTemplate().delete("deleteById" List<Person> List<Person> persons = getSqlMapClientTemplate().queryForList("queryAllPerson" Person queryById(
Iv. ibatis spring integration requires the ibatis configuration file.
SqlMapConfig. xml
SqlMapClient. xml should have data source configuration. After spring is used, the data source configuration is transplanted to spring.
V. Person. xml
Added, deleted, modified, and queried data.
6. Configure applicationContext. xml.
SqlMapConfig.xml
The required or not required in the comments have been tested by myself for many times. As to why is it necessary or not necessary, I am not able to clarify the principles clearly. I should write these statements here first.
If you are not familiar with each node and attributes, you can check other information online.
7. Compile the test class
This class uses junit for testing. Only some functions are tested.
ApplicationContext applicationContext = ; = ClassPathXmlApplicationContext("applicationContext.xml"); = (ActionImpl)applicationContext.getBean("personDAO" Person(1,"zhangsan",2 = (ActionImpl)applicationContext.getBean("personDAO"1 = (ActionImpl)applicationContext.getBean("personDAO"<Person> persons = Iterator<Person> ite =="ID: "+" Name: "+" Sex: "+
8: log4j. properties is required to record logs.
9: it is now the end. I think this is the most important thing, that is, the jar package problem.
I have been debugging for a long time. Most of the time is a jar problem.
List the jar packages that I think can run this applet.
If not, you can download it online.
The following is my directory structure
Conclusion: This article does not talk too much about the principles, for example, why is it written like this and why is it configured like this? It just provides a framework Framework framework.
I am also a cainiao. As for how to do it, I think it will be easy to understand when we have experience.
We also hope that everyone can work together to realize their dreams.
Hope you can join us!