mapper.xml中返回值类型
因为两次都错在这个上面上,所以还是记录一下。。。。resultType是直接表示返回类型的,比如Integer,String, List<Integer>也是一样,resultMap则是对外部ResultMap的引用例如:<select id="selectByStatus" resultType="java.lang.Integer" parameterType="com.me
因为两次都错在这个上面上,所以还是记录一下。。。。
resultType是直接表示返回类型的,比如Integer,String, List<Integer>也是一样,resultMap则是对外部ResultMap的引用
例如:
<select id="selectByStatus" resultType="java.lang.Integer" parameterType="com.meihui.learning.viewmodel.admin.question.QuestionStatusVM">
SELECT
t_question.id
FROM t_question LEFT JOIN t_question_status on t_question_status.question_id = t_question.id
<where>
and t_question.deleted = 0
<if test="questionType != null">
and t_question.question_type = #{questionType}
</if>
<if test="wrongStatus != null ">
and t_question_status.wrong_status= #{wrongStatus}
</if>
<if test="subjectSecondId != null ">
and t_question.subject_second_id= #{subjectSecondId}
</if>
<if test="subjectId != null ">
and t_question.subject_id= #{subjectId}
</if>
</where>
</select>
<select id="getUserDingTaskByDdUserIdDeptId" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_user_ding_task
where dd_user_id = #{ddUserId} and dept_id = #{deptId} and deleted = 0 limit 1
</select>
还有一种略特殊的,其实也不算特殊,之前没理解清楚,下面并没有引用外部的,所以用resultType是正常的。。 <include refid="Base_Column_List"/>这种才是外部引用。。。
<select id="selectCountByDate" resultType="com.meihui.learning.domain.other.KeyValue">
SELECT create_time as name,COUNT(create_time) as value from
(
SELECT DATE_FORMAT(create_time,'%Y-%m-%d') as create_time from
t_user_event_log
WHERE create_time between #{startTime} and #{endTime}
) a
GROUP BY create_time
</select>
List<KeyValue> selectCountByDate(@Param("startTime") Date startTime, @Param("endTime") Date endTime);
https://blog.csdn.net/woshixuye/article/details/27521071 这位很详细
还有就是关于传递参数为list的时候的一个小问题。。
默认的list,亲测可行
List<UserDTO> selectByDdUserIds(List<String> list);
<select id="selectByDdUserIds" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from t_user_ding
where id in
<foreach item="ddUserId" collection="list" open="(" separator=","
close=")">
#{ddUserId}
</foreach>
</select>
这里的collection为list,所以上面的代码里不用传@Param("list")之类的
但是如果是自定义的,就得加上@Param("ddUserIds")之类的。。
List<UserDTO> selectByDdUserIds(@Param("ddIdList") List<String> ddIdList);
<select id="selectByDdUserIds" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from t_user_ding
where id in
<foreach item="ddUserId" collection="ddIdList" open="(" separator=","
close=")">
#{ddUserId}
</foreach>
</select>
但其实我代码里这么写还是报错 。。。清过redis缓存,clean也clean过了。。就是报错。。。但是其他的xml里的也是这写法就可以,应该还是哪里出问题了。。
https://blog.csdn.net/qq_28379809/article/details/83342196 这位也很详细。。
更多推荐
所有评论(0)