当前位置: 首页 > 工具软件 > Ajax Submit > 使用案例 >

$.post()和 $.ajax()以及$.ajaxSubmit(options)的用法及整理

融泓
2023-12-01
jQuery.post( url, [data], [callback], [type] ) :使用POST方式来进行异步请求

参数:

url (String) : 发送请求的URL地址.

data (Map) : (可选) 要发送给服务器的数据,以 Key/value 的键值对形式表示。

callback (Function) : (可选) 载入成功时回调函数(只有当Response的返回状态是success才是调用该方法)。

type (String) : (可选)官方的说明是:Type of data to be sent。其实应该为客户端请求的类型(JSON,XML,等等)

这是一个简单的 POST 请求功能以取代复杂 $.ajax 。请求成功时可调用回调函数。如果需要在出错时执行函数,请使用 $.ajax。示例代码:

 

<#import "/common/htmlcomponent.ftl" as hc>
<@hc.moduleDiv titleName="">
<script type="text/javascript" src="${request.contextPath}/static/js/myscript.js"></script>
<script>
  function goBack(){
     var url = "${request.contextPath}/practice/info/trackAdmin.action?searchAcadyear=${searchAcadyear!}&searchClsId=${searchClsId!}";
	load("#container",url);
  }
  
  function addTr(){
	var trackDates = document.getElementsByName("trackDate");
  	if(trackDates.length > 10){
  		showMsgWarn("个人发展情况最多不能超过10个");
  		return;
  	}
	$($('#copyTr tr').clone(false)).appendTo('#devTable');
	doFalsh();
  }
  
  function doFalsh(){
  	$(".delTr").unbind("click").click(function(e){
  		if(confirm("确定删除该记录吗?")){
  			var thisId = $(this).attr("id");
	  		var index = $(this).parents("tr").index();
	  		var index1 = $(this).parents("tr").index()+1;
	  		var index2 = $(this).parents("tr").index()+2;
	  		var index3 = $(this).parents("tr").index()+3;
	  		if(thisId != null && thisId != ''){
	  			$.ajax({
					type: "POST",
					url: "${request.contextPath}/practice/info/trackAdmin-trackDelete.action",
					data: {practiceTrackId:thisId},
					success: function(data){
						if(data!=null){
							showMsgError(data);
						}else{
							showMsgSuccess("删除个人发展情况成功");
					  		$("#devTable tr:eq("+index3+")").remove();
					  		$("#devTable tr:eq("+index2+")").remove();
					  		$("#devTable tr:eq("+index1+")").remove();
					  		$("#devTable tr:eq("+index+")").remove();
							return;
						}
					},
					dataType: "json",
					error: function(XMLHttpRequest, textStatus, errorThrown){alert(XMLHttpRequest.status);}
				});
	  		}else{
		  		$("#devTable tr:eq("+index3+")").remove();
		  		$("#devTable tr:eq("+index2+")").remove();
		  		$("#devTable tr:eq("+index1+")").remove();
		  		$("#devTable tr:eq("+index+")").remove();
	  		}	
  		}
  	});
  }
  
  var isSubmit = false;
  function doSave(){
  	if(isSubmit){
  		return;
  	}
  	var trackDates = document.getElementsByName("trackDate");
  	if(trackDates.length < 2){
  		showMsgWarn("未维护个人发展情况");
  		return;
  	}
  	var flag = false;
  	for(var i = 0; i < trackDates.length-1;i++) {
  		if(trackDates[i].value == null || trackDates[i].value == '' ){
  			flag = true;
  			break;
  		}
  	}
  	if(flag){
  		showMsgWarn("跟踪日期不能为空!");
  		return;
  	}
	showSaveTip();
	isSubmit = true;
	var options = {
	       url:'${request.contextPath}/practice/info/trackAdmin-editSave.action', 
		   success : showReply,
	       dataType : 'json',
           clearForm : false,
           resetForm : false,
           type : 'post',
           timeout : 3000
    };
	$('#devForm').ajaxSubmit(options);
  }
  function showReply(data){
    closeTip();
	if(data && data != ''){
		showMsgError(data);
		isSubmit = false;
	} else {
		showMsgSuccess('毕业生足迹成功','',goBack);
	}
  }
  doFalsh();
