前端传来的是 sid atype adesc
sid 学号
atype 要签到还是签退
签到传0 签退传1
Controller
package com.chinasofti.fwgl.ctrl;
import java.util.HashMap;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.chinasofti.fwgl.bean.att_attendance;
import com.chinasofti.fwgl.bean.att_student;
import com.chinasofti.fwgl.service.att_studentService;
@Controller
public class att_studentController {
@Autowired
private att_studentService as;
@RequestMapping("/doQianDaoOrQianTui")
@ResponseBody
public HashMap<String,Object> qindaoqiantui(@RequestParam("sid") int sid,
@RequestParam("adesc") String adesc,
@RequestParam("atype") int atype){
int count = 0;
// 如果 要签到的话 前端传来的atype=0
if(atype==0){
count = as.qiandao(sid, atype,adesc);
}else{
// 如果要签退的话 前端传来的atype=1
count = as.qiantui(sid);
}
HashMap<String,Object> hm = new HashMap<>();
if(count>0){
hm.put(“statecode”, 400);
}else{
hm.put("statecode", 200);
}
return hm;
}
}
Service
package com.chinasofti.fwgl.service;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.chinasofti.fwgl.bean.att_attendance;
import com.chinasofti.fwgl.bean.att_student;
import com.chinasofti.fwgl.dao.att_studentMapper;
@Service
public class att_studentService {
@Autowired
private att_studentMapper am;
public int qiandao(int sid,int atype,String adesc) {
return am.qiandao(sid,atype,adesc);
}
public int qiantui(int sid) {
return am.qiantui(sid);
}
}
Mapper
package com.chinasofti.fwgl.dao;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
@Mapper
public interface att_studentMapper {
@Insert("insert into att_attendance values(1008,#{sid},sysdate,1,#{adesc}" )
public int qiandao(@Param("sid") int sid,@Param("atype") int atype,@Param("adesc") String adesc);
@Update("update att_attendance set atype = 1 where sid=#{sid}" )
public int qiantui(@Param("sid") int sid);
}