当前位置: 首页 > news >正文

沈阳专业做网站方案网站推广优化的原因

沈阳专业做网站方案,网站推广优化的原因,工厂管理软件,c2c模式的典型网站文章目录 数据库表的设计和准备数据环境搭建前端页面编写后端代码实现后端代码目录dao层servicewebpojoUtils 数据库表的设计和准备数据 环境搭建 在pom.xml中配置依赖&#xff08;logback、mybatis、mysql、servlet&#xff09; 注意引入tomcat 前端页面编写 <!DOCTYPE …

文章目录

  • 数据库表的设计和准备数据
  • 环境搭建
  • 前端页面编写
  • 后端代码实现
    • 后端代码目录
    • dao层
    • service
    • web
    • pojo
    • Utils

数据库表的设计和准备数据

在这里插入图片描述
在这里插入图片描述

环境搭建

在pom.xml中配置依赖(logback、mybatis、mysql、servlet)
注意引入tomcat

前端页面编写

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>银行账户转账</title>
</head>
<body><form action="/bank/transfer" method="post">转出账户:<input type="text" name="fromActno"><br>转入账号:<input type="text" name="toActno"><br>转账金额:<input type="text" name="money"><br><input type="submit" value="转账"></form>
</body>
</html>

后端代码实现

后端代码目录

在这里插入图片描述

dao层

//AccountDaoImpl
package com.example.bank.dao.impl;import com.example.bank.dao.AccountDao;
import com.example.bank.pojo.Account;
import com.example.bank.utils.SqlSessionUtil;
import org.apache.ibatis.session.SqlSession;public class AccountDaoImpl implements AccountDao {@Overridepublic Account selectByActno(String actno) {SqlSession sqlSession = SqlSessionUtil.openSession();Account account = (Account) sqlSession.selectOne("account.selectByActno", actno);sqlSession.close();return account;}@Overridepublic int updateByActno(Account act) {SqlSession sqlSession = SqlSessionUtil.openSession();int count = sqlSession.update("account.updateByActno",act);sqlSession.commit();sqlSession.close();return count;}
}
package com.example.bank.dao;import com.example.bank.pojo.Account;//dao对象中的任何一个方法和业务不挂钩,没有任何业务逻辑在里面
//DAO中的方法就是做CRUD的
public interface AccountDao {//根据账号查询账户信息Account selectByActno(String actno);//更新账户信息int updateByActno(Account act);
}

dao层是三层架构的最底层,是数据访问层,主要是连接MySQL,并做数据的CRUD,不包含任何的逻辑

service

