cache 给命名空间的缓存配置
cache-ref 其他命名空间缓存配置的引用
resultMap 描述如何从数据库结果集中来加载对象
<!--column不做限制,可以为任意表的字段,而property须为type 定义的pojo属性--> <resultMap id="唯一的标识" type="映射的pojo对象"> <id column="表的主键字段,或者可以为查询语句中的别名字段" jdbcType="字段类型" property="映射pojo对象的主键属性" /> <result column="表的一个字段(可以为任意表的一个字段)" jdbcType="字段类型" property="映射到pojo对象的一个属性(须为type定义的pojo对象中的一个属性)"/> <association property="pojo的一个对象属性" javaType="pojo关联的pojo对象"> <id column="关联pojo对象对应表的主键字段" jdbcType="字段类型" property="关联pojo对象的主席属性"/> <result column="任意表的字段" jdbcType="字段类型" property="关联pojo对象的属性"/> </association> <!-- 集合中的property须为oftype定义的pojo对象的属性--> <collection property="pojo的集合属性" ofType="集合中的pojo对象"> <id column="集合中pojo对象对应的表的主键字段" jdbcType="字段类型" property="集合中pojo对象的主键属性" /> <result column="可以为任意表的字段" jdbcType="字段类型" property="集合中的pojo对象的属性" /> </collection> </resultMap>
sql 可被其他语句引用的可重用语句块
sql id="sqlid"> res_type_id,res_type </sql> <select id="selectbyId" resultType="com.property.vo.PubResTypeVO"> select <include refid="sqlid"/> from pub_res_type </select>
insert 映射插入语句
<insert id="upateUserById" parameterType="User" >
insert into user (name,age) values (#{name},#{age})
</insert>
update 映射更新语句
<updateid="upateUserById" parameterType="User" > update user set username=#{username},age=#{age} where id=#{id} </update>
delete 映射删除语句
<delete id="delUserById" parameterType="int" > delete from user where id=#{id} </delete>
select 映射查询语句
<select id="getUserById" parameterType="int" resultType="User"> //或使用resultMap resultType 用类的全名称 或别名 select * from user where id=#{id} </select>
自动映射
前提 SQL 列名 和 javebean 的属性是一致的
自动映射的等级autoMappingBehavior 设置为PARTIAL ,谨慎使用FULL
使用resultType
如果列名和 JavaBean 不一致,但列名符合单词下划线分隔时,java是驼峰命名法 则mapUnderscoreToCase可设置为true