1.实体类Bill.java
package com.bean;
import java.util.Date;
/**
* @auther zll
* @create 2020/7/9-18:03
*/
public class Bill {
private int id;
private String billCode;
private String productName;
private String productDesc;
private String productCount;
private String totalPrice;
private Integer isPayment;
private Integer createdBy;
private Date creationDate;
private Integer modifyBy;
private String modifyDate;
private Integer providerId;
private String providerName;
public String getProviderName() {
return providerName;
}
public void setProviderName(String providerName) {
this.providerName = providerName;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getBillCode() {
return billCode;
}
public void setBillCode(String billCode) {
this.billCode = billCode;
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
public String getProductDesc() {
return productDesc;
}
public void setProductDesc(String productDesc) {
this.productDesc = productDesc;
}
public String getProductCount() {
return productCount;
}
public void setProductCount(String productCount) {
this.productCount = productCount;
}
public String getTotalPrice() {
return totalPrice;
}
public void setTotalPrice(String totalPrice) {
this.totalPrice = totalPrice;
}
public String getModifyDate() {
return modifyDate;
}
public void setModifyDate(String modifyDate) {
this.modifyDate = modifyDate;
}
public Integer getIsPayment() {
return isPayment;
}
public void setIsPayment(Integer isPayment) {
this.isPayment = isPayment;
}
public Integer getCreatedBy() {
return createdBy;
}
public void setCreatedBy(Integer createdBy) {
this.createdBy = createdBy;
}
public Date getCreationDate() {
return creationDate;
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
public Integer getModifyBy() {
return modifyBy;
}
public void setModifyBy(Integer modifyBy) {
this.modifyBy = modifyBy;
}
public Integer getProviderId() {
return providerId;
}
public void setProviderId(Integer providerId) {
this.providerId = providerId;
}
@Override
public String toString() {
return "Bill{" +
"id=" + id +
", billCode='" + billCode + '\'' +
", productName='" + productName + '\'' +
", productDesc='" + productDesc + '\'' +
", productCount='" + productCount + '\'' +
", totalPrice='" + totalPrice + '\'' +
", isPayment=" + isPayment +
", createdBy=" + createdBy +
", creationDate=" + creationDate +
", modifyBy=" + modifyBy +
", modifyDate='" + modifyDate + '\'' +
", providerId=" + providerId +
", providerName='" + providerName + '\'' +
'}';
}
}
2.SQL映射文件BillMapper.xml 和 接口类BillMapper
package com.dao;
import com.bean.Bill;
import java.util.List;
/**
* @auther zll
* @create 2020/7/9-19:21
*/
public interface BillMapper {
//根据商品名称(模糊查询),供应商id,是否付款 进行查询
public List<Bill> getBillByProName(Bill bill);
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.dao.BillMapper">
<select id="getBillByProName" resultType="com.bean.Bill" resultMap="billlist">
select b.billCode,b.productName,b.totalPrice,b.isPayment,b.creationDate,p.proName
from smbms_bill b,smbms_provider p where b.productName like concat('%',#{productName},'%') and b.isPayment=#{isPayment}
and b.providerId=p.id
</select>
<resultMap id="billlist" type="com.bean.Bill">
<id property="id" column="id"></id>
<result property="providerName" column="proName"></result>
</resultMap>
</mapper>
2.测试类
TestBillMapper.java
package com.test;
import com.bean.Bill;
import com.dao.BillMapper;
import com.util.SqlSessionUtil;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;
import java.util.List;
/**
* @auther zll
* @create 2020/7/9-19:39
*/
public class TestBillMapper {
@Test
public void test(){
SqlSession sqlSession = SqlSessionUtil.getSqlSession();
Bill bill = new Bill();
bill.setProductName("豆");
bill.setProviderId(6);
bill.setIsPayment(2);
List<Bill> list = sqlSession.getMapper(BillMapper.class).getBillByProName(bill);
for(Bill b : list){
System.out.println(b.getBillCode()+"\t"+b.getProductName()+"\t"+b.getProviderName());
}
SqlSessionUtil.closeSqlsession(sqlSession);
}
}