</script>
<div id="container">
	<form id="devForm" name="devForm">
	<input type="hidden" id="studentId" name="studentId" value="${studentId!}">
	<input type="hidden" id="searchClsId" name="searchClsId" value="${searchClsId!}">
	<table width="100%" border="0" cellspacing="0" cellpadding="0" class="table-form table-list-edit" id="devTable">
        <tr>
            <th colspan="4" class="t-center b f14">基本信息</th>
        </tr>
        <tr>
            <th width="15%">年级班级:</th>
            <td width="35%"><span class="origin-txt">${clsName?default('')}</span></td>
            <th width="15%">班主任:</th>
            <td width="35%"><span class="origin-txt">${teaName?default('')}</span></td>
        </tr>
        <tr>
            <th>姓名:</th>
            <td><span class="origin-txt">${student.stuname?default("")}</span></td>
            <th>性别:</th>
            <td><span class="origin-txt">${appsetting.getMcode("DM-XB").get((x.studentSex?string)!)}</span></td>
        </tr>
        <tr>
            <th>家庭地址:</th>
            <td><span class="origin-txt">${student.homeAddress?default('')}</span></td>
            <th>政治面貌:</th>
            <td><span class="origin-txt">${appsetting.getMcode("DM-ZZMM").get((student.background)!)}</span></td>
        </tr>
        <tr>
            <th>联系电话:</th>
            <td><span class="origin-txt">${student.linkPhone?default('')}</span></td>
            <th> </th>
            <td> </td>
        </tr>
        <tr>
            <th colspan="4" class="t-center b f14">个人发展情况</th>
        </tr>
        <#if ptList?exists && ptList?size gt 0>
        <#list ptList as pt>
        <tr>
            <td colspan="4">
            	<span class="ml-15">跟踪日期:</span>
            	<@hc.datepicker id="trackDate" name="trackDate" value="${((pt.trackDate)?string('yyyy-MM-dd'))?if_exists}" class="input-date" size="20" />
            	<a href="javascript:void(0);" class="fn-right delTr" id="${pt.id!}"><img src="${request.contextPath}/static/images/icon/del2.png" alt="删除"></a>
            </td>
        </tr>
        <tr>
            <th>就业单位:</th>
            <td class="edit-td"><input type="text" class="edit-txt input-txt" id="workCompany" name="workCompany" value="${pt.workCompany?default('')}"/></td>
            <th>岗位:</th>
            <td class="edit-td"><input type="text" class="edit-txt input-txt" id="position" name="position" value="${pt.position?default('')}"/></td>
        </tr>
        <tr>
            <th>职务或职称:</th>
            <td class="edit-td"><input type="text" class="edit-txt input-txt" id="duty" name="duty" value="${pt.duty?default('')}"/></td>
            <th>学历:</th>
            <td class="edit-td"><input type="text" class="edit-txt input-txt" id="degree" name="degree" value="${pt.degree?default('')}"/></td>
        </tr>
        <tr>
            <th>年薪(万):</th>
            <td class="edit-td"><input type="text" class="edit-txt input-txt" id="annualSalary" name="annualSalary" value="${pt.annualSalary?default('')}"/></td>
            <th>其他:</th>
            <td class="edit-td"><input type="text" class="edit-txt input-txt" id="remark" name="remark" value="${pt.remark?default('')}"/></td>
        </tr>
        </#list>
        </#if> 
    </table>
    </form>
    <table id="copyTr" style="display:none;">
    	<tr>
            <td colspan="4"><span class="ml-15">跟踪日期:</span>
            	<@hc.datepicker id="trackDate" name="trackDate" class="input-date" size="20" />
            	<a href="javascript:void(0);" class="fn-right delTr"><img src="${request.contextPath}/static/images/icon/del2.png" alt="删除"></a>
            </td>
        </tr>
        <tr>
            <th>就业单位:</th>
            <td class="edit-td"><input type="text" class="edit-txt input-txt" id="workCompany" name="workCompany"/></td>
            <th>岗位:</th>
            <td class="edit-td"><input type="text" class="edit-txt input-txt" id="position" name="position"/></td>
        </tr>
        <tr>
            <th>职务或职称:</th>
            <td class="edit-td"><input type="text" class="edit-txt input-txt" id="duty" name="duty"/></td>
            <th>学历:</th>
            <td class="edit-td"><input type="text" class="edit-txt input-txt" id="degree" name="degree"/></td>
        </tr>
        <tr>
            <th>年薪(万):</th>
            <td class="edit-td"><input type="text" class="edit-txt input-txt" id="annualSalary" name="annualSalary"/></td>
            <th>其他:</th>
            <td class="edit-td"><input type="text" class="edit-txt input-txt" id="remark" name="remark"/></td>
        </tr>
    </table>
    <a href="javascript:void(0);" class="bottom-add-new" οnclick="addTr();">+ 新增个人发展情况</a>
    <div class="base-operation t-center">
	   	<p>
	   		<a href="javascript:void(0);" style="margin-top:10px;" οnclick="doSave();" class="abtn-blue-big">保存</a>
	   		<a href="javascript:void(0);" style="margin-top:10px;" οnclick="goBack();" class="abtn-blue-big">返回</a>
	   	</p>
    </div>
