程序框架spring-boot
拼接sql,注意or语句的写法
@Service
public class StudentsMainServiceImpl extends ServiceImpl<StudentsMainDao, StudentsMain> implements StudentsMainService {
@Autowired
StudentsMainDao studentsMainDao;
@Override
public List<Map<String,Object>> matchStudents(Map<String, Object> params) {
String phone = params.get("fdUserCode").toString();
EntityWrapper<StudentsMain> wrapper = new EntityWrapper();
wrapper.setSqlSelect("FD_NO","STUDENT_NAME","NOW_GRADE","FD_ID");
wrapper.like("FATHER_MOBILE", phone).or().like("MOTHER_MOBILE", phone);
List<Map<String,Object>> reList = this.selectMaps(wrapper);
return reList;
}
接口测试返回的结果
{
"msg": "查询成功",
"code": 0,
"data": "[{\"NOW_GRADE\":\"初中三年级 \",\"FD_ID\":\"1\",\"FD_NO\":\"00001\",\"STUDENT_NAME\":\"张晓\"},{\"NOW_GRADE\":\"高中一年级\",\"FD_ID\":\"2\",\"FD_NO\":null,\"STUDENT_NAME\":\"萨克森\"}]"
}
后台打印的sql
但是之前经历了一点我还没有搞明白
@Service
public class StudentsMainServiceImpl extends ServiceImpl<StudentsMainDao, StudentsMain> implements StudentsMainService {
@Autowired
StudentsMainDao studentsMainDao;
@Override
public List<StudentsMain> matchStudents(Map<String, Object> params) {
String phone = params.get("fdUserCode").toString();
EntityWrapper<StudentsMain> wrapper = new EntityWrapper();
wrapper.setSqlSelect("FD_NO","STUDENT_NAME","NOW_GRADE","FD_ID");
wrapper.like("FATHER_MOBILE", phone).or().like("MOTHER_MOBILE", phone);
List<StudentsMain> reList = this.selectList(wrapper);
return reList;
}
}
虽然设置了要返回的字段属性
但是接口测试返回的是:
{
"msg": "查询成功",
"code": 0,
"data": "[{\"fatherName\":\"\",\"fdTeacherChargeId\":\"\",\"fdSex\":\"\",\"fdGrade\":\"\",\"fdRemark\":\"\",\"fdStatus\":0,\"fdCreateTime\":null,\"fdBirthday\":\"\",\"fatherMobile\":\"\",\"fdCustId\":\"\",\"fdCreateId\":\"\",\"fdId\":\"1\",\"fdSchoolidId\":\"\",\"fdPublicClass\":\"\",\"nowGrade\":\"初中三年级\",\"fdPublicSchool\":\"\",\"motherMobile\":\"\",\"motherName\":\"\",\"fdAge\":0,\"fdAlterTime\":null,\"fdNo\":\"00001\",\"informationOrigin\":\"\",\"fdCustMobile\":\"\",\"fdCustName\":\"\",\"studentName\":\"张晓\",\"fdAlterId\":\"\"},{\"fatherName\":\"\",\"fdTeacherChargeId\":\"\",\"fdSex\":\"\",\"fdGrade\":\"\",\"fdRemark\":\"\",\"fdStatus\":0,\"fdCreateTime\":null,\"fdBirthday\":\"\",\"fatherMobile\":\"\",\"fdCustId\":\"\",\"fdCreateId\":\"\",\"fdId\":\"2\",\"fdSchoolidId\":\"\",\"fdPublicClass\":\"\",\"nowGrade\":\"高中一年级\",\"fdPublicSchool\":\"\",\"motherMobile\":\"\",\"motherName\":\"\",\"fdAge\":0,\"fdAlterTime\":null,\"fdNo\":\"\",\"informationOrigin\":\"\",\"fdCustMobile\":\"\",\"fdCustName\":\"\",\"studentName\":\"萨克森\",\"fdAlterId\":\"\"}]"
}
也就是说它把所有字段都返回了,后台打印的sql