把上一篇代码https://blog.csdn.net/GLOAL_COOK/article/details/112604622复制一份,基本原理都差不多,只不过把applicationContext.xml的部分内容搬到具体的类中
(在AccountServiceImpl有体现)
整体结构和上一篇博客一模一样
pom.xml没变,只贴和上一篇不一样的代码
AccountDaoImpl:
package com.itheima.dao.impl;
import com.itheima.dao.AccountDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
@Repository("accountDao")
public class AccountDaoImpl implements AccountDao {
@Autowired
private JdbcTemplate jdbcTemplate; //用注解就不用set方法了
public void out(String outMan, double money) {
jdbcTemplate.update("update account set money=money-? where name=?",money,outMan);
}
public void in(String inMan, double money) {
jdbcTemplate.update("update account set money=money+? where name=?"