映射文件xxxMapper.xml

接口中的每一个方法,都要在映射文件中有与之关联的SQL语句 增删改的返回值默认是int类型,不需要设置resultType,但是select必须要写返回值类型
方法的参数类型可以是基本数据类型、包装类型、对象类型、集合类型
映射文件中的节点:
1.
2.
3.
4.
5.




  • property是type对应类中的属性。column是通过查询得到的列,如果查询出来的列通过as改名了,那么一定要对应
    语句:
    增加:
    insert into user(id,name,password) values(#{uid},#{uname},#{pwd})
更改:
update user set age=#{uage},name=#{uname} where id=#{uid}

删除:
delete from user where id=#{uid}

各种查询:查询resultType是返回值类型,默认情况下返回的是个集合,所以只需要指明集合的类型即可
  • 【映射文件xxxMapper.xml】通过姓名模糊查询

    select id,name,password,gender,address
    from user
    where name like CONCAT(’%’,#{uname},’%’)
    在mapper文件中方法不能重载
    insert into smbms_user(userCode,userName,userPassword) values (#{userCode},#{userName},#{userPassword}) update smbms_user set userCode=#{userCode},userName=#{userName} where id=#{id} delete from smbms_user where id=#{id} select count(id) from smbms_userselect id,userName,userCode from smbms_userselect id,userName,userCode from smbms_user where userName like CONCAT('%',#{name},'%')select id,userName,userCode,gender from smbms_user where userName like CONCAT('%',#{userName},'%') and gender = #{gender}select id,userName,userCode from smbms_user where id = #{id}select id,userName,userCode,gender from smbms_user where userName like CONCAT('%',#{name},'%') and gender = #{g}select id,userName,userCode,gender from smbms_user where userName like CONCAT('%',#{uname},'%') and gender=#{sex} select u.id as uid,userName,userCode,address,userRole,r.roleName from smbms_user u inner join smbms_role r on u.userRole=r.id select u.id,userCode,userName,userRole,r.id as roleId,roleName,roleCode from smbms_user u inner join smbms_role r on u.userRole=r.id select u.id as uid,userName,userCode,a.contact,a.addressDesc from smbms_user u left join smbms_address a on a.userId=u.id where u.id=#{uid}

    推荐阅读