spingboot银行案例

2023-11-09 12:59
文章标签 案例 银行 spingboot

本文主要是介绍spingboot银行案例,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1.搭建环境

在这里插入图片描述

2.common

在这里插入图片描述

Account

public class Account implements Serializable {private Long id;private String cardno;private String password;private Double balance;private Long status;

Record

public class Record implements Serializable {private long id;private String cardno;private String transactiondate;private double expense;private double income;private double balance;private String transactiontype;private String remark;private String starttime;private String endtime;

AccountService

public interface AccountService {//1.登录Map<String,Object> login(Account account);//2.根据卡号查询余额Double findBalance(Account account);//3.修改密码String updatePWd(Account account);
}

RecordService

public interface RecordService {//1.转账String transferAccounts(String currentCardNo,String targetCardNo,Double money);//2.分页查询PageInfo<Map<String,Object>> showPage(Integer pageno, Record record);
}
3.provider结构

在这里插入图片描述

AccountMapper
public interface AccountMapper {//1.查询账号详情:根据卡号查,根据卡号密码查,根据卡号查余额Account findAccountInfo(Account account);//2.修改密码@Update("update account set password=#{password} where cardno#{cardno}")int updatePassword(Account account);//3.修改账号余额@Update("update account set balance=#{balance} where cardno#{cardno}")int updateBalance(Account account);
}
RecordMapper
public interface RecordMapper {//1.添加转出的交易记录@Insert("insert into record(cardno,transactiondate,expense,income,balance,transactiontype) values(#{cardno},now(),#{expense},0.0,#{balance},'转出')")int addExpenseRecord(Record record);//2.添加转入的交易记录@Insert("insert into record(cardno,transactiondate,expense,income,balance,transactiontype) values(#{cardno},now(),#{income},0.0,#{balance},'转入')")int addIncomeRecord(Record record);//3.根据交易日期分页查询,按照日期升序排列List<Map<String,Object>> showData(Record record);
}

AccountServiceImpl

@Service
@Transactional
public class AccountServiceImpl implements AccountService {@Autowiredprivate AccountMapper accountMapper;//登录@Overridepublic Map<String, Object> login(Account account) {Map<String, Object> map = new HashMap<String, Object>();//根据卡号查询Account loginuser = accountMapper.findAccountInfo(account);//判断卡号是否存在if (loginuser == null) {map.put("msg", "登录失败,你输入卡号不存在!");return map;}if(loginuser!=null){//判断密码是否正确if (!loginuser.getPassword().equals(account.getPassword())){map.put("msg","登录失败,您输入的密码不正确!");return map;}//判断账号是否被冻结if (loginuser.getStatus()==0){map.put("msg","登录失败,您的账号已冻结!");return map;}}//登录成功map.put("loginuser",loginuser);return map;}//查询余额@Overridepublic Double findBalance(Account account) {//根据卡号查询return accountMapper.findAccountInfo(account).getBalance();}//修改密码@Overridepublic String updatePWd(Account account) {String pwd = accountMapper.findAccountInfo(account).getPassword();if (!pwd.equals(account.getPassword())){return "旧密码输入错误!";}//修改accountMapper.updatePassword(account);return "success";}
}

RecordServiceImpl

public class RecordServiceImpl implements RecordService {@Autowiredprivate RecordMapper recordMapper;@Autowiredprivate AccountMapper accountMapper;//转账public String transferAccounts(String currentCardNo, String targetCardNo, Double money) {//查询目标账号Account targetAccount=accountMapper.findAccountInfo(new Account(targetCardNo,null,null));//判断目标卡号是否存在if(targetAccount==null){return "转账失败,目标账号不存在!";}//判断目标账号是否冻结if (targetAccount!=null && targetAccount.getStatus()==0){return "转账失败,目标账号已冻结";}//查询当前账号Account currentAccount=accountMapper.findAccountInfo(new Account(currentCardNo,null,null));//判断当前账号余额是否 >= 转账金额if (currentAccount!=null){if (currentAccount.getBalance()<money){return "转账失败,转出账号余额不足!";}}//当前账号余额减少currentAccount.setBalance(currentAccount.getBalance()-money);accountMapper.updateBalance(targetAccount);//目标账号余额增加targetAccount.setBalance(targetAccount.getBalance()+money);accountMapper.updateBalance(targetAccount);//当前账号转出交易记录Record currentAccountRecord=new Record(currentCardNo,money,null,currentAccount.getBalance());recordMapper.addExpenseRecord(currentAccountRecord);//目标账号转入交易记录Record targetAccountRecord=new Record(targetCardNo,null,money,targetAccount.getBalance());recordMapper.addIncomeRecord(targetAccountRecord);return "success";}//分页@Overridepublic PageInfo<Map<String, Object>> showPage(Integer pageno, Record record) {PageHelper.startPage(pageno,3);List<Map<String,Object>> list=recordMapper.showData(record);return new PageInfo<Map<String,Object>>(list);}
}

ProviderApplication

@MapperScan("cn.kgc.mapper")
@ImportResource("classpath:spring-provider.xml")
resource>mapper

AccountMapper.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.kgc.mapper.AccountMapper"><select id="findAccountInfo" resultType="Account" parameterType="Account">SELECT * FROM account WHERE cardno=#{cardno}<if test="password!=null">AND password=#{password}</if></select>
</mapper>

RecordMapper.xml

<mapper namespace="cn.kgc.mapper.RecordMapper"><select id="showData" parameterType="Record" resultType="map">SELECT * from record WHERE cardno=#{cardno}<if test="starttime!=null and endtime!=nulll">AND transactiondate BETWEEN #{starttime} AND #{endtime}</if>ORDER BY transactiondate ASC</select>
</mapper>

application.properties

server.port=9090spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/bankonline
spring.datasource.username=root
spring.datasource.password=123.mybatis.type-aliases-package=cn.kgc.vomybatis.mapper-locations=mapper/*.xmlpagehelper.helper-dialect=mysql

spring-provider.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:dubbo="http://code.alibabatech.com/schema/dubbo"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://code.alibabatech.com/schema/dubbohttp://code.alibabatech.com/schema/dubbo/dubbo.xsd"><!-- 提供方应用信息,用于计算依赖关系 --><dubbo:application name="myprovider" /><!-- 使用zookeeper注册中心暴露服务地址,我的zookeeper是架在本地的 --><dubbo:registry protocol="zookeeper" address="127.0.0.1:2181" timeout="60000"/><!-- 用dubbo协议在20880端口暴露服务 --><dubbo:protocol name="dubbo" port="20880" /><!-- 用户服务接口 --><dubbo:service interface="cn.kgc.service.AccountService" ref="accountService"/><bean id="accountService" class="cn.kgc.service.AccountServiceImpl"/><dubbo:service interface="cn.kgc.service.RecordService" ref="recordService"/><bean id="recordService" class="cn.kgc.service.RecordServiceImpl"/>
</beans>

4.consumer

CenterController

@RestController
public class CenterController {@Autowiredprivate AccountService accountService;@Autowiredprivate RecordService recordService;//登录@RequestMapping("/login.do")public Map<String,Object> login(Account account){return accountService.login(account);}//查询余额@RequestMapping("/balance.do")public Double findBalance(Account account){return accountService.findBalance(account);}//修改密码@RequestMapping("/pwd.do")public String updatePWd(Account account){return accountService.updatePWd(account);}//转账@RequestMapping("/ta.do")public String transferAccounts(String currentCardNo,String targetCardNo,Double money){return recordService.transferAccounts(currentCardNo,targetCardNo,money);}//分页@RequestMapping("/page.do")public PageInfo<Map<String,Object>> showPage(Integer pageno, Record record){return recordService.showPage(pageno,record);}
}

ConsumerApplication

@ImportResource("classpath:spring-consumer.xml")

rvice.transferAccounts(currentCardNo,targetCardNo,money);
}
//分页
@RequestMapping("/page.do")
public PageInfo<Map<String,Object>> showPage(Integer pageno, Record record){
return recordService.showPage(pageno,record);
}
}


ConsumerApplication```java
@ImportResource("classpath:spring-consumer.xml")

这篇关于spingboot银行案例的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/376237

相关文章

Nginx使用Keepalived部署web集群(高可用高性能负载均衡)实战案例

《Nginx使用Keepalived部署web集群(高可用高性能负载均衡)实战案例》本文介绍Nginx+Keepalived实现Web集群高可用负载均衡的部署与测试,涵盖架构设计、环境配置、健康检查、... 目录前言一、架构设计二、环境准备三、案例部署配置 前端 Keepalived配置 前端 Nginx

MySQL 复合查询案例详解

《MySQL复合查询案例详解》:本文主要介绍MySQL复合查询案例详解,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录基本查询回顾多表笛卡尔积子查询与where子查询多行子查询多列子查询子查询与from总结合并查询(不太重要)union基本查询回顾查询

Java Stream流使用案例深入详解

《JavaStream流使用案例深入详解》:本文主要介绍JavaStream流使用案例详解,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录前言1. Lambda1.1 语法1.2 没参数只有一条语句或者多条语句1.3 一个参数只有一条语句或者多

MySQL 中的 JSON 查询案例详解

《MySQL中的JSON查询案例详解》:本文主要介绍MySQL的JSON查询的相关知识,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录mysql 的 jsON 路径格式基本结构路径组件详解特殊语法元素实际示例简单路径复杂路径简写操作符注意MySQL 的 J

Python Transformers库(NLP处理库)案例代码讲解

《PythonTransformers库(NLP处理库)案例代码讲解》本文介绍transformers库的全面讲解,包含基础知识、高级用法、案例代码及学习路径,内容经过组织,适合不同阶段的学习者,对... 目录一、基础知识1. Transformers 库简介2. 安装与环境配置3. 快速上手示例二、核心模

Python中使用正则表达式精准匹配IP地址的案例

《Python中使用正则表达式精准匹配IP地址的案例》Python的正则表达式(re模块)是完成这个任务的利器,但你知道怎么写才能准确匹配各种合法的IP地址吗,今天我们就来详细探讨这个问题,感兴趣的朋... 目录为什么需要IP正则表达式?IP地址的基本结构基础正则表达式写法精确匹配0-255的数字验证IP地

MySQL高级查询之JOIN、子查询、窗口函数实际案例

《MySQL高级查询之JOIN、子查询、窗口函数实际案例》:本文主要介绍MySQL高级查询之JOIN、子查询、窗口函数实际案例的相关资料,JOIN用于多表关联查询,子查询用于数据筛选和过滤,窗口函... 目录前言1. JOIN(连接查询)1.1 内连接(INNER JOIN)1.2 左连接(LEFT JOI

springboot循环依赖问题案例代码及解决办法

《springboot循环依赖问题案例代码及解决办法》在SpringBoot中,如果两个或多个Bean之间存在循环依赖(即BeanA依赖BeanB,而BeanB又依赖BeanA),会导致Spring的... 目录1. 什么是循环依赖?2. 循环依赖的场景案例3. 解决循环依赖的常见方法方法 1:使用 @La

MySQL中实现多表查询的操作方法(配sql+实操图+案例巩固 通俗易懂版)

《MySQL中实现多表查询的操作方法(配sql+实操图+案例巩固通俗易懂版)》本文主要讲解了MySQL中的多表查询,包括子查询、笛卡尔积、自连接、多表查询的实现方法以及多列子查询等,通过实际例子和操... 目录复合查询1. 回顾查询基本操作group by 分组having1. 显示部门号为10的部门名,员

Python爬虫selenium验证之中文识别点选+图片验证码案例(最新推荐)

《Python爬虫selenium验证之中文识别点选+图片验证码案例(最新推荐)》本文介绍了如何使用Python和Selenium结合ddddocr库实现图片验证码的识别和点击功能,感兴趣的朋友一起看... 目录1.获取图片2.目标识别3.背景坐标识别3.1 ddddocr3.2 打码平台4.坐标点击5.图