</div>
/@hc.moduleDiv

 

后台代码示例:

package net.zdsoft.eisu.practice.action;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import net.zdsoft.eis.base.common.entity.Student;
import net.zdsoft.eis.base.common.service.SemesterService;
import net.zdsoft.eis.base.common.service.StudentService;
import net.zdsoft.eis.frame.action.BaseAction;
import net.zdsoft.eis.frame.client.LoginInfo;
import net.zdsoft.eisu.eduadm.constant.EduadmConstants;
import net.zdsoft.eisu.eduadm.entity.EduadmTeachClass;
import net.zdsoft.eisu.eduadm.entity.EduadmTeachClassStu;
import net.zdsoft.eisu.eduadm.service.EduadmTeachClassService;
import net.zdsoft.eisu.eduadm.service.EduadmTeachClassStuService;
import net.zdsoft.eisu.practice.entity.PracticeEvaluation;
import net.zdsoft.eisu.practice.entity.PracticeTrack;
import net.zdsoft.eisu.practice.service.PracticeEvaluationService;
import net.zdsoft.eisu.practice.service.PracticeTrackService;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;

import com.opensymphony.xwork2.ModelDriven;
/**
 * 毕业足迹维护
 * 
 *@author chens
 *@since 2014-04-03
 */
@SuppressWarnings("serial")
public class GraduateTrackAdminAction extends BaseAction implements ModelDriven<Student>{

	private SemesterService semesterService;
	private PracticeTrackService practiceTrackService;
	private EduadmTeachClassService eduadmTeachClassService;
	private StudentService studentService;
	private EduadmTeachClassStuService eduadmTeachClassStuService;
	private PracticeEvaluationService practiceEvaluationService;
	
	private Student student = new Student();
	private List<String> acadyearList;
	private List<PracticeTrack> ptList;
	private List<EduadmTeachClass> eduTeacherClassList;
	private List<EduadmTeachClassStu> eduadmTeachClassStuList;
	private String searchAcadyear;
	private String searchClsId;
	private String studentId;
	private String[] studentIds;
	
	private Date[] trackDate;		//跟踪日期
	private String[] workCompany;	//就业单位
	private String[] position;		//岗位
	private String[] duty;			//职务或职称
	private String[] degree;		//学历
	private String[] annualSalary;	//年薪(万)   
	private String[] remark;        //其他
	
	private String practiceTrackId;	//个人发展情况id
	// 模块首页
	public String execute(){
		acadyearList = semesterService.getAcadyears();
		if(CollectionUtils.isEmpty(acadyearList)){
			promptMessageDto.setErrorMessage("学校还没有维护过学年学期信息!");
			return PROMPTMSG;
		}
		String currentyear = semesterService.getCurrentAcadyear();
		if(StringUtils.isBlank(searchAcadyear)){
			if(StringUtils.isBlank(currentyear)){
				searchAcadyear = acadyearList.get(0);
			} else {
				searchAcadyear = currentyear;
			}
		}
		eduTeacherClassList = eduadmTeachClassService.getTeachClassList(this.getLoginInfo().getUnitID(), searchAcadyear, String.valueOf(EduadmConstants.TEACH_CLASS_PRACTICE), null);
		if(StringUtils.isBlank(searchClsId) && CollectionUtils.isNotEmpty(eduTeacherClassList)){
			searchClsId = eduTeacherClassList.get(0).getId();
		}
		if(!StringUtils.isBlank(searchClsId))
			ptList = practiceTrackService.getPracticeTrackList(searchAcadyear, searchClsId);
		return SUCCESS;
	}
	
