【Mybatis】多参数传递
来源:互联网 发布:win7系统网络共享设置 编辑:程序博客网 时间:2024/05/20 20:04
1、单个参数
Dao层方法
/** * 根据学号查询所有考试信息 findAllExamByCode * @param code * @return */ List<MyExamModel> findAllExamByCode(String code);
Mapper对应内容
<select id="findAllExamByCode" parameterType="String" resultMap="MyExamModelMap">SELECTexam.course_id AS courseId,exam.starting_date AS startTime ,exam.ending_date AS endTime,room.classroom_id AS roomIdFROMt_examinee ee,t_examination_room_arrangement room,t_examination examWHEREee.examination_room_arrangement_id=room.idANDroom.examination_id=exam.idANDee.student_code=#{code}</select><resultMap id="MyExamModelMap" type="com.dmsdbj.itoo.examinationEvaluation.entity.ext.MyExamModel"><!--property="实体中属性名称(保持一致)",column="查询结果中对应的字段名称(见Select查询结果字段)"--><result property="courseId" column="course_id"/><result property="startTime" column="starting_date"/><result property="endTime" column="ending_date"/><result property="roomId" column="classroom_id"/></resultMap>
2、Map封装多参数
Dao层方法
/** * 根据学号查询本次考试详情 findExamByCode * @param map (time 查询时间,code 学生学号) * @return */ ExamInfoModel findExamByCode(Map map)throws Exception;
Mapper对应内容
<select id="findExamByCode" parameterType="java.util.Map" resultMap="ExamineeExamInfoModelMap"> SELECT ee.id AS examineeId , -- 考生安排ID ee.student_code AS studentCode, -- 考生学号 ee.student_exam_state AS studentExamState, -- 考生考试状态 ee.student_ip AS studentIp,-- 考生IP ee.examination_room_arrangement_id AS examRoomId, -- 考场ID room.examination_room_name AS examRoomName, -- 考场名称 exam.course_id AS courseId, -- 课程ID exam.examination_name AS examName, -- 考试名称 exam.starting_date AS examStartTime, -- 考试开始时间 exam.ending_date AS examEndTime, -- 考试结束时间 exam.examination_type_id AS examTypeId, -- 考试类型ID exam.paper_or_template_id AS paperId, -- 试卷或模板ID tp.is_paper_or_template AS isTemplatePaper -- 是试卷还是模板 FROM t_examination exam, t_examination_room_arrangement room, t_examinee ee, t_template_paper tp WHERE room.examination_id = exam.id AND tp.id = exam.paper_or_template_id AND ee.examination_room_arrangement_id=room.id ANDCAST(#{time} AS TIME)>=CAST(exam.starting_date AS TIME) AND CAST(exam.ending_date AS TIME) >= CAST(#{time} AS TIME) AND exam.is_delete = "0" AND exam.is_calculate = "0" AND ee.is_delete="0" and room.is_delete="0" AND ee.student_code=#{code} ORDER BY exam.starting_date ASC LIMIT 1 </select>
<resultMap id="ExamineeExamInfoModelMap" type="com.dmsdbj.itoo.examinationEvaluation.entity.ext.ExamInfoModel"> <result property="examineeId" column="examineeId"/> <result property="studentCode" column="studentCode"/> <result property="studentExamState" column="studentExamState"/> <result property="studentIp" column="studentIp"/> <result property="examRoomId" column="examRoomId"/> <result property="courseId" column="courseId"/> <result property="examName" column="examName"/> <result property="examStartTime" column="examStartTime"/> <result property="examEndTime" column="examEndTime"/> <result property="examTypeName" column="examTypeId"/> <result property="paperId" column="paperId"/> <result property="isTemplatePaper" column="isTemplatePaper"/> </resultMap>
3、注解传多参数@Param("参数名")
Dao层方法
Mapper对应内容
List<ExamHandleQuestionTypeModel> findTypeById(@Param("id") String id, @Param("code") String code);
4、List封装in(List为具体数据)
Dao层方法
Mapper对应内容
<select id="getXXXBeanList" resultType="XXBean">
select 字段... from XXX where id in
<foreach item="item" index="index" collection="list" open="(" separator="," close=")">
#{item}
</foreach>
</select>
foreach 最后的效果是select 字段... from XXX where id in ('1','2','3','4')
5、索引获得参数值
Dao层方法
Mapper对应内容
IDEA 中是从右向左为索引增加方向
网上有人说myeclipes是从左向右为索引增加方向
6、内部传递多个参数
sql语句套sql语句,在colum中以map形式传参{参数名1=参数值1,参数名2=参数值2,…}
阅读全文
0 0
- mybatis多参数传递
- MyBatis多参数传递
- 【Mybatis】多参数传递
- MyBatis多参数传递
- Mybatis多参数传递
- Mybatis传递多个参数
- Mybatis传递多个参数
- Mybatis传递多个参数
- mybatis多参数传递小结
- MYbatis 多参数传递方式
- mybatis传递多个参数
- mybatis传递多个参数
- Mybatis传递多个参数
- Mybatis传递多个参数
- MyBatis传递多个参数,
- Mybatis传递多个参数
- Mybatis传递多个参数
- MyBatis传递多个参数
- 我的第一篇博客
- java基础 常识
- windows下pip install安装第三方库速度慢问题的解决
- 不能随便输入的“netsh winsock reset”
- API之Byte类型
- 【Mybatis】多参数传递
- 次小生成树
- 关于Java Servlet
- Linux设备驱动之异步通知
- 树莓派3上运行Fuchsia/Magenta OS
- 第二十二讲项目2
- 排序算法
- 面试题59:对称的二叉树
- API之Character类型