首页新闻找找看学习计划

后台接口和sql都没题,前台请求空指针异常

0
[待解决问题]

前台代码

var starDate = null;
var endDate = null;
var GradeId=0;
var ClassId=0;
var type=0;

/**
* 点击查询
* @constructor
*/
function ClickStudentCode() {

starDate = $("#datetimepicker").val();
endDate = $("#datetimepicker2").val();
GradeId = $("select[name='Grade_Id']").val();
ClassId = $("select[name='Class_Id']").val();
type = $("select[name='Type_Id']").val();
// StudentName="'"+$("#StudentName").val()+"'";
if (starDate == "") {
starDate = null;
swal("","请添加开始日期!","error");
return
}
if (endDate == "") {
endDate = null;
swal("","请添加结束日期!","error");
return
}
// if (GradeId =='0'||GradeId =='') {
// GradeId = null;
// swal("提示","请选择年级","error");
// return
// }
// if (ClassId == "") {
// ClassId = null;
// swal("提示","请选择班级","error");
// return
// }
// if (type == "") {
// type = null;
// swal("提示","请选择类型","error");
// return
// }
Init(starDate, endDate, GradeId, ClassId, type, 1, 10);
}

 

function Init(StarDate, EndDate, GId, Class_Id, TId, Page, PageSize) {
var data = "<?xml version='1.0' encoding='utf-8'?>";
data += "<soapenv:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:exam='http://example.wisdom.hzf.com'>"
data += "<soapenv:Header/>"
data += "<soapenv:Body>"
data += "<exam:getAbsence_From_DutyInit soapenv:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>"
data += "<Json xsi:type='xsd:string'>{\"cls_Id\":" + Class_Id + ",\"gId\":" + GId + ",\"tId\":" + TId + ",\"StarDate\":" + StarDate + ",\"EndDate\":" + EndDate + ",\"Page\":"+((Page-1)*PageSize)+",\"PageSize\":"+PageSize+"}</Json>"
data += " </exam:getAbsence_From_DutyInit>"
data += "</soapenv:Body>"
data += "</soapenv:Envelope>";
//
$.ajax({
method: "post",
url: "http://192.168.1.200:8082/Attendance/services/AbsenceFromDuty",
data: data,
dataType: "json",
beforeSend: function (xhr) {
xhr.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xhr.setRequestHeader("SOAPAction", "http://www.ip-assistance.pt/WS/GPS/FreeTextGeoCode");
},
success: function (json) {
if(json==null){
swal("没有对应的信息","请重新输入","error");
}
console.log(json);
getAllCondition(json)



// PublicJqPaginator(Page,json.count);
},
error: function () {
console.log('error');
}
})
}后台代码
public String getAbsence_From_DutyInit(String Json) throws ParseException {
JSONObject json = JSONObject.fromObject(Json);
int Class_Id = json.getInt("cls_Id");//班级id
int GId = json.getInt("gId");//年级id
int TId = json.getInt("tId");//类型id
int Page = json.getInt("Page");//页数
int PageSize = json.getInt("PageSize");//每页显示条数
String StarDate = json.getString("StarDate");
String EndDate = json.getString("EndDate");

// SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
// Date sd=sdf.parse(StarDate);
// Date ed=sdf.parse(EndDate);


String Sql = String.format(" select temp.date dates,g.`Name` grade,cls.`Name` class,temp.`name` student," +
"temp.id studentId,IFNULL(a_type.`name`,IFNULL(a_leave.`name`,'未打卡')) states," +
"a_stu_leave.Remark remark, a_time.StartTime start,a_time.EndTime end " +
"from (select date_format(adddate('2017-11-01', INTERVAL num DAY),'%%Y-%%m-%%d') as date, s.id,s.Class_Id,s.name " +
"from num,student s where adddate('2010-01-01', INTERVAL num DAY) <= date_format('2050-12-31','%%Y-%%m-%%d') " +
"order by s.id,date) temp " +
"LEFT JOIN attendance_student_code ac on ac.Stu_id = temp.id and DATE_FORMAT(ac.CodeTime,'%%Y-%%m-%%d') = temp.date " +
"LEFT JOIN attendance_type a_type on a_type.Id = ac.TypeId and a_type.`name` is not NULL " +
"LEFT JOIN attendance_student a_stu on a_stu.Stu_Id = temp.id " +
"LEFT JOIN attendance a on a.Id = a_stu.Attendance_Id " +
"LEFT JOIN attendance_time a_time on a_time.AttendanceId = a.Id " +
"LEFT JOIN attendance_student_leave a_stu_leave on a_stu_leave.Stu_Id = temp.id " +
"and date_format(a_stu_leave.StarDate,'%%Y-%%m-%%d') <= date_format(temp.date,'%%Y-%%m-%%d') " +
"and date_format(a_stu_leave.EndDate,'%%Y-%%m-%%d') >= date_format(temp.date,'%%Y-%%m-%%d') " +
"LEFT JOIN attendance_leave a_leave on a_leave.Id = a_stu_leave.LeaveId " +
"LEFT JOIN class cls ON cls.Id=temp.Class_Id " +
"LEFT JOIN grade g ON g.Id=cls.Grade_Id "
);
//只有类型
if (Class_Id <= 0 && TId > 0 && GId <= 0 && StarDate.length()>0 && EndDate.length()>0) {
Sql += String.format(" where a_leave.Id=%d and a_stu_leave.StarDate='%s' and a_stu_leave.EndDate='%s' ORDER BY DATE ASC limit %d,%d", TId, StarDate, EndDate, (Page - 1) * PageSize, PageSize);
}
//有班级 有年级 没有类型
else if (Class_Id > 0 && TId <= 0 && StarDate.length()>0 && EndDate.length()>0) {
Sql += String.format(" where g.Id=%d and cls.Id=%d and a_stu_leave.StarDate='%s' and a_stu_leave.EndDate='%s' ORDER BY DATE ASC limit %d,%d", GId,Class_Id, StarDate, EndDate, (Page - 1) * PageSize, PageSize);
}
//有年级 有班级 有类型
else if (Class_Id > 0 && TId > 0 && StarDate.length()>0 && EndDate.length()>0) {
Sql += String.format(" where g.Id=%d and cls.Id=%d and a_leave.Id=%d and a_stu_leave.StarDate='%s' and a_stu_leave.EndDate='%s' ORDER BY DATE ASC limit %d,%d", GId,Class_Id, TId, StarDate, EndDate, (Page - 1) * PageSize, PageSize);
}
//有年级 没班级 有类型
else if (Class_Id <= 0 && GId > 0 && TId > 0 && StarDate.length()>0 && EndDate.length()>0) {
Sql += String.format(" where g.Id=%d and a_leave.Id=%d and a_stu_leave.StarDate='%s' and a_stu_leave.EndDate='%s' ORDER BY DATE ASC limit %d,%d", GId, TId, StarDate, EndDate, (Page - 1) * PageSize, PageSize);
}
//有年级 没班级 没类型
else if (Class_Id <= 0 && GId > 0 && TId <= 0 && StarDate.length()>0 && EndDate.length()>0) {
Sql += String.format(" where g.Id=%d and a_stu_leave.StarDate='%s' and a_stu_leave.EndDate='%s' ORDER BY DATE ASC limit %d,%d", GId, StarDate, EndDate, (Page - 1) * PageSize, PageSize);
}
//没有年级 班级 类型
else if (Class_Id <= 0 && GId <= 0 && TId <= 0) {
Sql += String.format(" where temp.id is null");
}
List resultsBySql = commAttendanceDAO.getResultsBySql(Sql);
JSONArray array = new JSONArray();
for (int i = 0; i < resultsBySql.size(); i++) {
Object[] o = (Object[]) resultsBySql.get(i);
JSONObject obj = new JSONObject();
// Date now=sdf.parse(o[0].toString());
// if (sd.before(now)&&now.before(ed)){
obj.put("dates", o[0]);
obj.put("grade", o[1]);
obj.put("cls_Id", o[2]);
obj.put("student", o[3]);
obj.put("studentId", o[4]);
obj.put("states", o[5]);
obj.put("remark", o[6]);
obj.put("start", o[7]);
obj.put("end", o[8]);
array.add(obj);
}
// }
new JSONWI().writeJSONtoApp(array.toString());
return array.toString();

}

}
落霞与孤鹜的主页 落霞与孤鹜 | 菜鸟二级 | 园豆:204
提问于:2017-11-15 18:19
< >
分享
所有回答(2)
0

一场在哪一行。把那一行每一次.都做一次空引用判断.

吴瑞祥 | 园豆:28675 (高人七级) | 2017-11-15 22:32
0

分页写了两次,导致传到后台的page成了-10

落霞与孤鹜 | 园豆:204 (菜鸟二级) | 2017-12-02 11:30
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册