	//根据学年得到班级
	public String getclsByAcadyear(){
		eduTeacherClassList = eduadmTeachClassService.getTeachClassList(this.getLoginInfo().getUnitID(), searchAcadyear, String.valueOf(EduadmConstants.TEACH_CLASS_PRACTICE), null);
		return SUCCESS;
	}
	
	public String getPracticeTrackList(){
		if(!StringUtils.isBlank(studentId)){
			ptList = practiceTrackService.getPracticeTrack(studentId);
			student = studentService.getStudent(studentId);
		}
		return SUCCESS;
	}
	
	//毕业生推荐
	public String recommend(){
		eduTeacherClassList = eduadmTeachClassService.getTeachClassList(this.getLoginInfo().getUnitID(), searchAcadyear, String.valueOf(EduadmConstants.TEACH_CLASS_PRACTICE), null);
		if(StringUtils.isBlank(searchClsId) && CollectionUtils.isNotEmpty(eduTeacherClassList)){
			searchClsId = eduTeacherClassList.get(0).getId();
		}
		eduadmTeachClassStuList = eduadmTeachClassStuService.getTeachClassStuListByClassId(searchClsId);
		return SUCCESS;
	}
	
	//毕业生推荐信息保存
	public String recommendSave(){
		if(studentIds!=null&&studentIds.length>0){
			try {
				PracticeEvaluation eva;
				LoginInfo loginInfo = getLoginInfo();
				List<PracticeEvaluation> evas = new ArrayList<PracticeEvaluation>();
				for (String stuId : studentIds) {
					eva = new PracticeEvaluation();
					eva.setStudentId(stuId);
					eva.setEvaluate(0);
					eva.setIsTracked(true);
					eva.setUnitId(loginInfo.getUnitID());
					eva.setTeacherId(loginInfo.getUser().getTeacherid());
					eva.setAcadyear(searchAcadyear);
					evas.add(eva);
					eva = null;
				}
				practiceEvaluationService.saveEvas(evas, PracticeEvaluation.EVALUATION_TRACK);
			} catch (Exception e) {
				log.error(e.getMessage(), e);
				jsonError = "操作失败!";
			}
		}else{
			jsonError = "没有选择要推荐的学生,请先选择!";
		}
		return SUCCESS;
	}
	
	public String edit(){
		if(!StringUtils.isBlank(studentId)){
			ptList = practiceTrackService.getPracticeTrack(studentId);
			student = studentService.getStudent(studentId);
		}
		return SUCCESS;
	}
	
	public String editSave() {
		String unitId = getLoginInfo().getUnitID();
		ptList = new ArrayList<PracticeTrack>();
		for(int i=0;i<trackDate.length;i++){
			PracticeTrack pt = new PracticeTrack();
			pt.setUnitId(unitId);
			pt.setClassId(searchClsId);
			pt.setStudentId(studentId);
			pt.setTrackDate(trackDate[i]);
			pt.setWorkCompany(workCompany[i]);		//就业单位
			pt.setPosition(position[i]);			//岗位
			pt.setDuty(duty[i]);					//职务或职称
			pt.setDegree(degree[i]);				//学历
			pt.setAnnualSalary(annualSalary[i]);	//年薪(万)   
			pt.setRemark(remark[i]);				//其他
			ptList.add(pt);
		}
		if(StringUtils.isNotBlank(studentId)){
			try {
				practiceTrackService.saveList(studentId, ptList);
			} catch (Exception e) {
				log.error(e.getMessage());
				jsonError = "操作失败!";
			}
		}else{
			jsonError = "学生id为空";
		}
		return SUCCESS;
	}
	
	public String trackDelete(){
		try {
			practiceTrackService.deleteById(practiceTrackId);
		} catch (Exception e) {
			log.error(e.getMessage());
			jsonError = "删除个人发展情况失败";
		}
		return SUCCESS;
	}

