其他分享
首页 > 其他分享> > 【Mybatis01】实现缩小版银行转账+分页查询功能

【Mybatis01】实现缩小版银行转账+分页查询功能

作者:互联网

一、实现转账

1.1 项目实现图和结构图
在这里插入图片描述在这里插入图片描述
1.1.1 pojo实体类

public class Account {        //用户账户表
    private int id;
    private String accNo;
    private int password;
    private Double balance;
    private String name;
public class Log {          //转账日志表
    private int id;
    private String accIn;
    private String accOut;
    private double money;

!分页查询表

    private int pageSize;   //当前页显示的数据   
    private int pageNumber;  //当前页数
    private long total;     //总数量
    private List<?> list;     //当前页显示的总数数据

1.2 全局文件mybatis.xml的编写

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
    <typeAliases>
        <package name="com.bjsxt.pojo"/>
    </typeAliases>
    <environments default="default">
        <environment id="default">
            <transactionManager type="JDBC"></transactionManager>
            <dataSource type="POOLED">  //三种方式此种是数据库连接池方式
                <property name="driver" value="com.mysql.jdbc.Driver"/>
                <property name="url" value="jdbc:mysql://localhost:3306/ssm"/>
                <property name="username" value="root"/>
                <property name="password" value="1234"/>
            </dataSource>
        </environment>
    </environments>
    <mappers>
        <mapper resource="com\bjsxt\mapper\AccountMapper.xml"/>   //加载转账的xml
        <mapper resource="com\bjsxt\mapper\LogMapper.xml"/>         //加载转账日志的xml
</mappers>
</configuration>

1.3 mapper.xml的编写(用来进行查询!!!)
在这里插入图片描述

AccountMapper.xml

1.3.1分析:

<?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.bjsxt.mapper.AccountMapper">
    <!--根据账号和密码查询账户信息-->
    <select id="selByAccnoPwd" resultType="account" parameterType="account">
        select * from account where accno=#{accNo} and password=#{password}
    </select>
    <!--根据账号和姓名查询账户信息-->
    <select id="selByAccnoName"  resultType="account" parameterType="account">
        select * from account where accno=#{accNo} and name=#{name}
    </select>
    <!--根据账号修改余额-->
    <update id="updBalanceByAccno" parameterType="account">
        update account set  balance=balance+#{balance} where accno=#{accNo}
    </update>
</mapper>

1.3.2写完mapper然后写service层!

-分析
int transfer(Account accIn,Account accOut) throws IOException;

impl层

标签:转账,xml,Account,分页,int,private,String,Mybatis01
来源: https://blog.csdn.net/wrf20162305/article/details/88206802