Use Ibatis in one step (1)

xiaoxiao2021-03-06  146

First of all, I want to declare that I am not very familiar with Ibatis, I am also in the learning phase. I just recorded the process of learning Ibatis. Of course, according to this process, you will eventually complete your first iBatis program. Among them, there are many places that make people dissatisfied, or you need to optimize, I hope everyone will discuss this thing with me.

Why do I want to learn ibatis? In fact, it is very simple, because I can use 20% of the code quantity to complete 80% of the function. There is also a good place for me is that my SQL statement can be modified simply through the configuration file.

The first step is ready. Under the IBATIS package, huh, go to http://www.ibatis.com to download, then Ibatis-Dao-2.jar, Ibatis-Sqlmap-2.jar, Ibatis-Common-2.jar three The file is added to the ClassPath of your project. (Toned to download IBAST source program packages and documentation. Description documents don't need me to say, everyone is only necessary, downloading the source package is mainly to better use this open source project, huh, you can modify itself Some functions :))

?? Step 2, huh, huh, build a simple table in the database. Daguo said that we have established a TEST table with but a field ID, name, email. Oh, here is the way, the more the fields you will find, the more Ibast's benefits :)

?? Step 3, build an Entity for this table, simply code as follows:

/ *? * CREATED ON 2004-8-9 *? * / Package test;

/ **? * @Author? @ *? * CopyRight (c) 2004? REASON BR>? *? * / public class testinfo {???????? String name; ??? String email ;? ???? / ** ???? * @return returns the email. ???? * / ??? public string getemail () {??????? Return email; ???} ?? ? / ** ???? * @Param email the email to set. ???? * / ??? public void setemail (String email) {??????? this.email = email; ??? } ??? / ** ???? * @return returns the ID. ???? * / ??? public int getId () {??????? Return ID; ???}??? / ** ???? * @Param ID the ID to set. ???? * / ??? public void setid (int id) {??????? this.id = ID; ???} ??? / ** ???? * @Return Returns the name. ???? * / ??? public string getName () {??????? Return Name; ???} ??? / ** ???? * @Param name the name to set. ???? * / ??? public void setname (String name) {??????? this.name = name; ???}}

??? The fourth step, OK, we start entering the iBast! ?????? Today we first build an interface for our developer. As for why I want to use the interface, I will understand together with you. (Note Oh, I didn't classify the package in this test program, huh, huh, in order to write this test, huh, don't learn me like this.) / *? * Created on 2004-8-9 *? * / package test;

/ **? * @author? @ ?? * Copyright? (c) 2004 REASON? *? * / import java.util.list;

Public interface testdao {? public list getList (int id); public int insert (test); public int delete (test) ;? public int update (TestOrder test);}??? We define basic Database operation method, if there are other needs in the actual development, you can follow this other way!

?? Oh, a little tired, today is still working overtime, Tomorrow's reference to Ibatis's MAPDAO, and the final implementation TestService two source code collapses :)

----- ibast We can start doing according to our easiest way, so I press my own idea, put the iBatis database configuration, the image of the SQL statement is written in the last side, because I think it looks in front. I know that these methods will go to the back of the mapping may be more convenient to understand!

转载请注明原文地址:https://www.9cbs.com/read-127565.html

New Post(0)