Spring整合MyBatis-Plus
Spring整合MyBatis-Plus
maven依赖
<dependencies>
<!-- 单元测试 -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
</dependency>
<!-- spring start -->
<!--Spring核心依赖 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.3.1</version>
</dependency>
<!-- Spring beans包 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>5.3.1</version>
</dependency>
<!--Spring aspects依赖 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>5.3.1</version>
</dependency>
<!-- 切入点表达式解析 -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.9.6</version>
</dependency>
<!-- aopalliance -->
<dependency>
<groupId>aopalliance</groupId>
<artifactId>aopalliance</artifactId>
<version>1.0</version>
</dependency>
<!--Spring aop依赖 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>5.3.1</version>
</dependency>
<!-- Spring 容器包 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.3.1</version>
</dependency>
<!-- Spring 事务管理 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>5.3.1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.3.1</version>
</dependency>
<!-- spring end -->
<!-- mybatis-spring -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>2.0.6</version>
</dependency>
<!-- mybatis-plus -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus</artifactId>
<version>3.4.1</version>
</dependency>
<!-- 数据库连接驱动 -->
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.3.0</version>
</dependency>
<!-- Druid数据库连接池 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.2.3</version>
</dependency>
<!-- startLog -->
<!-- slf4j -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.0-alpha1</version>
</dependency>
<!-- logback -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.3.0-alpha5</version>
</dependency>
<!-- endLog -->
</dependencies>
<!-- 指定java版本 -->
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<encoding>UTF-8</encoding>
<java.version>1.8</java.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
配置文件
logback.xml
我这里使用的日志是logback
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoder 默认配置为PatternLayoutEncoder -->
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="DEBUG">
<appender-ref ref="STDOUT" />
</root>
</configuration>
jdbc.properties
使用的数据库连接池是Druid
jdbc.driverClassName=oracle.jdbc.OracleDriver
jdbc.url=jdbc:oracle:thin:@127.0.0.1:1521:ORCL
jdbc.username=ycy
jdbc.password=root
# 初始化连接数量
jdbc.initialSize=5
# 最大连接数
jdbc.maxActive=10
# 最大等待时间
jdbc.maxWait=3000
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
https://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- 扫描service包下的注解 -->
<context:component-scan base-package="cn.yecaiyu.bill.service"/>
<!-- 导入外部数据库配置 -->
<context:property-placeholder location="classpath:jdbc.properties"/>
<!-- 创建Druid数据源 -->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
<property name="initialSize" value="${jdbc.initialSize}"/>
<property name="maxActive" value="${jdbc.maxActive}"/>
<property name="maxWait" value="${jdbc.maxWait}"/>
</bean>
<!-- 配置SqlSessionFactoryBean -->
<bean id="sqlSessionFactoryBean" class="com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean">
<!-- 引入数据源 -->
<property name="dataSource" ref="dataSource"/>
<!-- 引入mybatisConfig -->
<property name="configuration" ref="configuration"/>
<!-- MyBaits 别名包扫描路径,通过该属性可以给包中的类注册别名,注册后在 Mapper 对应的 XML 文件中可以直接使用类名,而不用使用全限定的类名(即 XML 中调用的时候不用包含包名) -->
<property name="typeAliasesPackage" value="cn.yecaiyu.*.pojo"/>
<!-- 扫描xml文件 -->
<property name="mapperLocations">
<list>
<value>classpath:cn/yecaiyu/bill/mapper/*.xml</value>
</list>
</property>
<!-- 配置分页插件(已废弃) -->
<!-- <property name="plugins">
<array>
<bean class="com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor"/>
</array>
</property>-->
<property name="plugins">
<array>
<!-- 注入MybaitisPlus插件-->
<bean class="com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor">
<property name="interceptors">
<list>
<!-- 分页插件 -->
<bean class="com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor"/>
</list>
</property>
</bean>
</array>
</property>
</bean>
<!-- 配置mybatisConfig里的Setting -->
<bean id="configuration" class="com.baomidou.mybatisplus.core.MybatisConfiguration">
<!-- 指定 MyBatis 应如何自动映射列到字段或属性。
NONE 表示关闭自动映射;
PARTIAL 只会自动映射没有定义嵌套结果映射的字段。
FULL 会自动映射任何复杂的结果集(无论是否嵌套)。
-->
<property name="autoMappingBehavior" value="FULL"/>
<!-- 是否开启驼峰命名自动映射,即从经典数据库列名 A_COLUMN 映射到经典 Java 属性名 aColumn。 -->
<property name="mapUnderscoreToCamelCase" value="true"/>
<!-- Oracle一定要设置为NULL 默认:OTHER,Oracle识别不出OTHER -->
<property name="jdbcTypeForNull" value="NULL"/>
</bean>
<!-- 扫描mapper接口 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="cn.yecaiyu.*.mapper"/>
</bean>
<!-- 配置事务管理器 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- 注解方式配置事物 -->
<tx:annotation-driven/>
</beans>
测试
数据库表
使用的是Oracle数据库
create table SMBMS_BILL
(
id NUMBER(20) not null,
billcode VARCHAR2(20),
productname VARCHAR2(30),
productdesc VARCHAR2(50),
productunit VARCHAR2(10),
productcount NUMBER(20,2),
totalprice NUMBER(20,2),
ispayment NUMBER(10),
createdby NUMBER(20),
creationdate DATE,
modifyby NUMBER(20),
modifydate DATE,
providerid NUMBER(20)
)
tablespace SYSTEM
pctfree 10
pctused 40
initrans 1
maxtrans 255
storage
(
initial 64K
next 1M
minextents 1
maxextents unlimited
);
comment on column SMBMS_BILL.id
is '主键ID';
comment on column SMBMS_BILL.billcode
is '账单编码';
comment on column SMBMS_BILL.productname
is '商品名称';
comment on column SMBMS_BILL.productdesc
is '商品描述';
comment on column SMBMS_BILL.productunit
is '商品单位';
comment on column SMBMS_BILL.productcount
is '商品数量';
comment on column SMBMS_BILL.totalprice
is '商品总额';
comment on column SMBMS_BILL.ispayment
is '是否支付(1:未支付 2:已支付)';
comment on column SMBMS_BILL.createdby
is '创建者(userId)';
comment on column SMBMS_BILL.creationdate
is '创建时间';
comment on column SMBMS_BILL.modifyby
is '更新者(userId)';
comment on column SMBMS_BILL.modifydate
is '更新时间';
comment on column SMBMS_BILL.providerid
is '供应商ID';
alter table SMBMS_BILL
add primary key (ID)
using index
tablespace SYSTEM
pctfree 10
initrans 2
maxtrans 255
storage
(
initial 64K
next 1M
minextents 1
maxextents unlimited
);
insert into SMBMS_BILL (id, billcode, productname, productdesc, productunit, productcount, totalprice, ispayment, createdby, creationdate, modifyby, modifydate, providerid)
values (1, 'BILL2016_001', '洗发水、护发素', '日用品-洗发、护发', '瓶', 500, 25000, 2, 1, to_date('14-12-2014 13:02:03', 'dd-mm-yyyy hh24:mi:ss'), null, null, 13);
insert into SMBMS_BILL (id, billcode, productname, productdesc, productunit, productcount, totalprice, ispayment, createdby, creationdate, modifyby, modifydate, providerid)
values (2, 'BILL2016_002', '香皂、肥皂、药皂', '日用品-皂类', '块', 1000, 10000, 2, 1, to_date('23-03-2016 04:20:40', 'dd-mm-yyyy hh24:mi:ss'), null, null, 13);
insert into SMBMS_BILL (id, billcode, productname, productdesc, productunit, productcount, totalprice, ispayment, createdby, creationdate, modifyby, modifydate, providerid)
values (3, 'BILL2016_003', '大豆油', '食品-食用油', '斤', 300, 5890, 2, 1, to_date('14-12-2014 13:02:03', 'dd-mm-yyyy hh24:mi:ss'), null, null, 6);
insert into SMBMS_BILL (id, billcode, productname, productdesc, productunit, productcount, totalprice, ispayment, createdby, creationdate, modifyby, modifydate, providerid)
values (4, 'BILL2016_004', '橄榄油', '食品-进口食用油', '斤', 200, 9800, 2, 1, to_date('10-10-2013 03:12:13', 'dd-mm-yyyy hh24:mi:ss'), null, null, 7);
insert into SMBMS_BILL (id, billcode, productname, productdesc, productunit, productcount, totalprice, ispayment, createdby, creationdate, modifyby, modifydate, providerid)
values (5, 'BILL2016_005', '洗洁精', '日用品-厨房清洁', '瓶', 500, 7000, 2, 1, to_date('14-12-2014 13:02:03', 'dd-mm-yyyy hh24:mi:ss'), null, null, 9);
insert into SMBMS_BILL (id, billcode, productname, productdesc, productunit, productcount, totalprice, ispayment, createdby, creationdate, modifyby, modifydate, providerid)
values (6, 'BILL2016_006', '美国大杏仁', '食品-坚果', '袋', 300, 5000, 2, 1, to_date('14-04-2016 06:08:09', 'dd-mm-yyyy hh24:mi:ss'), null, null, 4);
insert into SMBMS_BILL (id, billcode, productname, productdesc, productunit, productcount, totalprice, ispayment, createdby, creationdate, modifyby, modifydate, providerid)
values (7, 'BILL2016_007', '沐浴液、精油', '日用品-沐浴类', '瓶', 500, 23000, 1, 1, to_date('22-07-2016 10:10:22', 'dd-mm-yyyy hh24:mi:ss'), null, null, 14);
insert into SMBMS_BILL (id, billcode, productname, productdesc, productunit, productcount, totalprice, ispayment, createdby, creationdate, modifyby, modifydate, providerid)
values (8, 'BILL2016_008', '不锈钢盘碗', '日用品-厨房用具', '个', 600, 6000, 2, 1, to_date('14-04-2016 05:12:13', 'dd-mm-yyyy hh24:mi:ss'), null, null, 14);
insert into SMBMS_BILL (id, billcode, productname, productdesc, productunit, productcount, totalprice, ispayment, createdby, creationdate, modifyby, modifydate, providerid)
values (9, 'BILL2016_009', '塑料杯', '日用品-杯子', '个', 350, 1750, 2, 1, to_date('04-02-2016 11:40:20', 'dd-mm-yyyy hh24:mi:ss'), null, null, 14);
insert into SMBMS_BILL (id, billcode, productname, productdesc, productunit, productcount, totalprice, ispayment, createdby, creationdate, modifyby, modifydate, providerid)
values (10, 'BILL2016_010', '豆瓣酱', '食品-调料', '瓶', 200, 2000, 2, 1, to_date('29-10-2013 05:07:03', 'dd-mm-yyyy hh24:mi:ss'), null, null, 8);
insert into SMBMS_BILL (id, billcode, productname, productdesc, productunit, productcount, totalprice, ispayment, createdby, creationdate, modifyby, modifydate, providerid)
values (11, 'BILL2016_011', '海之蓝', '饮料-国酒', '瓶', 50, 10000, 1, 1, to_date('14-04-2016 16:16:00', 'dd-mm-yyyy hh24:mi:ss'), null, null, 1);
insert into SMBMS_BILL (id, billcode, productname, productdesc, productunit, productcount, totalprice, ispayment, createdby, creationdate, modifyby, modifydate, providerid)
values (12, 'BILL2016_012', '芝华士', '饮料-洋酒', '瓶', 20, 6000, 1, 1, to_date('09-09-2016 17:00:00', 'dd-mm-yyyy hh24:mi:ss'), null, null, 1);
insert into SMBMS_BILL (id, billcode, productname, productdesc, productunit, productcount, totalprice, ispayment, createdby, creationdate, modifyby, modifydate, providerid)
values (13, 'BILL2016_013', '长城红葡萄酒', '饮料-红酒', '瓶', 60, 800, 2, 1, to_date('14-11-2016 15:23:00', 'dd-mm-yyyy hh24:mi:ss'), null, null, 1);
insert into SMBMS_BILL (id, billcode, productname, productdesc, productunit, productcount, totalprice, ispayment, createdby, creationdate, modifyby, modifydate, providerid)
values (14, 'BILL2016_014', '泰国香米', '食品-大米', '斤', 400, 5000, 2, 1, to_date('09-10-2016 15:20:00', 'dd-mm-yyyy hh24:mi:ss'), null, null, 3);
insert into SMBMS_BILL (id, billcode, productname, productdesc, productunit, productcount, totalprice, ispayment, createdby, creationdate, modifyby, modifydate, providerid)
values (15, 'BILL2016_015', '东北大米', '食品-大米', '斤', 600, 4000, 2, 1, to_date('14-11-2016 14:00:00', 'dd-mm-yyyy hh24:mi:ss'), null, null, 3);
insert into SMBMS_BILL (id, billcode, productname, productdesc, productunit, productcount, totalprice, ispayment, createdby, creationdate, modifyby, modifydate, providerid)
values (16, 'BILL2016_016', '可口可乐', '饮料', '瓶', 2000, 6000, 2, 1, to_date('27-03-2012 13:03:01', 'dd-mm-yyyy hh24:mi:ss'), null, null, 2);
insert into SMBMS_BILL (id, billcode, productname, productdesc, productunit, productcount, totalprice, ispayment, createdby, creationdate, modifyby, modifydate, providerid)
values (17, 'BILL2016_017', '脉动', '饮料', '瓶', 1500, 4500, 2, 1, to_date('10-05-2016 12:00:00', 'dd-mm-yyyy hh24:mi:ss'), null, null, 2);
insert into SMBMS_BILL (id, billcode, productname, productdesc, productunit, productcount, totalprice, ispayment, createdby, creationdate, modifyby, modifydate, providerid)
values (18, 'BILL2016_018', '哇哈哈', '饮料', '瓶', 2000, 4000, 2, 1, to_date('24-11-2015 15:12:03', 'dd-mm-yyyy hh24:mi:ss'), null, null, 2);
commit;
alter table SMBMS_BILL enable all triggers;
实体类
package cn.yecaiyu.bill.pojo;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.util.Date;
/**
* @author YeCaiYu
* @date 2020-11-19 15:13:09
*/
@TableName(value = "SMBMS_BILL")
public class Bill {
/**
* 主键ID
*/
@TableId
private Integer id;
/**
* 账单编码
*/
@TableField(value = "BILLCODE")
private String billCode;
/**
* 商品名称
*/
@TableField(value = "PRODUCTNAME")
private String productName;
/**
* 商品描述
*/
@TableField(value = "PRODUCTDESC")
private String productDesc;
/**
* 商品单位
*/
@TableField(value = "PRODUCTUNIT")
private String productUnit;
/**
* 商品数量
*/
@TableField(value = "PRODUCTCOUNT")
private Integer productCount;
/**
* 商品总额
*/
@TableField(value = "TOTALPRICE")
private Integer totalPrice;
/**
* 是否支付(1:未支付 2:已支付)
*/
@TableField(value = "ISPAYMENT")
private Integer isPayment;
/**
* 创建者(userId)
*/
@TableField(value = "CREATEDBY")
private Integer createdBy;
/**
* 创建时间
*/
@TableField(value = "CREATIONDATE")
private Date creationDate;
/**
* 更新者(userId)
*/
@TableField(value = "MODIFYBY")
private Integer modifyBy;
/**
* 更新时间
*/
@TableField(value = "MODIFYDATE")
private Date modifyDate;
/**
* 供应商ID
*/
@TableField(value = "PROVIDERID")
private Integer providerId;
public Integer getId() {
return id;
}
public void setId(Integer 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 getProductUnit() {
return productUnit;
}
public void setProductUnit(String productUnit) {
this.productUnit = productUnit;
}
public Integer getProductCount() {
return productCount;
}
public void setProductCount(Integer productCount) {
this.productCount = productCount;
}
public Integer getTotalPrice() {
return totalPrice;
}
public void setTotalPrice(Integer totalPrice) {
this.totalPrice = totalPrice;
}
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 Date getModifyDate() {
return modifyDate;
}
public void setModifyDate(Date modifyDate) {
this.modifyDate = modifyDate;
}
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 + '\'' +
", productUnit='" + productUnit + '\'' +
", productCount=" + productCount +
", totalPrice=" + totalPrice +
", isPayment=" + isPayment +
", createdBy=" + createdBy +
", creationDate=" + creationDate +
", modifyBy=" + modifyBy +
", modifyDate=" + modifyDate +
", providerId=" + providerId +
'}';
}
}
Mapper
接口
package cn.yecaiyu.bill.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import cn.yecaiyu.bill.pojo.Bill;
/**
* @author YeCaiYu
* @date 2020-11-19 15:13:09
*/
public interface IBillMapper extends BaseMapper<Bill> {
}
xml
<?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="cn.yecaiyu.bill.mapper.IBillMapper">
<resultMap id="BaseResultMap" type="cn.yecaiyu.bill.pojo.Bill">
<!--@mbg.generated-->
<!--@Table SMBMS_BILL-->
<id column="ID" jdbcType="DECIMAL" property="id"/>
<result column="BILLCODE" jdbcType="VARCHAR" property="billCode"/>
<result column="PRODUCTNAME" jdbcType="VARCHAR" property="productName"/>
<result column="PRODUCTDESC" jdbcType="VARCHAR" property="productDesc"/>
<result column="PRODUCTUNIT" jdbcType="VARCHAR" property="productUnit"/>
<result column="PRODUCTCOUNT" jdbcType="DECIMAL" property="productCount"/>
<result column="TOTALPRICE" jdbcType="DECIMAL" property="totalPrice"/>
<result column="ISPAYMENT" jdbcType="DECIMAL" property="isPayment"/>
<result column="CREATEDBY" jdbcType="DECIMAL" property="createdBy"/>
<result column="CREATIONDATE" jdbcType="TIMESTAMP" property="creationDate"/>
<result column="MODIFYBY" jdbcType="DECIMAL" property="modifyBy"/>
<result column="MODIFYDATE" jdbcType="TIMESTAMP" property="modifyDate"/>
<result column="PROVIDERID" jdbcType="DECIMAL" property="providerId"/>
</resultMap>
<sql id="Base_Column_List">
<!--@mbg.generated-->
ID, BILLCODE, PRODUCTNAME, PRODUCTDESC, PRODUCTUNIT, PRODUCTCOUNT, TOTALPRICE, ISPAYMENT,
CREATEDBY, CREATIONDATE, MODIFYBY, MODIFYDATE, PROVIDERID
</sql>
</mapper>
service
接口
package cn.yecaiyu.bill.service;
import com.baomidou.mybatisplus.extension.service.IService;
import cn.yecaiyu.bill.pojo.Bill;
/**
* @author YeCaiYu
* @date 2020-11-19 15:29:42
*/
public interface IBillService extends IService<Bill> {
}
实现类
package cn.yecaiyu.bill.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.yecaiyu.bill.mapper.IBillMapper;
import cn.yecaiyu.bill.pojo.Bill;
import cn.yecaiyu.bill.service.IBillService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
* @author YeCaiYu
* @date 2020-11-19 15:29:56
*/
@Service
public class BillService extends ServiceImpl<IBillMapper, Bill> implements IBillService {
}
测试类
package cn.yecaiyu.test;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import cn.yecaiyu.bill.pojo.Bill;
import cn.yecaiyu.bill.service.IBillService;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* @author YeCaiYu
* @date 2020-11-19 18:53:34
*/
public class TestMain {
@Test
public void test01() {
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
IBillService billService = (IBillService) context.getBean("billService");
QueryWrapper<Bill> wrapper = new QueryWrapper<>();
// wrapper.eq("ID", 1);
// List<Bill> bills = billService.list(wrapper);
// bills.forEach(System.out::println);
Page<Bill> page = new Page<>(1, 5);
Page<Bill> billPage = billService.page(page, wrapper);
billPage.getRecords().forEach(System.out::println);
}
}
目录结构
- src
- main
- java
- cn.yecaiyu.bill
- mapper
- IBillMapper.java
- pojo
- Bill.java
- service
- impl
- BillService.java
- IBillService.java
- impl
- mapper
- cn.yecaiyu.bill
- resources
- cn/yecaiyu/bill/mapper
- IBillMapper.xml
- applicationContext.xml
- jdbc.properties
- logback.xml
- cn/yecaiyu/bill/mapper
- java
- test
- cn.yecaiyu.bill.test
- TestMain.java
- cn.yecaiyu.bill.test
- main