编写properties文件
jdbc.driverClass = com.mysql.jdbc.Driver
jdbc.jdbcUrl = jdbc:mysql://localhost:3306/spring
jdbc.user = root
jdbc.password = 123456
dao层编写
package com.dao;
/**
- @author zzy
/
public interface AccountDao {
/
汇款
/
public void out(String outUser,int money);
/
收款
*/
public void in(String inUser,int money);
}
package com.xf.dao.impl;
import com.xf.dao.AccountDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
/**
-
@author zzy
*/
public class AccountDaoImpl implements AccountDao {
@Autowired
private JdbcTemplate jdbcTemplate;
public void setJdbcTemplate(JdbcTemplate jdbcTemplate){
this.jdbcTemplate=jdbcTemplate;
}
@Override
public void out(String outUser, int money) {
this.jdbcTemplate.update(“update account set money =money-?”
+ “where username =?”,money,outUser);
}@Override
public void in(String inUser, int money) {
this.jdbcTemplate.update(“update account set money =money+?”
+“where username=?”,money,inUser);
}
}
service层编写
package com.service;
public interface AccountService {