@Test public void addUser2(){ SqlSession sqlSession = MybatisUtils.getSqlSession(); UserDao mapper = sqlSession.getMapper(UserDao.class); HashMap<String, Object> map = new HashMap<String, Object>(); map.put("userName","zhangsi"); map.put("userSex","boy"); map.put("userAge",10); mapper.addUser2(map); sqlSession.commit(); sqlSession.close(); }
xml:
<insert id="addUser2" parameterType="map"> insert into user (name,sex,age) values (#{userName},#{userSex},#{userAge}) </insert>
@Test public void getUserById2(){ SqlSession sqlSession = MybatisUtils.getSqlSession(); UserDao mapper = sqlSession.getMapper(UserDao.class); Map<String, Object> map = new HashMap<String, Object>(); map.put("id",7); User user = mapper.getUserById2(map); System.out.println(user); sqlSession.close(); }
<select id="getUserById2" parameterType="map" resultType="com.logan.pojo.User"> select * from user where id = #{id} </select>