<|start_filename|>src/main/java/com/example/dao/StudentDao.java<|end_filename|>
package com.example.dao;

import java.util.HashMap;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import com.example.entry.Student;

@Mapper
public interface StudentDao {
	public Student searchById(String id);
	public List<Student> allStudent();
	public int insertStudent(Student student);
	public int deleteStudent(String id);
	public int updateStudent(HashMap<String,Object> map);
}


<|start_filename|>src/main/java/com/example/dao/AdminDao.java<|end_filename|>
package com.example.dao;

import org.apache.ibatis.annotations.Mapper;

import com.example.entry.Admin;

@Mapper
public interface AdminDao {
	public Admin loginCheck(String id);
}


<|start_filename|>src/main/java/com/example/controller/AdminController.java<|end_filename|>
package com.example.controller;

import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.example.entry.Admin;
import com.example.service.AdminService;

@CrossOrigin(origins= {"http://localhost:8080","null"})
@Controller
public class AdminController {
	
	@Resource
	private AdminService adminService;

	
	@RequestMapping(value = "judge", method = RequestMethod.POST)
	@ResponseBody
	public String jumpPage(@RequestBody Map<String, String> map,HttpServletResponse response) {		
		Admin admin = adminService.checkLogin(map.get("id"));		
		if (admin == null) {
			return "0";
		} 
		else {
			if (admin.getPassword().equals(map.get("password"))) {
				Cookie cookie=new Cookie("id", map.get("id"));
				cookie.setMaxAge(600);
				response.addCookie(cookie);
				return "1";
			} else {
				return "-1";
			}
		}
	}
}


<|start_filename|>src/main/java/com/example/controller/FirstPage.java<|end_filename|>
package com.example.controller;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class FirstPage {
	
	@RequestMapping("/")
	public String login() {
		return "admin/login";
	}
	
	@RequestMapping("/index.php")
	public String index(HttpServletRequest request) {
		Cookie[] cookies=request.getCookies();
		if (cookies!=null) {
			for (Cookie cookie : cookies) {
				if (cookie.getName().equals("id")) {
					return "student/index";
				}
			}	
		}			
			return "admin/login";
	}
}


<|start_filename|>src/main/java/com/example/service/StudentService.java<|end_filename|>
package com.example.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.example.dao.StudentDao;
import com.example.entry.Student;

@Service
public class StudentService {
	@Resource
	private StudentDao studentDao;	
		
	public Map<String, Object> PageShow(int limit,int offset){
		Map<String, Object> map=new HashMap<>();
		List<Student> page=new ArrayList<>();
		List<Student> all=studentDao.allStudent();
		for (int i = offset; i < offset+limit; i++) {
			if (i<all.size()) {
				page.add(all.get(i));
			}
		}
		map.put("rows", page);
		map.put("total", all.size());
		return map;
	}
	
	public int insertStudent(Student student) {
		return studentDao.insertStudent(student);
	}
	
	public int deleteStudent(String id) {
		return studentDao.deleteStudent(id);
	}
	
	public int updateStudent(HashMap<String, Object> map) {
		System.err.println(map);
		return studentDao.updateStudent(map);
	}
	
	public Student searchById(String id) {
		return studentDao.searchById(id);
	}
}


<|start_filename|>src/main/java/com/example/service/AdminService.java<|end_filename|>
package com.example.service;

import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.example.dao.AdminDao;
import com.example.entry.Admin;

@Service
public class AdminService {
	@Resource
	private AdminDao adminDao;
	
	public Admin checkLogin(String id) {
		Admin admin = adminDao.loginCheck(id);
		return admin;
	}
}


<|start_filename|>src/main/java/com/example/controller/StudentController.java<|end_filename|>
package com.example.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.example.entry.Student;
import com.example.service.StudentService;

@Controller
@ResponseBody
public class StudentController {
	@Resource
	private StudentService studentService;
	
	@RequestMapping(value="showTable",method=RequestMethod.POST)
	public Map<String, Object> getTable(@RequestParam(value="limit") Integer limit,@RequestParam(value="offset") Integer offset) {
		return studentService.PageShow(limit, offset);
	}
	
	@RequestMapping(value="insertStudent",method=RequestMethod.POST)
	public int insertStudent(@RequestBody Student student) {					
		return studentService.insertStudent(student);
	}
	
	@RequestMapping(value="deleteStudent",method=RequestMethod.POST)
	public int deleteStudent(@RequestParam(value="id") String id) {
		return studentService.deleteStudent(id);
	}
	
	@RequestMapping(value="updateStudent",method=RequestMethod.POST)
	public int updateStudent(@RequestBody HashMap<String, Object> map) {
		return studentService.updateStudent(map);
	}
	
	@RequestMapping(value="searchById",method=RequestMethod.POST)
	public Student searchById(@RequestParam(value="id") String id) {
		return studentService.searchById(id);
	}
}
