• spring 事务


    首先建两个实体类:

    Account  持股票

    Stock  股票

    实现这两个接口

    public class StockImpl extends JdbcDaoSupport implements StockDao {
        public int addstock(Stock stock) {
            String sql="insert into stock(sname,counts) values(?,?)";
            int stouccount = getJdbcTemplate().update(sql, stock.getStockname(), stock.getStockmoney());
            return stouccount;
        }
    
        public int updatestock(int sid, int stockmoney, boolean isMoreOrLess) {
           String sql="";
           if(isMoreOrLess){
               //ture   销售股票
              sql="update stock set counts=counts-? where sid=?";
           }else {
    
               sql="update stock set counts=counts+? where sid=?";
           }
            int count = getJdbcTemplate().update(sql,stockmoney,sid);
            return count;
        }
        public void setJdbcTemplate2(JdbcTemplate jdbcTemplate) {
            super.setJdbcTemplate(jdbcTemplate);
        }
    }
    public class AccountImpl extends JdbcDaoSupport implements AccountDao {
        public int Addcount(Account account) {
           String sql="insert into account(aname,balance) values(?,?)";
            int count = getJdbcTemplate().update(sql, account.getAccountname(), account.getAccountyu());
            return count;
        }
        public int updateAccount(int add, int accountyu, boolean isMoreOrLess) {
         String sql="";
         if(isMoreOrLess){
             //余额增加    销售股票
             sql="update account set balance=balance+? where aid=?";
    
         }else{
             sql="update account set balance=balance-? where aid=?";
         }
         int count=getJdbcTemplate().update(sql,accountyu,add);
            return count;
        }
        public void setJdbcTemplate2(JdbcTemplate jdbcTemplate) {
            super.setJdbcTemplate(jdbcTemplate);
        }
    
    }

    service接口

    public interface IAccountService {
        public int Addcount(Account account);
    
        public int addstock(Stock stock);
    
        public int update(int aid,int money,int sid,int stockmoney);
    }

    实现service

    public class StockImpl extends JdbcDaoSupport implements StockDao {
        public int addstock(Stock stock) {
            String sql="insert into stock(sname,counts) values(?,?)";
            int stouccount = getJdbcTemplate().update(sql, stock.getStockname(), stock.getStockmoney());
            return stouccount;
        }
    
        public int updatestock(int sid, int stockmoney, boolean isMoreOrLess) {
           String sql="";
           if(isMoreOrLess){
               //ture   销售股票
              sql="update stock set counts=counts-? where sid=?";
           }else {
    
               sql="update stock set counts=counts+? where sid=?";
           }
            int count = getJdbcTemplate().update(sql,stockmoney,sid);
            return count;
        }
        public void setJdbcTemplate2(JdbcTemplate jdbcTemplate) {
            super.setJdbcTemplate(jdbcTemplate);
        }
    }
    public class AccountImpl extends JdbcDaoSupport implements AccountDao {
        public int Addcount(Account account) {
           String sql="insert into account(aname,balance) values(?,?)";
            int count = getJdbcTemplate().update(sql, account.getAccountname(), account.getAccountyu());
            return count;
        }
    
        public int updateAccount(int add, int accountyu, boolean isMoreOrLess) {
         String sql="";
         if(isMoreOrLess){
             //余额增加    销售股票
             sql="update account set balance=balance+? where aid=?";
    
         }else{
             sql="update account set balance=balance-? where aid=?";
         }
         int count=getJdbcTemplate().update(sql,accountyu,add);
            return count;
        }
        public void setJdbcTemplate2(JdbcTemplate jdbcTemplate) {
            super.setJdbcTemplate(jdbcTemplate);
        }
    
    }
  • 相关阅读:
    并发编程之线程进阶
    并发编程之线程
    进程间通信(队列和管道)
    在python程序中的进程操作
    操作系统之进程
    网络编程之黏包
    树莓派 websocket 控制LED
    lua 调用 C -- 实例 C函数作为应用程序的一部分
    linux 环境下进程什么时候会被 killed掉
    STM32 + cJSON 死机问题解决
  • 原文地址:https://www.cnblogs.com/xiaoyu1997/p/6672148.html
Copyright © 2020-2023  润新知