在自己建的的项目建立个lib文件
然后导入包
3.两个jar包部署到项目中和为项目添加测试类库
4.配置数据库
:连接数据库
环境配置好了,就建立
在src中建立一个包 entity
建立供应商的实体
package entity;public class Provider {private String procode;private String proname;private String prodesc;private String procontact;private String prophone;private String proaddress;private String profax;private int createdby;private String creationdate;public String getProcode() {return procode;}public void setProcode(String procode) {this.procode = procode;}public String getProname() {return proname;}public void setProname(String proname) {this.proname = proname;}public String getProdesc() {return prodesc;}public void setProdesc(String prodesc) {this.prodesc = prodesc;}public String getProcontact() {return procontact;}public void setProcontact(String procontact) {this.procontact = procontact;}public String getProphone() {return prophone;}public void setProphone(String prophone) {this.prophone = prophone;}public String getProaddress() {return proaddress;}public void setProaddress(String proaddress) {this.proaddress = proaddress;}public String getProfax() {return profax;}public void setProfax(String profax) {this.profax = profax;}public int getCreatedby() {return createdby;}public void setCreatedby(int createdby) {this.createdby = createdby;}public String getCreationdate() {return creationdate;}public void setCreationdate(String creationdate) {this.creationdate = creationdate;}
}
注意:是在包mapper下建立,ProviderMapper.xml
这是固定的:
然后要在:mybatis-config.xml
这里写这个
import java.io.IOException;
import java.io.InputStream;
import java.util.List;import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;import entity.Provider;public class ProviderMapperTest {@Testpublic void testFindAllUser() throws IOException{//1.加载mybatis核心配置文件InputStream inputStream = Resources.getResourceAsStream("mybatis-config.xml");//2.获取SqlSessionFactory对象SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);//3.得到执行sql的对象SqlSession SqlSession sqlSession = sqlSessionFactory.openSession();//4.执行sql语句List list = sqlSession.selectList("ProviderMapper.findAllProvider","HB_GYS001");//5.处理结果for (Provider smbms_provider: list) {System.out.println("编号:"+smbms_provider.getProcode()+",供应商名:"+smbms_provider.getProname()+"主要产品"+smbms_provider.getProdesc()+"姓名"+smbms_provider.getProcontact()+"电话"+smbms_provider.getProphone()+"地址"+smbms_provider.getProaddress()+"Fax:"+smbms_provider.getProfax()+"By:"+smbms_provider.getCreatedby()+"时间"+smbms_provider.getCreationdate());}//6.关闭数据库会话sqlSession.close();}}
上一篇:高校成人教育数字图书馆的服务理念