典型的查询语句
2015-06-26 16:40
330 查看
1.多个关联
2.条件查询
3.更新
<!--老师个人中心需要的信息 wuyiwen --> <select id="getActivitiesByTeacherId" resultMap="resultListTeachers"> select ac.id as acid,ac.maxNum as acmaxNum, aa.id as aaid,aa.name as aaname, aa.publishUser,aa.startDate as aastartDate,aa.endDate as aaendDate, aa.courseStartDate,aa.courseEndDate,aa.admissions,aa.warning as aawarning, aa.status,c.name as cname,c.type as ctype,c.id as cid,t.name as tname , t.id as tId,act.hour as actHour,act.startTime as actStartTime,act.endTime as actEndTime, count(sc.id) as count from aa_activitycourse ac left join bd_course c on ac.id_course = c.id left join aa_activitycourseteacher acte on ac.id = acte.id_activitycourse left join bd_teacher t on t.id = acte.id_teacher left join aa_applyactivity aa on aa.id=ac.id_applyactivity left join aa_activitycoursetime act on act.id_activitycourse=ac.id left join aa_studentcourse sc on ac.id = sc.id_activitycourse where t.id = #{teacherId} <if test="activeName != null and activeName != '' "> and aa.name like CONCAT('%',#{activeName},'%') </if> <if test="courseName != null and courseName != '' "> and c.name like CONCAT('%',#{courseName},'%') </if> GROUP BY sc.id_activitycourse,sc.id_applyactivity order by aa.endDate </select>
<!--老师个人的活动课程 --> <resultMap type="ActivityCourse" id="resultListTeachers"> <id column="acid" property="id" /> <result column="acmaxNum" property="maxNum"/> <result column="count" property="courseReportCount"/> <association property="applyActivity" javaType="ApplyActivity"> <id column="aaid" property="id" /> <result column="aaname" property="name"/> <result column="publishUser" property="publishUser"/> <result column="aastartDate" property="startDate" /> <result column="aaendDate" property="endDate" /> <result column="admissions" property="admissions" /> <result column="aawarning" property="warning" /> <result column="courseStartDate" property="courseStartDate" /> <result column="courseEndDate" property="courseEndDate" /> <result column="status" property="status" /> </association> <association property="course" javaType="Course"> <id column="cid" property="id" /> <result column="cname" property="name"/> <result column="ctype" property="type"/> </association> <collection property="activityCourseTeachers" ofType="ActivityCourseTeacher"> <id column="actId" property="id" /> <association property="teacher" javaType="Teacher"> <id column="tId" property="id" /> <result column="tname" property="name" /> </association> </collection> <collection property="activityCourseTimes" ofType="ActivityCourseTime"> <id column="timeId" property="id" /> <result column="actStartTime" property="startTime"/> <result column="actHour" property="hour"/> <result column="actEndTime" property="endTime"/> <result column="place" property="place"/> </collection> </resultMap>
2.条件查询
<select id="getPage" resultMap="resultListStudent" parameterType="page"> select stu.id id,stu.name name,stu.sex sex,stu.birthDate birthDate, stu.address address,stu.identityCard identityCard,stu.email email, stu.parentPhone1 parentPhone1,stu.parentPhone2 parentPhone2, stu.ft ft, sch.id as id_school,sch.name as schoolName, are.id as areaId ,are.name as areaName from bd_student stu left join bd_school sch on stu.id_school=sch.id left join bd_area are on sch.id_area=are.id left join bd_user us on us.id=stu.id where 1=1 and us.status=1 <if test="params.name != null and params.name != '' "> and stu.name like CONCAT('%',#{params.name},'%') </if> <if test="params.sex != null and params.sex != '' "> and stu.sex=#{params.sex} </if> <if test="params.birthDate != null and params.birthDate != '' "> and stu.birthDate=#{params.birthDate} </if> <if test="params.address != null and params.address != '' "> and stu.address=#{params.address} </if> <if test="params.identityCard != null and params.identityCard != '' "> and stu.identityCard like CONCAT('%',#{params.identityCard},'%') </if> <if test="params.email != null and params.email != '' "> and stu.email=#{params.email} </if> <if test="params.parentPhone1 != null and params.parentPhone1 != '' "> and stu.parentPhone1=#{params.parentPhone1} </if> <if test="params.parentPhone2 != null and params.parentPhone2 != '' "> and stu.parentPhone2=#{params.parentPhone2} </if> <if test="params.schoolId != null and params.schoolId != '' "> and stu.id_school=#{params.schoolId} </if> <if test="params.areaId != null and params.areaId != ''"> and sch.id_area=#{params.areaId} </if> order by stu.id desc </select>
3.更新
<!--只对非空字段进行更新 --> <update id="update" parameterType="Student"> update bd_student <set> <if test="name != null and name != '' "> name=#{name}, </if> <if test="sex != null and sex != '' "> sex=#{sex}, </if> <if test="birthDate != null and birthDate != '' "> birthDate=#{birthDate}, </if> <if test="address != null and address != '' "> address=#{address}, </if> <if test="identityCard != null and identityCard != '' "> identityCard=#{identityCard}, </if> <if test="email != null and email != '' "> email=#{email}, </if> <if test="email != null and email == '' "> email=#{email}, </if> <if test="parentPhone1 != null and parentPhone1 != '' "> parentPhone1=#{parentPhone1}, </if> <if test="parentPhone2 != null and parentPhone2 != '' "> parentPhone2=#{parentPhone2}, </if> <if test="parentPhone2 != null and parentPhone2 == '' "> parentPhone2=#{parentPhone2}, </if> <if test="school!=null and school.id != null and school.id != '' "> id_school=#{school.id}, </if> </set> WHERE id=#{id} </update>
相关文章推荐
- php 快速排序
- [Selenium] Explicit wait 方法
- console.debug()浏览器控制台打印输出 只在支持console的浏览器下打印
- OpenStack Juno系列之L3 HA agent and VRRP 推荐
- 【Hadoop权威指南】Hadoop分布式文件系统(第三天)
- 接口调用-http和https
- opencv学习笔记(五)
- Linux学习笔记(四)——Linux档案权限
- 第一条登录CSDN,写下第一条博文!
- ffmpeg解码数据转为Mat通过opencv函数显示
- linux系统日志函数syslog,openlog,closelog函数
- Spring4新特性——泛型限定式依赖注入
- springMVC 返回类型选择 以及 SpringMVC中model,modelMap.request,session取值顺序
- json与jsonp应用及其他ajax数据交互方式
- MyEclipse 2014中Customize Persperctive设置无效的解决方法
- java反射
- maven 之 build lifecycle
- 数据结构之图:图的存储结构和遍历
- Linux下vsftp的安装及配置
- 拨开迷雾,近距离见识CloudStack的物理网络架构