mybatis的增删改查
session.commit(); //提交事务,重点!不写的话不会提交到数据库
1 namespace说明
- namespace命名空间作为在mapper中的属性之一,是Mapper接口与xml实现的唯一依据。
2 select
-
UserMapper接口增加方法
//根据id查询用户 UserInf selectUserById(@Param("id")int id);
-
UserMapper.xml增加方法对应映射
<select id="selectUserById" parameterType="int" resultType="com.lyj.entity.UserInf"> select id,name,pwd from user where id = #{ id} </select>
-
测试
@Test public void TsetSelectUserById() { SqlSession session = SqlSessionUtil.getSession(); UserMapper userMapper = session.getMapper(UserMapper.class); UserInf user = userMapper.selectUserById(1); System.out.println(user); session.close();