两个查询在线人员的接口我们可以使用一个接口进行实现,两个接口的区别主要是在于入参不一致,我们可以通过使用mybatis的动态SQL进行实现。
Controller层
@PostMapping("/queryCourseContent")
public List<CourseContentEntity> queryCourseContent(@RequestBody CourseContentEntity courseContent){
return iCourseContentService.queryCourseContent(courseContent);
}
IService层
List<CourseContentEntity> queryCourseContent(CourseContentEntity courseContent);
ServiceImpl层
@Resource
CourseContentMapper courseContentMapper;
@Override
public List<CourseContentEntity> queryCourseContent(CourseContentEntity courseContent) {
return courseContentMapper.queryCourseContentRecord(courseContent);
}
Mapper层
//通用查询语句
List<CourseContentEntity> queryCourseContentRecord(CourseContentEntity courseContentEntity);
Mapper.xml
<select id="queryCourseContentRecord" resultMap="courseContentMap">
SELECT id,course_assembly_id,assembly_content,create_time,created_id,created_by,update_time,updated_id,updated_by
FROM tar_course_content_info
WhERE
is_delete=0
<if test="id != null"> and id = #{id} if>
<if test="courseAssemblyId != null">and course_assembly_id = #{courseAssemblyId}if>
<if test="assemblyContent != null">and assembly_content = #{assemblyContent}if>
<if test="createdBy != null">and created_by = #{createdBy}if>
<if test="updatedBy != null">and updated_by = #{updatedBy}if>
<if test="remark != null">and remark = #{remark}if>
select>
Body中什么都不传,查出来的所有课程
Body中传入参数,查出来的是某个人创建的课程
将course_id和class_id抽出来作为公共数据使用
select id,
user_id,
user_name,
questionnaire_id,
activity_name,
course_id,
class_id,
user_answer,
start_time,
update_time,
remark,
is_delete
from
`arpro_user_answer`
<where>
<choose>
<when test="id !='' and id != null">
and id=#{id}
when>
<when test="user_answer !='' and user_answer != null">
user_answer=#{user_answer}
and course_id = #{course_id}
and class_id = #{class_id}
when>
<when test="questionnaire_id !='' and questionnaire_id != null">
and questionnaire_id=#{questionnaire_id}
and course_id = #{course_id}
and class_id = #{class_id}
when>
<otherwise>
and course_id = #{course_id}
and class_id = #{class_id}
and is_delete = 0
otherwise>
choose>
where>
select>
select id,
user_id,
user_name,
questionnaire_id,
activity_name,
course_id,
class_id,
user_answer,
start_time,
update_time,
remark,
is_delete
from
`arpro_user_answer`
<where>
course_id = #{course_id}
and class_id = #{class_id}
and is_delete = 0
<choose>
<when test="id !='' and id != null">
and id=#{id}
when>
<when test="user_answer !='' and user_answer != null">
user_answer=#{user_answer}
when>
<when test="questionnaire_id !='' and questionnaire_id != null">
and questionnaire_id=#{questionnaire_id}
when>
choose>
where>
select>
在软件设计的时候要从全局观出发,要考虑到前端使用哪些组件,后端使用哪些接口,以及后端需要的接口是有可以复用的。在进行软件设计时,我们也要想是面向对象的设计还是面向过程的设计。如果是面向对象的设计,那么就需要考虑可复用、可扩展、可维护。