一、简单实现基本业务
1、new一个web project
2、加入必备的jar包(如下图)、配置log4j.properties、db.properties文件
3、数据库,数据表准备
4、创建一个AccountDao接口和其实现类AccountDaoImpl
AccountDao.java
package com.hy.spring.dao;
public interface AccountDao {
void addMoney(Integer id, double money);
void subMoney(Integer id, double money);
}
AccountDaoImpl.java
package com.hy.spring.dao.impl;
import javax.annotation.Resource;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import com.hy.spring.dao.AccountDao;
@Repository("accountDao")
public class AccountDaoImpl implements AccountDao{
@Resource(name="jdbcTemplate")
private JdbcTemplate jtemplate;
@Override
public void addMoney(Integer id, double money) {
String sql = "update account set acccount = acccount + ? where id = ?";
jtemplate.update(sql,money,id);
}
@Override
public void subMoney(Integer id, double money) {
String sql = "update account set acccount = acccount - ? where id = ?";
jtemplate.update(sql,money,id);
}
}
5、创建Service
AccountService.java
package com.hy.spring.service;
public interface AccountService {
public void transfer(Integer from, Integer to, double money);
}
AccountServiceImpl.java
package com.hy.spring.service