第一步:创建BillMapper接口 ,ProviderMapper接口
public interface BillMapper {
//根据商品名称(模糊查询),供应商id,是否付款 进行查询
public List getBillByProName(Bill bill);
}
public interface ProviderMapper {
public List getAllProvider();
}
第二步:创建他们的实现类
public class BillMapperImpl implements BillMapper{
private SqlSessionTemplate sqlSessionTemplate;
public SqlSessionTemplate getSqlSessionTemplate() {
return sqlSessionTemplate;
}
public void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate) {
this.sqlSessionTemplate = sqlSessionTemplate;
}
@Override
public List getBillByProName(Bill bill) {
return sqlSessionTemplate.getMapper(BillMapper.class).getBillByProName(bill);
}
}
package com.MyBatis.dao;
import com.pojo.Provider;
import org.mybatis.spring.SqlSessionTemplate;
import java.util.List;
/**
* @auther zll
* @create 2020/7/16-19:25
*/
public class ProviderMapperImpl implements ProviderMapper{
private SqlSessionTemplate sqlSessionTemplate;
public SqlSessionTemplate getSqlSessionTemplate() {
return sqlSessionTemplate;
}
public void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate) {
this.sqlSessionTemplate = sqlSessionTemplate;
}
@Override
public List getAllProvider() {
return sqlSessionTemplate.getMapper(ProviderMapper.class).getAllProvider();
}
}
第三步:创建其对应的映射文件
第四步:创建BillService和ProviderService接口
public interface BillService {
public List getBillByNameIdIsPay(Bill bill);
}
public interface ProviderService {
public List getall();
}
第五步:实现类
package com.spring.service;
import com.MyBatis.dao.BillMapperImpl;
import com.pojo.Bill;
import java.util.List;
/**
* @auther zll
* @create 2020/7/16-20:33
*/
public class BillServiceImpl implements BillService {
private BillMapperImpl billMapper;
public BillMapperImpl getBillMapper() {
return billMapper;
}
public void setBillMapper(BillMapperImpl billMapper) {
this.billMapper = billMapper;
}
@Override
public List getBillByNameIdIsPay(Bill bill) {
return billMapper.getBillByProName(bill);
}
}
package com.spring.service;
import com.MyBatis.dao.ProviderMapper;
import com.pojo.Provider;
import java.util.List;
/**
* @auther zll
* @create 2020/7/16-19:38
*/
public class ProviderServiceImpl implements ProviderService {
private ProviderMapper providerMapper;
public ProviderMapper getProviderMapper() {
return providerMapper;
}
public void setProviderMapper(ProviderMapper providerMapper) {
this.providerMapper = providerMapper;
}
@Override
public List getall() {
return providerMapper.getAllProvider();
}
}
第六步:配置applicationContext.xml文件
第七步:测试
public class TestBill {
@Test
public void test(){
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
BillService p = (BillService) context.getBean("billService");
List list = new ArrayList<>();
Bill bill = new Bill();
bill.setProductName("北");
bill.setIsPayment(2);
list = p.getBillByNameIdIsPay(bill);
for (Bill p1 : list){
System.out.println(p1.toString());
}
}
}
public class TestProvider {
@Test
public void test(){
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
ProviderService p = (ProviderService) context.getBean("providerService");
List list = new ArrayList<>();
list = p.getall();
for (Provider p1 : list){
System.out.println(p1.toString());
}
}
}