Java四十二篇:SSM整合

ssm(spring+springmvc+mybtais)

整合第一步:搭建spring环境

创建项目基本结构(domain层、dao层、service层、controller层)

model:Account.java

@Service("accountService")
public class AccountServiceImpl implements AccountService {
@Resource
private AccountMapper accountMapper;

public void transfer(String origin,String target,Double money) throws Exception{
//1、查询两个账户信息
Account originAccount = accountMapper.findByUserName(origin);//转出账户
System.out.println(originAccount);
Account targetAccount = accountMapper.findByUserName(target);//转入账户
//2、分别设置两个账户的余额
originAccount.setBalance(originAccount.getBalance()-money);
targetAccount.setBalance(targetAccount.getBalance()+money);
//3、调用方法修改数据库表的信息
accountMapper.updateAccount(originAccount);
int i=1/0;
accountMapper.updateAccount(targetAccount);
}
}

至此,ssm整合结束,可以通过对业务层方法异常的注释与否来测试声明式事务是否成功。


本篇文章来源于微信公众号: 小刘Java之路

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/11021.html

(0)
小半的头像小半

相关推荐

发表回复

登录后才能评论
极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!