	@Override
	public Student getModel() {
		return student;
	}
	public SemesterService getSemesterService() {
		return semesterService;
	}
	public void setSemesterService(SemesterService semesterService) {
		this.semesterService = semesterService;
	}
	public PracticeTrackService getPracticeTrackService() {
		return practiceTrackService;
	}
	public void setPracticeTrackService(PracticeTrackService practiceTrackService) {
		this.practiceTrackService = practiceTrackService;
	}
	public EduadmTeachClassService getEduadmTeachClassService() {
		return eduadmTeachClassService;
	}
	public void setEduadmTeachClassService(
			EduadmTeachClassService eduadmTeachClassService) {
		this.eduadmTeachClassService = eduadmTeachClassService;
	}
	public StudentService getStudentService() {
		return studentService;
	}
	public void setStudentService(StudentService studentService) {
		this.studentService = studentService;
	}
	public EduadmTeachClassStuService getEduadmTeachClassStuService() {
		return eduadmTeachClassStuService;
	}
	public void setEduadmTeachClassStuService(
			EduadmTeachClassStuService eduadmTeachClassStuService) {
		this.eduadmTeachClassStuService = eduadmTeachClassStuService;
	}
	public PracticeEvaluationService getPracticeEvaluationService() {
		return practiceEvaluationService;
	}
	public void setPracticeEvaluationService(
			PracticeEvaluationService practiceEvaluationService) {
		this.practiceEvaluationService = practiceEvaluationService;
	}
	public Student getStudent() {
		return student;
	}
	public void setStudent(Student student) {
		this.student = student;
	}
	public List<String> getAcadyearList() {
		return acadyearList;
	}
	public void setAcadyearList(List<String> acadyearList) {
		this.acadyearList = acadyearList;
	}
	public List<PracticeTrack> getPtList() {
		return ptList;
	}
	public void setPtList(List<PracticeTrack> ptList) {
		this.ptList = ptList;
	}
	public List<EduadmTeachClass> getEduTeacherClassList() {
		return eduTeacherClassList;
	}
	public void setEduTeacherClassList(List<EduadmTeachClass> eduTeacherClassList) {
		this.eduTeacherClassList = eduTeacherClassList;
	}
	public List<EduadmTeachClassStu> getEduadmTeachClassStuList() {
		return eduadmTeachClassStuList;
	}
	public void setEduadmTeachClassStuList(
			List<EduadmTeachClassStu> eduadmTeachClassStuList) {
		this.eduadmTeachClassStuList = eduadmTeachClassStuList;
	}
	public String getSearchAcadyear() {
		return searchAcadyear;
	}
	public void setSearchAcadyear(String searchAcadyear) {
		this.searchAcadyear = searchAcadyear;
	}
	public String getSearchClsId() {
		return searchClsId;
	}
	public void setSearchClsId(String searchClsId) {
		this.searchClsId = searchClsId;
	}
	public String getStudentId() {
		return studentId;
	}
	public void setStudentId(String studentId) {
		this.studentId = studentId;
	}
	public String[] getStudentIds() {
		return studentIds;
	}
	public void setStudentIds(String[] studentIds) {
		this.studentIds = studentIds;
	}
	public Date[] getTrackDate() {
		return trackDate;
	}
	public void setTrackDate(Date[] trackDate) {
		this.trackDate = trackDate;
	}
	public String[] getWorkCompany() {
		return workCompany;
	}
	public void setWorkCompany(String[] workCompany) {
		this.workCompany = workCompany;
	}
	public String[] getPosition() {
		return position;
	}
	public void setPosition(String[] position) {
		this.position = position;
	}
	public String[] getDuty() {
		return duty;
	}
	public void setDuty(String[] duty) {
		this.duty = duty;
	}
	public String[] getDegree() {
		return degree;
	}
	public void setDegree(String[] degree) {
		this.degree = degree;
	}
	public String[] getAnnualSalary() {
		return annualSalary;
	}
	public void setAnnualSalary(String[] annualSalary) {
		this.annualSalary = annualSalary;
	}
	public String[] getRemark() {
		return remark;
	}
	public void setRemark(String[] remark) {
		this.remark = remark;
	}
	public String getPracticeTrackId() {
		return practiceTrackId;
	}
	public void setPracticeTrackId(String practiceTrackId) {
		this.practiceTrackId = practiceTrackId;
	}
	
}


 

1 ,引入依赖脚本

<script type="text/javascript" src="/js/jquery/jquery.form.js"></script> //ajaxForm 依赖脚本

<script type="text/javascript" src="/js/jquery/jquery-1.8.0.min.js"></script>
< script type="text/javascript" src="/js/jquery/jquery.easyui.min.js"></script>