//AccountServiceImpl
package com.example.bank.service.impl;import com.example.bank.dao.AccountDao;
import com.example.bank.dao.impl.AccountDaoImpl;
import com.example.bank.exceptions.MoneyNotEnoughException;
import com.example.bank.exceptions.TransferException;
import com.example.bank.pojo.Account;
import com.example.bank.service.AccountService;public class AccountServiceImpl implements AccountService {private AccountDao accountDao = new AccountDaoImpl();@Overridepublic void transfer(String fromActno, String toActno, double money) throws MoneyNotEnoughException, TransferException {//1、判断转出账户的余额是否充足Account fromAct = accountDao.selectByActno(fromActno);if (fromAct.getBalance() < money){//2、如果转出账户余额不足,提示用户throw new MoneyNotEnoughException("对不起,您的余额不足");}//3、如果转出账户余额充足,更新转出账户余额(update)//先更新内存中java对象account的余额Account toAct = accountDao.selectByActno(toActno);fromAct.setBalance(fromAct.getBalance() - money);toAct.setBalance(toAct.getBalance() + money);int count = accountDao.updateByActno(fromAct);//4、更新转入账户余额(update)count += accountDao.updateByActno(toAct);if (count != 2){throw new TransferException("转账异常,未知原因");}}}
//AccountService
package com.example.bank.service;import com.example.bank.exceptions.MoneyNotEnoughException;
import com.example.bank.exceptions.TransferException;public interface AccountService {
//    @param fromActno 转出账号
//    @param toActno 转入账号
//    @param money 转账金额void transfer(String fromActno, String toActno, double money) throws MoneyNotEnoughException, TransferException;
}

service层是业务逻辑层,主要是对数据进行逻辑的处理,页面的改变等。这里的逻辑主要就是对余额先进行能否转移的判断,其次是对账户余额的转移改变,最后就是对不同错误的出现返回不同的错误类型

web

//AccountServlet
package com.example.bank.web;import com.example.bank.exceptions.MoneyNotEnoughException;
import com.example.bank.exceptions.TransferException;
import com.example.bank.service.AccountService;
import com.example.bank.service.impl.AccountServiceImpl;import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/transfer")
public class AccountServlet extends HttpServlet {//为了让这个对象在其他方法中也可以用private AccountService accountService = new AccountServiceImpl();@Overrideprotected void doPost(HttpServletRequest request, HttpServletResponse response)throws IOException{//获取表单数据String fromActno = request.getParameter("fromActno");String toActno = request.getParameter("toActno");double money = Double.parseDouble(request.getParameter("money"));try {//调用servlet的转账方法完成转账。(调业务层)accountService.transfer(fromActno,toActno,money);//程序能够走到这里,表示转账一定成功了//调用view完成展示结果response.sendRedirect(request.getContextPath() + "/success.html");} catch (MoneyNotEnoughException e) {response.sendRedirect(request.getContextPath() + "/error1.html");} catch (TransferException e) {response.sendRedirect(request.getContextPath() + "/error2.html");}}
}

展示层,获取表单数据以及针对不同情况错误的出现展示不同的页面信息。

pojo

pojo是封装类,账号的类型里面有的相关数据,一方面能在java中进行数据操作,另一方面对接MySQL的账户信息,方便CRUD。

package com.example.bank.web;import com.example.bank.exceptions.MoneyNotEnoughException;
import com.example.bank.exceptions.TransferException;
import com.example.bank.service.AccountService;
import com.example.bank.service.impl.AccountServiceImpl;import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/transfer")
public class AccountServlet extends HttpServlet {//为了让这个对象在其他方法中也可以用private AccountService accountService = new AccountServiceImpl();@Overrideprotected void doPost(HttpServletRequest request, HttpServletResponse response)throws IOException{//获取表单数据String fromActno = request.getParameter("fromActno");String toActno = request.getParameter("toActno");double money = Double.parseDouble(request.getParameter("money"));try {//调用servlet的转账方法完成转账。(调业务层)accountService.transfer(fromActno,toActno,money);//程序能够走到这里,表示转账一定成功了//调用view完成展示结果response.sendRedirect(request.getContextPath() + "/success.html");} catch (MoneyNotEnoughException e) {response.sendRedirect(request.getContextPath() + "/error1.html");} catch (TransferException e) {response.sendRedirect(request.getContextPath() + "/error2.html");}}
}

Utils

package com.example.bank.utils;import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;import java.io.IOException;public class SqlSessionUtil {private SqlSessionUtil(){}private static SqlSessionFactory sqlSessionFactory;static {try {sqlSessionFactory = new SqlSessionFactoryBuilder().build(Resources.getResourceAsStream("mybatis-config.xml"));} catch (IOException e) {throw new RuntimeException(e);}}public static SqlSession openSession(){return sqlSessionFactory.openSession();}}

写好的工具类,方便在dao层获取sqlsession对象。

银行转账小功能

http://www.hkea.cn/news/904772/

相关文章:

  • 武汉企业网站推广外包网络广告营销案例分析
  • 深圳哪里有做网站的汕头seo排名收费
  • 如何用腾讯云主机做网站株洲发布最新通告
  • 中国建设银行官网站下载信息流广告投放公司
  • 合肥建站平台网络平台推广是干什么
  • 黄冈工程建设标准造价信息网优化工作流程
  • 怎么做服装外贸网站怎么去推广一个产品
  • 和各大网站做视频的工作总结软件推广赚佣金渠道
  • asp.net是做网站的吗企业文化培训
  • 有链接的网站怎么做seochan是什么意思
  • 开发公司 工程管理中存在问题seo人工智能
  • 网站卖给别人后做违法信息seo和点击付费的区别
  • 网站配色 绿色网络推广主要做什么
  • 个人网站制作多少钱公关公司的主要业务
  • 网站底备案号链接代码西安网络推广营销公司
  • 哪个网站开发是按月付费的百度指数是免费的吗
  • asp网站后台管理教程放单平台
  • 做网站毕设任务书网络营销网站建设案例
  • .net 企业网站 模版关键词seo深圳
  • 网站建设优化价格网站seo诊断
  • 网站设计详细设计有没有好用的网站推荐
  • 没有货源可以开网店吗网站更新seo
  • 淄博有做网站的吗百度搜索排名怎么收费
  • wordpress页面添加自定义字段木卢seo教程
  • 长寿网站制作保定seo排名外包
  • 域名和网站一样吗电商运营推广怎么做
  • css个人简介网站怎么做b2b网站免费推广平台
  • 网站建设中企动力上海百度广告投诉电话客服24小时
  • 深圳靠谱的电商公司正版搜索引擎优化
  • 自己如何做团购网站腾讯云建站