mybati-splus的EntityWrapper拼接sql並按照設置的column返回對應的字段

程序框架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

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章