2 使用方法

<form name="testForm" id="testForm" >

<input type="button" value="submit"/>

</form>

<script type="text/javascript">

var ajax_option={

url:"login",//默认是form action

success:function(data){

}

$('#testForm').ajaxSubmit(ajax_option);

}

</script>


//注意$("#testForm") 引号中名称必须要和form元素id值要保持一致

3 ajaxSubmit 和ajaxForm区别

ajaxForm不能提交表单。在document的ready函数中,使用ajaxForm来为AJAX提交表单进行准备。提交动作必须由submit开始

ajaxSubmit 马上由AJAX来提交表单。你可以在任何情况下进行该项提交。

4

option的参数
var options = {
target: '#output1', // target element(s) to be updated with server response
beforeSubmit: showRequest, // pre-submit callback
success: showResponse // post-submit callback

// other available options:
//url: url // override for form's 'action' attribute
//type: type // 'get' or 'post', override for form's 'method' attribute
//dataType: null // 'xml', 'script', or 'json' (expected server response type)
//clearForm: true // clear all form fields after successful submit
//resetForm: true // reset the form after successful submit

// $.ajax options can be used here too, for example:
//timeout: 3000
};


package net.zdsoft.eisu.practice.action;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import net.zdsoft.eis.base.common.entity.Student;
import net.zdsoft.eis.base.common.service.SemesterService;
import net.zdsoft.eis.base.common.service.StudentService;
import net.zdsoft.eis.frame.action.BaseAction;
import net.zdsoft.eis.frame.client.LoginInfo;
import net.zdsoft.eisu.eduadm.constant.EduadmConstants;
import net.zdsoft.eisu.eduadm.entity.EduadmTeachClass;
import net.zdsoft.eisu.eduadm.entity.EduadmTeachClassStu;
import net.zdsoft.eisu.eduadm.service.EduadmTeachClassService;
import net.zdsoft.eisu.eduadm.service.EduadmTeachClassStuService;
import net.zdsoft.eisu.practice.entity.PracticeEvaluation;
import net.zdsoft.eisu.practice.entity.PracticeTrack;
import net.zdsoft.eisu.practice.service.PracticeEvaluationService;
import net.zdsoft.eisu.practice.service.PracticeTrackService;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;

import com.opensymphony.xwork2.ModelDriven;
/**
 * 毕业足迹维护
 * 
 *@author chens
 *@since 2014-04-03
 */
@SuppressWarnings("serial")
public class GraduateTrackAdminAction extends BaseAction implements ModelDriven<Student>{

	private SemesterService semesterService;
	private PracticeTrackService practiceTrackService;
	private EduadmTeachClassService eduadmTeachClassService;
	private StudentService studentService;
	private EduadmTeachClassStuService eduadmTeachClassStuService;
	private PracticeEvaluationService practiceEvaluationService;
	
	private Student student = new Student();
	private List<String> acadyearList;
	private List<PracticeTrack> ptList;
	private List<EduadmTeachClass> eduTeacherClassList;
	private List<EduadmTeachClassStu> eduadmTeachClassStuList;
	private String searchAcadyear;
	private String searchClsId;
	private String studentId;
	private String[] studentIds;
	
	private Date[] trackDate;		//跟踪日期
	private String[] workCompany;	//就业单位
	private String[] position;		//岗位
	private String[] duty;			//职务或职称
	private String[] degree;		//学历
	private String[] annualSalary;	//年薪(万)   
	private String[] remark;        //其他
	
	private String practiceTrackId;	//个人发展情况id
	// 模块首页
	public String execute(){
		acadyearList = semesterService.getAcadyears();
		if(CollectionUtils.isEmpty(acadyearList)){
			promptMessageDto.setErrorMessage("学校还没有维护过学年学期信息!");
			return PROMPTMSG;
		}
		String currentyear = semesterService.getCurrentAcadyear();
		if(StringUtils.isBlank(searchAcadyear)){
			if(StringUtils.isBlank(currentyear)){
				searchAcadyear = acadyearList.get(0);
			} else {
				searchAcadyear = currentyear;
			}
		}
		eduTeacherClassList = eduadmTeachClassService.getTeachClassList(this.getLoginInfo().getUnitID(), searchAcadyear, String.valueOf(EduadmConstants.TEACH_CLASS_PRACTICE), null);
		if(StringUtils.isBlank(searchClsId) && CollectionUtils.isNotEmpty(eduTeacherClassList)){
			searchClsId = eduTeacherClassList.get(0).getId();
		}
		if(!StringUtils.isBlank(searchClsId))
			ptList = practiceTrackService.getPracticeTrackList(searchAcadyear, searchClsId);
		return SUCCESS;
	}
	
