zoukankan      html  css  js  c++  java
  • 在Mybatis中使用注解@多个參数查询

        @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 " +
                "(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` " +
                "WHERE wu.`organization_id` = #{organization_id} AND wu.`role_id` = 4) f ON f.family_user_id = ws.`user_id` " +
                "WHERE ws.`homework_id` = #{homework_id}")
        int selectViewCounts(Map<String,Object> map);

  • 相关阅读:
    洛谷P3178 [HAOI2015]树上操作 题解 树链剖分+线段树
    洛谷P2590 [ZJOI2008]树的统计 题解 树链剖分+线段树
    2017年NOIP普及组复赛题解
    洛谷P3957 跳房子 题解 二分答案/DP/RMQ
    2016年NOIP普及组复赛题解
    2015年NOIP普及组复赛题解
    2014年NOIP普及组复赛题解
    洛谷P2258 子矩阵 题解 状态压缩/枚举/动态规划
    2013年NOIP普及组复赛题解
    第四章 选择结构(二)
  • 原文地址:https://www.cnblogs.com/zfyouxi/p/4242554.html
Copyright © 2011-2022 走看看