首页 > 其他 > 详细

在Mybatis中使用注解@多个参数查询

时间:2014-08-21 00:12:43      阅读:981      评论:0      收藏:0      [点我收藏+]
    @Select("SELECT * FROM wc_homework WHERE organization_id=#{classId} ORDER BY createtime DESC LIMIT #{start},#{count}")
    @Results({
            @Result(column = "course_id", property = "course_id"),
            @Result(column = "homework_id", property = "homework_id"),
            @Result(column = "organization_id", property = "organization_id"),
            @Result(property = "course", column = "course_id", one = @One(select = "selectCourse")),
            @Result(property = "viewTotalNum", column = "organization_id", one = @One(select = "SelectStudentCount")),
            @Result(property = "attachments", javaType = List.class, column = "homework_id", many = @Many(select = "selectAttachments")),
            @Result(property = "viewNum",column = "{homework_id = homework_id,organization_id = organization_id}",one = @One(select = "selectViewCounts")),
            @Result(property = "feedbackNum",column = "{homework_id = homework_id,organization_id = organization_id}",one = @One(select = "selectFeedbackCounts"))
    })

    List<HomeworkExt> selectByClassId(@Param("classId") Long classId, @Param("start") int start, @Param("count") int count);

上面的 @Result(property = "feedbackNum",column = "{homework_id = homework_id,organization_id = organization_id}",one = @One(select = "selectFeedbackCounts"))

最后一行,通过传入两个参数查询:对应下面的Map键值对。

 @Select("SELECT COUNT(DISTINCT f.user_id)  FROM wc_homework_log_see ws INNER JOIN \n" +
            "(SELECT wu.user_id, wf.`family_user_id` FROM wc_organization_user wu INNER JOIN wc_family wf ON wu.`user_id` = wf.`student_id` \n" +
            "WHERE wu.`organization_id` = #{organization_id} AND wu.`role_id` = 4) f ON f.family_user_id = ws.`user_id` \n" +
            "WHERE ws.`homework_id` = #{homework_id}")
    int selectViewCounts(Map<String,Object> map);

在Mybatis中使用注解@多个参数查询,布布扣,bubuko.com

在Mybatis中使用注解@多个参数查询

原文:http://blog.csdn.net/ginkgo_leaf/article/details/38716347

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!