public User getUserById(Integer id){ SqlSession sqlSession = sqlSessionFactory.openSession(); User user = (User) sqlSession.selectOne("org.javaboy.mybatis.mapper.UserDao.getUserById", id); sqlSession.close(); return user; }
public Integer addUser(User user){ SqlSession sqlSession = sqlSessionFactory.openSession(); int insert = sqlSession.insert("org.javaboy.mybatis.mapper.UserDao.addUser", user); sqlSession.commit(); sqlSession.close(); return insert; }
public Integer addUser2(User user){ SqlSession sqlSession = sqlSessionFactory.openSession(); int insert = sqlSession.insert("org.javaboy.mybatis.mapper.UserDao.addUser2", user); sqlSession.commit(); sqlSession.close(); return insert; }
public Integer deleteUserById(Integer id){ SqlSession ssqlSession = sqlSessionFactory.openSession(); int desete = sqlSession.delete("com.swpu.htht.mapper.UserDao.deleteUserById",id); sqlSession.commit(); sqlSession.close(); return delete; }
public Integer updateUser(User user){ SqlSession sqlSession = sqlSessionFactory.openSession(); int delete = sqlSession.delete("org.javaboy.mybatis.mapper.UserDao.updateUser", user); sqlSession.commit(); sqlSession.close(); return delete; }
<selectid="getUserById"resultType="org.javaboy.mybatis.model.User"> select * from user where id=#{id}; </select> <insertid="addUser"parameterType="org.javaboy.mybatis.model.User"> insert into user (username,address) values (#{username},#{address}); </insert> <insertid="addUser2"parameterType="org.javaboy.mybatis.model.User"> <selectKeyresultType="java.lang.String"keyProperty="id"order="BEFORE"> select uuid(); </selectKey> insert into user (id,username,address) values (#{id},#{username},#{address}); </insert>
<deleteid="deleteUserById"parameterType="java.lang.Integer"> delete from user where id=#{id} </delete>
<updateid="updateUser"parameterType="org.javaboy.mybatis.model.User"> update user set username = #{username} where id=#{id}; </update>
<selectid="getAllUser"resultType="org.javaboy.mybatis.model.User"> select * from user; </select> </mapper>
<selectid="getUserById"resultType="org.javaboy.mybatis.model.User"> select * from user where id=#{id}; </select> <insertid="addUser"parameterType="org.javaboy.mybatis.model.User"> insert into user (username,address) values (#{username},#{address}); </insert> <insertid="addUser2"parameterType="org.javaboy.mybatis.model.User"> <selectKeyresultType="java.lang.String"keyProperty="id"order="BEFORE"> select uuid(); </selectKey> insert into user (id,username,address) values (#{id},#{username},#{address}); </insert>
<deleteid="deleteUserById"parameterType="java.lang.Integer"> delete from user where id=#{id} </delete>
<updateid="updateUser"parameterType="org.javaboy.mybatis.model.User"> update user set username = #{username} where id=#{id}; </update>
<selectid="getAllUser"resultType="org.javaboy.mybatis.model.User"> select * from user; </select> </mapper>