??????????????????
1packagecn.mrf.mybatis.dao;
2
3importjava.util.List;
4
5importorg.apache.ibatis.session.SqlSession;
6importorg.apache.ibatis.session.SqlSessionFactory;
7
8importcn.mrf.mybatis.po.User;
9/**
10*
11*@ClassName:UserDaoImpl
12*@Description:????????
13*@authormrf
14*@date2015-9-19????05:57:03
15*
16*/
17publicclassUserDaoImplimplementsUserDao{
18
19//?????dao??????????SqlSessionFactory
20//????????????????
21privateSqlSessionFactorysqlSessionFactory;
22
23publicUserDaoImpl(SqlSessionFactorysqlSessionFactory){
24this.sqlSessionFactory=sqlSessionFactory;
25}
26
27
28@Override
29publicUserfindUserById(intid)throwsException{
30//sqlSession??????????????????????
31SqlSessionsqlSession=sqlSessionFactory.openSession();
32
33Useruser=sqlSession.selectOne("test.findUserById"??id);
34
35//??????
36sqlSession.close();
37returnuser;
38}
39
40@Override
41publicList<User>findUserByName(Stringname)throwsException{
42SqlSessionsqlSession=sqlSessionFactory.openSession();
43
44List<User>list=sqlSession.selectList("test.findUserByName"??name);
45
46//??????
47returnlist;
48}
49
50@Override
51publicvoidinsertUser(Useruser)throwsException{
52SqlSessionsqlSession=sqlSessionFactory.openSession();
53//??в???
54sqlSession.insert("test.insertUser"??user);
55
56//??????
57sqlSession.commit();
58//??????
59sqlSession.close();
60
61
62}
63
64@Override
65publicvoiddeleteUser(intid)throwsException{
66SqlSessionsqlSession=sqlSessionFactory.openSession();
67
68//??в??????
69sqlSession.delete("test.deleteUser"??id);
70
71//??????
72sqlSession.commit();
73
74//??????
75sqlSession.close();
76}
77
78}