教师端培养方案查询功能
1、.xml文件中的SQL语句
<!-- 教师端:通过专业、学生类型、方案名、年度查询教学方案-->
<select id="selective" parameterType="com.sdu.postgraduate.entity.StudyProject" resultMap="BaseResultMap">
select * from study_project
<trim prefix="where (" suffix=")" suffixOverrides=",">
<if test="dname != null">
dname = #{dname,jdbcType=VERCHAR},
</if>
<if test="studyProjectId != null">
study_project_id = #{studyProjectId,jdbcType=INTEGER},
</if>
<if test="stuType != null">
stu_type = #{stuType,jdbcType=VARCHAR},
</if>
<if test="major != null">
major = #{major,jdbcType=VARCHAR},
</if>
<if test="proName != null">
pro_name = #{proName,jdbcType=VARCHAR},
</if>
<if test="studyTime != null">
study_time = #{studyTime,jdbcType=VARCHAR},
</if>
</trim>
</select>
2、mapper接口中的方法定义
/**
* 教师端:培养方案查询
* @param record
* @return
*/
List<StudyProject> selective(StudyProject record);
3、service层中的方法定义
/**
* 根据一个studyproj对象进行多条件查询
* @param sp
* @return
*/
public List<StudyProject> searchStudyProj(StudyProject sp){
return studyProjectDao.selective(sp);
}
4、controller层业务逻辑
/**
* 培养方案查询:
* 根据一个proj对象进行多条件查询
* @param request
* @return
*/
@RequestMapping("/searchStuProj")
public Result searchStuProj(@RequestBody Map<String, Object> request) {
//专业
String dname = (String) request.get("dname");
//学生类型
String stuType = (String) request.get("stu_type");
//专业类型
String major = (String) request.get("major");
//方案名
String proName = (String) request.get("pro_name");
//年度
String studyTime = (String) request.get("study_time");
StudyProject a = new StudyProject();
if(!dname.equals(""))
a.setDname(dname);
if(!stuType.equals(""))
a.setStuType(stuType);
System.out.println("stutype:"+a.getStuType());
if(!major.equals(""))
a.setMajor(major);
System.out.println("majoy:"+a.getMajor());
if(!proName.equals(""))
a.setProName(proName);
System.out.println("ProName:"+a.getProName());
if(!studyTime.equals(""))
a.setStudyTime(studyTime);
System.out.println("StudyTime:"+a.getStudyTime());
return Result.succ(teacherService.searchStudyProj(a));
}
5、测试接口
post请求body部分
{
"dname":"",
"stu_type": "",
"major": "软件工程",
"pro_name": "",
"study_time": ""
}
获得数据
6、前后端连接
//前端保存查询条件
collectData(){
console.log("info"+this.info.pro_name);
// console.log("cd"+this.dname[0]);
console.log("info"+this.dname_index);
if(this.dname_index==0)
this.info.dname="";
else
this.info.dname=this.dname[this.dname_index];
if(this.stuType_index==0)
this.info.stu_type="";
else
this.info.stu_type=this.stutype[this.stuType_index];
if(this.major_index==0)
this.info.major="";
else
this.info.major=this.major[this.major_index];
if(this.studyTime_index==0)
this.info.study_time="";
else
this.info.study_time=this.year[this.studyTime_index];
// this.info.pro_name=this.pro_name
console.log("请求的数据为"+this.info.dname);
console.log("dname:"+this.info.stu_type);
console.log("stuType:"+this.info.major);
console.log("major:"+this.info.study_time);
console.log("pro_name:"+this.info.pro_name);
}
//发起post请求
this.collectData();
uni.request({
// header: {
// 'Content-Type': 'application/x-www-form-urlencoded'
// },
url: 'http://localhost:8081/teacher/searchStuProj',
method: 'POST',
data: this.info,
dataType:'json',
success: (res) => {
console.log(res.data);
uni.setStorageSync('studyProjectList', res.data.data);
uni.navigateTo({
url:'/pages/teacher/studyProject/list'
})
}
});
7、界面展示