	//根据学年得到班级
	public String getclsByAcadyear(){
		eduTeacherClassList = eduadmTeachClassService.getTeachClassList(this.getLoginInfo().getUnitID(), searchAcadyear, String.valueOf(EduadmConstants.TEACH_CLASS_PRACTICE), null);
		return SUCCESS;
	}
	
	public String getPracticeTrackList(){
		if(!StringUtils.isBlank(studentId)){
			ptList = practiceTrackService.getPracticeTrack(studentId);
			student = studentService.getStudent(studentId);
		}
		return SUCCESS;
	}
	
	//毕业生推荐
	public String recommend(){
		eduTeacherClassList = eduadmTeachClassService.getTeachClassList(this.getLoginInfo().getUnitID(), searchAcadyear, String.valueOf(EduadmConstants.TEACH_CLASS_PRACTICE), null);
		if(StringUtils.isBlank(searchClsId) && CollectionUtils.isNotEmpty(eduTeacherClassList)){
			searchClsId = eduTeacherClassList.get(0).getId();
		}
		eduadmTeachClassStuList = eduadmTeachClassStuService.getTeachClassStuListByClassId(searchClsId);
		return SUCCESS;
	}
	
	//毕业生推荐信息保存
	public String recommendSave(){
		if(studentIds!=null&&studentIds.length>0){
			try {
				PracticeEvaluation eva;
				LoginInfo loginInfo = getLoginInfo();
				List<PracticeEvaluation> evas = new ArrayList<PracticeEvaluation>();
				for (String stuId : studentIds) {
					eva = new PracticeEvaluation();
					eva.setStudentId(stuId);
					eva.setEvaluate(0);
					eva.setIsTracked(true);
					eva.setUnitId(loginInfo.getUnitID());
					eva.setTeacherId(loginInfo.getUser().getTeacherid());
					eva.setAcadyear(searchAcadyear);
					evas.add(eva);
					eva = null;
				}
				practiceEvaluationService.saveEvas(evas, PracticeEvaluation.EVALUATION_TRACK);
			} catch (Exception e) {
				log.error(e.getMessage(), e);
				jsonError = "操作失败!";
			}
		}else{
			jsonError = "没有选择要推荐的学生,请先选择!";
		}
		return SUCCESS;
	}
	
	public String edit(){
		if(!StringUtils.isBlank(studentId)){
			ptList = practiceTrackService.getPracticeTrack(studentId);
			student = studentService.getStudent(studentId);
		}
		return SUCCESS;
	}
	
	public String editSave() {
		String unitId = getLoginInfo().getUnitID();
		ptList = new ArrayList<PracticeTrack>();
		for(int i=0;i<trackDate.length;i++){
			PracticeTrack pt = new PracticeTrack();
			pt.setUnitId(unitId);
			pt.setClassId(searchClsId);
			pt.setStudentId(studentId);
			pt.setTrackDate(trackDate[i]);
			pt.setWorkCompany(workCompany[i]);		//就业单位
			pt.setPosition(position[i]);			//岗位
			pt.setDuty(duty[i]);					//职务或职称
			pt.setDegree(degree[i]);				//学历
			pt.setAnnualSalary(annualSalary[i]);	//年薪(万)   
			pt.setRemark(remark[i]);				//其他
			ptList.add(pt);
		}
		if(StringUtils.isNotBlank(studentId)){
			try {
				practiceTrackService.saveList(studentId, ptList);
			} catch (Exception e) {
				log.error(e.getMessage());
				jsonError = "操作失败!";
			}
		}else{
			jsonError = "学生id为空";
		}
		return SUCCESS;
	}
	
	public String trackDelete(){
		try {
			practiceTrackService.deleteById(practiceTrackId);
		} catch (Exception e) {
			log.error(e.getMessage());
			jsonError = "删除个人发展情况失败";
		}
		return SUCCESS;
	}

