黑马程序员--用户注册登录管理系统…
2015-12-24 10:25
423 查看
--------android培训java培训期待与您交流------
package cn.itcast.dao.impl;
import java.util.List;
import
org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper;
import
org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import org.springframework.stereotype.Repository;
import
org.springframework.transaction.annotation.Propagation;
import
org.springframework.transaction.annotation.Transactional;
import cn.itcast.dao.UserDao;
import cn.itcast.domain.User;
import cn.itcast.util.JdbcUtils;
@SuppressWarnings("deprecation")
@Repository
public class UserDaoSpringImpl implements UserDao
{ @Autowired private SimpleJdbcTemplate
simpleJdbcTemplate; @Override @Transactional(propagation =
Propagation.REQUIRED) public boolean add(User user) { String sql = "insert into
user(username,password,email,birthday,nickname)
values(?,?,?,?,?)"; Object[] args = new Object[] {
user.getUsername(), user.getPassword(), user.getEmail(),
user.getBirthday(), user.getNickname() }; return
simpleJdbcTemplate.update(sql, args) == 1 ? true : false; }
@Override @Transactional(propagation =
Propagation.NOT_SUPPORTED) public User find(String username, String
password) { String sql = "select
username,password,email,birthday,nickname from user where
username=? and password=?"; Object[] args = new Object[] {
username, password }; List<User>
users = simpleJdbcTemplate.query(sql, ParameterizedBeanPropertyRowMapper.newInstance(User.class), args);
//如果这个集合中是空,说明没找到则返回null; return users.isEmpty() ? null :
users.get(0); }
DAO层由Spring的SimpleJdbcTemplate接管,其中用到了基于注解方式的声明式事务管理和基于注解方式实现的bean装配与依赖注入;
开发完DAO层后,测试通过,然后抽取接口UserDao;
转发至微博
转发至微博
package cn.itcast.dao.impl;
import java.util.List;
import
org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper;
import
org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import org.springframework.stereotype.Repository;
import
org.springframework.transaction.annotation.Propagation;
import
org.springframework.transaction.annotation.Transactional;
import cn.itcast.dao.UserDao;
import cn.itcast.domain.User;
import cn.itcast.util.JdbcUtils;
@SuppressWarnings("deprecation")
@Repository
public class UserDaoSpringImpl implements UserDao
{ @Autowired private SimpleJdbcTemplate
simpleJdbcTemplate; @Override @Transactional(propagation =
Propagation.REQUIRED) public boolean add(User user) { String sql = "insert into
user(username,password,email,birthday,nickname)
values(?,?,?,?,?)"; Object[] args = new Object[] {
user.getUsername(), user.getPassword(), user.getEmail(),
user.getBirthday(), user.getNickname() }; return
simpleJdbcTemplate.update(sql, args) == 1 ? true : false; }
@Override @Transactional(propagation =
Propagation.NOT_SUPPORTED) public User find(String username, String
password) { String sql = "select
username,password,email,birthday,nickname from user where
username=? and password=?"; Object[] args = new Object[] {
username, password }; List<User>
users = simpleJdbcTemplate.query(sql, ParameterizedBeanPropertyRowMapper.newInstance(User.class), args);
//如果这个集合中是空,说明没找到则返回null; return users.isEmpty() ? null :
users.get(0); }
DAO层由Spring的SimpleJdbcTemplate接管,其中用到了基于注解方式的声明式事务管理和基于注解方式实现的bean装配与依赖注入;
开发完DAO层后,测试通过,然后抽取接口UserDao;
转发至微博
转发至微博
相关文章推荐
- 黑马程序员--用户注册管理系统(Sp…
- 黑马程序员--用户注册登录管理系统…
- 黑马程序员--JAVA中23种设计模式(-…
- [JAVA面试算法] 用代码体现“水仙花数”
- StackOverflow程序员推荐:每个程序员都应读的30本书
- 一道面试题引发的对android中context的研究(二)
- 一道面试题引发的对android中context的研究(一)-SharedPreference是否可以将文件保存在SD卡上
- 看顶级高手如何编程--从带程序员新手想到的
- 从测试角度看职业生涯
- 程序员自学需要具备的基本技能和素质
- Android之常见面试题
- c#面试题
- c#面试题
- 数据分析师常见的十道面试题目
- Android面试中常见问题集锦
- 脚踏实地 志存高远——我的码农之路
- 前端面试题目搜集——理论知识篇
- 代码整洁之道读后感——代码是程序员的情书
- 码农必备技能:烂代码的处理之道
- Java面试题