1.mapper.xml文件的sql语句书写
(1)mapper文件基本格式
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.school.employee.mapper.GoodsMapper">
<!-- 根据proceedId查询该物品领用单明细 -->
<select id="getGoodsProStatusById" parameterType="string" resultType="string">
SELECT
status
FROM
sm_goods_proceed
WHERE
id = #{proceedId}
</select>
</mapper>
(2)传参方式
参数传递一般有三种方式:
1. Map
将参数的存入Map中
2. @Param("paramName")
在dao层方法参数前加上此注解
3. 使用javaBean
参数为javaBean时,对应的参数字段名是JavaBean的属性名
(3)结果的返回
1. Map
当查询结果较少时,使用Map返回。其中key为对应数据库的列名,value为查询的结果。
2. 集合的嵌套查询和嵌套结果
<resultMap type="com.school.employee.bean.LearnCommentBean" id="learnCommentMap">
<result property="labelId" column="id"/>
<result property="labelName" column="label_name"/>
<result property="typeId" column="type_id"/>
<result property="learnRecordId" column="learn_record_id"/>
</resultMap>
<resultMap type="com.school.employee.bean.LearnCommentPageBean" id="learnCommentPageMap">
<result property="subjectType" column="subject_type"/>
<result property="itemName" column="name"/>
<result property="startTime" column="start_time"/>
<result property="endTime" column="end_time"/>
<result property="photoUrl" column="photo_url"/>
<!-- 集合的嵌套结果 -->
<collection property="learnComments" javaType="ArrayList"
ofType="com.school.employee.bean.LearnCommentBean" resultMap="learnCommentMap" />
</resultMap>