	@Override
	public Student getModel() {
		return student;
	}
	public SemesterService getSemesterService() {
		return semesterService;
	}
	public void setSemesterService(SemesterService semesterService) {
		this.semesterService = semesterService;
	}
	public PracticeTrackService getPracticeTrackService() {
		return practiceTrackService;
	}
	public void setPracticeTrackService(PracticeTrackService practiceTrackService) {
		this.practiceTrackService = practiceTrackService;
	}
	public EduadmTeachClassService getEduadmTeachClassService() {
		return eduadmTeachClassService;
	}
	public void setEduadmTeachClassService(
			EduadmTeachClassService eduadmTeachClassService) {
		this.eduadmTeachClassService = eduadmTeachClassService;
	}
	public StudentService getStudentService() {
		return studentService;
	}
	public void setStudentService(StudentService studentService) {
		this.studentService = studentService;
	}
	public EduadmTeachClassStuService getEduadmTeachClassStuService() {
		return eduadmTeachClassStuService;
	}
	public void setEduadmTeachClassStuService(
			EduadmTeachClassStuService eduadmTeachClassStuService) {
		this.eduadmTeachClassStuService = eduadmTeachClassStuService;
	}
	public PracticeEvaluationService getPracticeEvaluationService() {
		return practiceEvaluationService;
	}
	public void setPracticeEvaluationService(
			PracticeEvaluationService practiceEvaluationService) {
		this.practiceEvaluationService = practiceEvaluationService;
	}
	public Student getStudent() {
		return student;
	}
	public void setStudent(Student student) {
		this.student = student;
	}
	public List<String> getAcadyearList() {
		return acadyearList;
	}
	public void setAcadyearList(List<String> acadyearList) {
		this.acadyearList = acadyearList;
	}
	public List<PracticeTrack> getPtList() {
		return ptList;
	}
	public void setPtList(List<PracticeTrack> ptList) {
		this.ptList = ptList;
	}
	public List<EduadmTeachClass> getEduTeacherClassList() {
		return eduTeacherClassList;
	}
	public void setEduTeacherClassList(List<EduadmTeachClass> eduTeacherClassList) {
		this.eduTeacherClassList = eduTeacherClassList;
	}
	public List<EduadmTeachClassStu> getEduadmTeachClassStuList() {
		return eduadmTeachClassStuList;
	}
	public void setEduadmTeachClassStuList(
			List<EduadmTeachClassStu> eduadmTeachClassStuList) {
		this.eduadmTeachClassStuList = eduadmTeachClassStuList;
	}
	public String getSearchAcadyear() {
		return searchAcadyear;
	}
	public void setSearchAcadyear(String searchAcadyear) {
		this.searchAcadyear = searchAcadyear;
	}
	public String getSearchClsId() {
		return searchClsId;
	}
	public void setSearchClsId(String searchClsId) {
		this.searchClsId = searchClsId;
	}
	public String getStudentId() {
		return studentId;
	}
	public void setStudentId(String studentId) {
		this.studentId = studentId;
	}
	public String[] getStudentIds() {
		return studentIds;
	}
	public void setStudentIds(String[] studentIds) {
		this.studentIds = studentIds;
	}
	public Date[] getTrackDate() {
		return trackDate;
	}
	public void setTrackDate(Date[] trackDate) {
		this.trackDate = trackDate;
	}
	public String[] getWorkCompany() {
		return workCompany;
	}
	public void setWorkCompany(String[] workCompany) {
		this.workCompany = workCompany;
	}
	public String[] getPosition() {
		return position;
	}
	public void setPosition(String[] position) {
		this.position = position;
	}
	public String[] getDuty() {
		return duty;
	}
	public void setDuty(String[] duty) {
		this.duty = duty;
	}
	public String[] getDegree() {
		return degree;
	}
	public void setDegree(String[] degree) {
		this.degree = degree;
	}
	public String[] getAnnualSalary() {
		return annualSalary;
	}
	public void setAnnualSalary(String[] annualSalary) {
		this.annualSalary = annualSalary;
	}
	public String[] getRemark() {
		return remark;
	}
	public void setRemark(String[] remark) {
		this.remark = remark;
	}
	public String getPracticeTrackId() {
		return practiceTrackId;
	}
	public void setPracticeTrackId(String practiceTrackId) {
		this.practiceTrackId = practiceTrackId;
	}
	
}


 

 

 类似资料: