ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Cinephile 스프링 프로젝트 시작(login) 1
    프로젝트 2020. 9. 11. 19:34

    그동안 WebContetn에 작성했던 프로젝트 파일들을 영광이가 스프링으로 옮겼다.

    전에 WebContent에 만들어 놓았던 폴더를 그대로 스프링 WEB-INF/views/ 에 옮겨 놓았고 css, img, js_files, plugins 폴더는 assets폴더에 모두 모아놓았다. 이 프로젝트를 실행 하면 home.jsp가 실행이 되고 우리 홈페이지 대문이 뜨는데 저 이름을 index로 바꿔보려 시도했으나 오류가 나서 일단은 저렇게 놔뒀다.

    일단 나는 대문 페이지에 들어가는 사진들의 경로들을 맞춰주었고 대문 페이지의 오른쪽 상단에 내가 담당하는 '로그인'과 '회원가입'의 링크를 연결하기 위해 컨트롤러를 작성하려던 중 잠깐 고민에 빠지게 되었다.

    앞에 Professor이 들어가는 컨트롤러를 참고해서 만들려고 했는데 3개나 됐다. 

     

    일단 ProfessorController.java는(더보기)

    더보기
    package study.spring.springhelper.controllers;
    
    import java.util.List;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.Model;
    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.servlet.ModelAndView;
    
    import study.spring.springhelper.helper.PageData;
    import study.spring.springhelper.helper.RegexHelper;
    import study.spring.springhelper.helper.WebHelper;
    import study.spring.springhelper.model.Department;
    import study.spring.springhelper.model.Professor;
    import study.spring.springhelper.service.DepartmentService;
    import study.spring.springhelper.service.ProfessorService;
    
    @Controller
    public class ProfessorController {
    	/* WebHelper 주입 */
    	// -->import org.springframework.beans.factory.annotation.Autowired;
    	// -->import study.spring.springhelper.helper.WebHelper;
    	@Autowired WebHelper webHelper;
    	
    	/* RegexHelper 주입 */
    	// --> import study.spring.springhelper.helper.RegexHelper;
    	@Autowired RegexHelper regexHelper;
    	
    	/* Service 패턴 구현체 주입 */
    	// --> import study.spring.springhelper.service.ProfessorService;
    	@Autowired ProfessorService professorService;
    	
    	// -->import study.spring.springhelper.service.DepartmentService;
    	@Autowired DepartmentService departmentService;
    	
    	/* "/프로젝트 이름"에 해당하는 ContextPath 변수 주입 */
    	// --> import org.springframework.beans.factory.annotation.Value;
    	@Value("#{servletContext.contextPath}")
    	String contextPath;
    	
    	/* 목록페이지 */
    	@RequestMapping(value="/professor/list.do", method = RequestMethod.GET)
    	public ModelAndView list(Model model,
    			//검색어
    			@RequestParam(value="keyword", required=false) String keyword,
    			//페이지 구현에서 사용할 현재 페이지 번호
    			@RequestParam(value="page", defaultValue="1") int nowPage) {
    		
    		/* 1)페이지 구현에 필요한 변수값 생성 */
    		int totalCount = 0;		//전체 게시글 수
    		int listCount = 10;		//한 페이지당 표시할 목록 수
    		int pageCount = 5;		//한 그룹당 표시할 페이지 번호 수
    		
    		/* 2)데이터 조회하기 */
    		//조회에 필요한 조건값 (검색어)를 Beans에 담는다.
    		Professor input = new Professor();
    		input.setName(keyword);
    		
    		List<Professor> output = null; //조회결과가 저장될 객체
    		PageData pageData = null;		//페이지 번호를 계산한 결과가 저장될 객체
    		
    		try {
    			//전체 게시글 수 조회
    			totalCount = professorService.getProfessorCount(input);
    			//페이지 번호 계산 --> 계산결과를 로그로 출력될 것이다.
    			pageData = new PageData(nowPage, totalCount, listCount, pageCount);
    			
    			//SQL의 Limit절에서 사용될 값을 Beans의 static 변수에 저장
    			Professor.setOffset(pageData.getOffset());
    			Professor.setListCount(pageData.getListCount());
    			
    			//데이터 조회하기
    			output = professorService.getProfessorList(input);
    		}catch(Exception e) {
    			return webHelper.redirect(null, e.getLocalizedMessage());
    		}
    		
    		/* 3)View 처리 */
    		model.addAttribute("keyword", keyword);
    		model.addAttribute("output", output);
    		model.addAttribute("pageData", pageData);
    		
    		
    		return new ModelAndView("professor/list");
    		}
    	
    	/* 상세페이지 */
    	@RequestMapping(value="/professor/view.do", method = RequestMethod.GET)
    	public ModelAndView view(Model model,
    			@RequestParam(value="profno", defaultValue="0") int profno) {
    		/* 1)유효성 검사 */
    		//이 값이 존재하지 않는다면 데이터 조회가 불가능하므로 반드시 필수값으로 처리해야 한다.
    		if(profno ==0) {
    			return webHelper.redirect(null, "교수번호가 없습니다.");
    		}
    		
    		/* 2)데이터 조회하기 */
    		//데이터 조회에 필요한 조건값을 Beans에 저장하기
    		Professor input = new Professor();
    		input.setProfno(profno);
    		
    		//조회결과를 저장할 객체 선언
    		Professor output = null;
    		
    		try {
    			//데이터 조회
    			output = professorService.getProfessorItem(input);
    		}catch(Exception e) {
    			return webHelper.redirect(null, e.getLocalizedMessage());
    		}
    		
    		/* 3)View 처리 */
    		model.addAttribute("output", output);
    		return new ModelAndView("professor/view");
    	}
    	
    	/* 작성 폼 페이지 */
    	@RequestMapping(value="/professor/add.do", method = RequestMethod.GET)
    	public ModelAndView add(Model model) {
    		
    		/* 학과목록 조회하기 */
    		//조회 결과를 저장할 객체 선언
    		List<Department> output = null;
    		
    		try {
    			//데이터 조회 --> 검색조건 없이 모든 학과 조회
    			output = departmentService.getDepartmentList(null);
    		}catch(Exception e) {
    			return webHelper.redirect(null, e.getLocalizedMessage());
    		}
    		
    		//View에 추가
    		model.addAttribute("output", output);
    		return new ModelAndView("professor/add");
    	}
    	
    	/* 작성 폼 action 페이지 */
    	@RequestMapping(value="/professor/add_ok.do", method = RequestMethod.POST)
    	public ModelAndView add_ok(Model model,
    		@RequestParam(value="name", required=false) String name,
    		@RequestParam(value="userid", required=false) String userid,
    		@RequestParam(value="position", required=false) String position,
    		@RequestParam(value="sal", defaultValue="0") int sal,
    		@RequestParam(value="hiredate", required=false) String hiredate,
    		@RequestParam(value="comm", required=false) Integer comm,
    		@RequestParam(value="deptno", defaultValue="0") int deptno){
    		
    		/* 1)사용자가 입력한 파라미터에 대한 유효성 검사 */
    		//일반 문자열 입력 컬럼 -->String으로 파라미터가 선언되어 있는 경우는 값이 입력되지 않으면 빈 문자열로 처리된다.
    		if(name.equals(""))						{return webHelper.redirect(null, "이름을 입력하세요");}
    		if(!regexHelper.isKor(name))			{return webHelper.redirect(null, "이름은 한글만 입력 가능합니다.");}
    		if(userid.equals(""))					{return webHelper.redirect(null, "아이디를 입력하세요");}
    		if(!regexHelper.isEngNum(userid))		{return webHelper.redirect(null, "아이디는 영어와 숫자로만 가능합니다.");}
    		if(hiredate.equals(""))					{return webHelper.redirect(null, "입사일을 입력하세요");}
    		
    		//null을 허용하는 형태인 경우 int에 대응하는 Integer로 처리하였다.
    		if(position == null)					{return webHelper.redirect(null, "직급을 입력하세요");}
    		
    		//숫자 형으로 선언도니 파라미터()
    		if(sal == 0)							{return webHelper.redirect(null, "급여를 입력하세요");}
    		if(sal < 0)								{return webHelper.redirect(null, "급여는 0보다 작을 수 없습니다.");}
    		if(comm < 0)							{return webHelper.redirect(null, "보직수당은 0보다 작을 수 없습니다.");}
    		if(deptno == 0)							{return webHelper.redirect(null, "소속 학과 번호를 입력하세요");}
    	
    		/* 2)데이터 저장하기 */
    		//저장할 값들을 Beans에 담는다.
    		Professor input = new Professor();
    		input.setName(name);
    		input.setUserid(userid);
    		input.setPosition(position);
    		input.setSal(sal);
    		input.setHiredate(hiredate);
    		input.setComm(comm);
    		input.setDeptno(deptno);
    		
    		try {
    			//데이터 저장
    			// --> 데이터 저장에 성공하면 파라미터로 전달하는 input 객체에 PK값이 저장된다.
    			professorService.addProfessor(input);
    		}catch(Exception e) {
    			return webHelper.redirect(null, e.getLocalizedMessage());
    		}
    		
    		/* 3)결과를 확인하기 위한 페이지 이동 */
    		//저장 결과를 확인하기 위해서 데이터 저장시 생성된 PK값을 상세 페이지로 전달해야 한다.
    		String redirectUrl = contextPath + "/professor/view.do?profno=" + input.getProfno();
    		return webHelper.redirect(redirectUrl, "저장되었습니다.");
    		
    	
    		}
    	
    	/* 수정 폼 페이지 */
    	@RequestMapping(value="/professor/edit.do", method = RequestMethod.GET)
    	public ModelAndView edit(Model model,
    			@RequestParam(value="profno", defaultValue="0")int profno) {
    		
    		/* 1)파라미터 유효성 검사 */
    		//이 값이 존대하지 않는다면 데이터 조회가 불가능하므로 반드시 필수값으로 처리해야 한다.
    		if(profno == 0) {
    			return webHelper.redirect(null, "교수번호가 없습니다.");
    		}
    		
    		/* 2)데이터 조회하기 */
    		//데이터 조회에 필요한 조건값을 Beans에 저장하기
    		Professor input = new Professor();
    		input.setProfno(profno);
    		
    		//교수 조회 결과를 저장할 객체 선언
    		Professor output = null;
    		
    		//학과목록을 선택할 수 있는 드롭다운을 위한 조회결과를 저장할 객체 선언
    		List<Department> deptList = null;
    		
    		try {
    			//교수 기본 정보 조회
    			output = professorService.getProfessorItem(input);
    			//드롭다운을 위한 학과목록 조회
    			deptList = departmentService.getDepartmentList(null);
    		}catch(Exception e) {
    			return webHelper.redirect(null, e.getLocalizedMessage());
    		}
    		
    		/* 3)View 처리 */
    		model.addAttribute("output", output);
    		model.addAttribute("deptList", deptList);
    		return new ModelAndView("professor/edit");
    		
    	}
    	
    	
    	/* 수정 폼에 대한 action 페이지 */
    	@RequestMapping(value="/professor/edit_ok.do", method = RequestMethod.POST)
    	public ModelAndView edit_ok(Model model,
    			@RequestParam(value="profno", defaultValue="0") int profno,
    			@RequestParam(value="name", required=false) String name,
    			@RequestParam(value="userid", required=false) String userid,
    			@RequestParam(value="position", required=false) String position,
    			@RequestParam(value="sal", defaultValue="0") int sal,
    			@RequestParam(value="hiredate", required=false) String hiredate,
    			@RequestParam(value="comm", required=false) Integer comm,
    			@RequestParam(value="deptno", defaultValue="0") int deptno) {
    		
    		/* 1)사용자가 입력한 파라미터 유효성 검사 */
    		if(profno == 0) 					{return webHelper.redirect(null, "교수번호가 없습니다.");}
    		if(name == null) 					{return webHelper.redirect(null, "교수 이름을 입력하세요.");}
    		if(!regexHelper.isKor(name)) 		{return webHelper.redirect(null, "교수 이름은 한글만 가능합니다.");}
    		if(userid == null) 					{return webHelper.redirect(null, "교수 아이디를 입력하세요.");}
    		if(!regexHelper.isEngNum(userid)) 	{return webHelper.redirect(null, "교수 아이디는 영어와 숫자로만 가능합니다..");}
    		if(position == null) 				{return webHelper.redirect(null, "직급을 입력하세요.");}
    		if(sal == 0) 						{return webHelper.redirect(null, "급여를 입력하세요.");}
    		if(sal < 0) 						{return webHelper.redirect(null, "급여는 0보다 작을 수 없습니다.");}
    		if(hiredate == null) 				{return webHelper.redirect(null, "입사일을 입력하세요.");}
    		if(comm < 0) 						{return webHelper.redirect(null, "보직수당은 0보다 작을 수 없습니다.");}
    		if(deptno == 0) 					{return webHelper.redirect(null, "소속 학과 번호를 입력하세요.");}
    		
    		/* 2) 데이터 수정하기 */
    		//수정할 값들을 Beans에 담는다.
    		Professor input = new Professor();
    		input.setProfno(profno);
    		input.setName(name);
    		input.setUserid(userid);
    		input.setPosition(position);
    		input.setSal(sal);
    		input.setHiredate(hiredate);
    		input.setComm(comm);
    		input.setDeptno(deptno);
    		
    		try {
    			//데이터 수정
    			professorService.editProfessor(input);
    		}catch(Exception e) {
    			return webHelper.redirect(null, e.getLocalizedMessage());
    		}
    		
    		/* 3)결과를 확인하기 위한 페이지 이동 */
    		//수정한 대상을 상세페이지에 알려주기 위해서 PK값을 전달해야 한다.
    		String redirectUrl = contextPath + "/professor/view.do?profno=" + input.getProfno();
    		return webHelper.redirect(redirectUrl, "수정되었습니다.");
    		
    	}
    	
    	/* 삭제처리*/
    	@RequestMapping(value="/professor/delete_ok.do", method = RequestMethod.GET)
    	public ModelAndView delete_ok(Model model,
    			@RequestParam(value="profno", defaultValue="0") int profno) {
    		
    		/* 1)파라미터 유효성 검사 */
    		//이 값이 존대하지 않는다면 데이터 삭제가 불가능 하므로 반드시 필수 값으로 처리해야 하낟.
    		if(profno == 0) {
    			return webHelper.redirect(null, "교수번호가 없습니다.");
    		}
    		/* 2)데이터 삭제하기 */
    		//데이터 삭제에 필요한 조건값을 Beans에 저장하기
    		Professor input = new Professor();
    		input.setProfno(profno);
    		
    		try {
    			professorService.deleteProfessor(input);//데이터 삭제
    		}catch(Exception e) {
    			return webHelper.redirect(null, e.getLocalizedMessage());
    		}
    		/* 3)페이지 이동 */
    		//확인할 대상이 삭제된 상태이므로 목록 페이지로 이동
    		return webHelper.redirect(contextPath + "/professor/list.do", "삭제되었습니다.");
    	}
    }

    ProfessorAjaxController.java

    더보기
    package study.spring.springhelper.controllers;
    
    import java.util.List;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.Model;
    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.servlet.ModelAndView;
    
    import study.spring.springhelper.helper.PageData;
    import study.spring.springhelper.helper.RegexHelper;
    import study.spring.springhelper.helper.WebHelper;
    import study.spring.springhelper.model.Department;
    import study.spring.springhelper.model.Professor;
    import study.spring.springhelper.service.DepartmentService;
    import study.spring.springhelper.service.ProfessorService;
    
    @Controller
    public class ProfessorAjaxController {
    	/* WebHelper 주입 */
    	// -->import org.springframework.beans.factory.annotation.Autowired;
    	// -->import study.spring.springhelper.helper.WebHelper;
    	@Autowired WebHelper webHelper;
    	
    	/* RegexHelper 주입 */
    	// --> import study.spring.springhelper.helper.RegexHelper;
    	@Autowired RegexHelper regexHelper;
    	
    	/* Service 패턴 구현체 주입 */
    	// --> import study.spring.springhelper.service.ProfessorService;
    	@Autowired ProfessorService professorService;
    	
    	// -->import study.spring.springhelper.service.DepartmentService;
    	@Autowired DepartmentService departmentService;
    	
    	/* "/프로젝트 이름"에 해당하는 ContextPath 변수 주입 */
    	// --> import org.springframework.beans.factory.annotation.Value;
    	@Value("#{servletContext.contextPath}")
    	String contextPath;
    	
    	/* 목록페이지 */
    	@RequestMapping(value="/professor/list_ajax.do", method = RequestMethod.GET)
    	public ModelAndView list(Model model,
    			//검색어
    			@RequestParam(value="keyword", required=false) String keyword,
    			//페이지 구현에서 사용할 현재 페이지 번호
    			@RequestParam(value="page", defaultValue="1") int nowPage) {
    		
    		/* 1)페이지 구현에 필요한 변수값 생성 */
    		int totalCount = 0;		//전체 게시글 수
    		int listCount = 10;		//한 페이지당 표시할 목록 수
    		int pageCount = 5;		//한 그룹당 표시할 페이지 번호 수
    		
    		/* 2)데이터 조회하기 */
    		//조회에 필요한 조건값 (검색어)를 Beans에 담는다.
    		Professor input = new Professor();
    		input.setName(keyword);
    		
    		List<Professor> output = null; //조회결과가 저장될 객체
    		PageData pageData = null;		//페이지 번호를 계산한 결과가 저장될 객체
    		
    		try {
    			//전체 게시글 수 조회
    			totalCount = professorService.getProfessorCount(input);
    			//페이지 번호 계산 --> 계산결과를 로그로 출력될 것이다.
    			pageData = new PageData(nowPage, totalCount, listCount, pageCount);
    			
    			//SQL의 Limit절에서 사용될 값을 Beans의 static 변수에 저장
    			Professor.setOffset(pageData.getOffset());
    			Professor.setListCount(pageData.getListCount());
    			
    			//데이터 조회하기
    			output = professorService.getProfessorList(input);
    		}catch(Exception e) {
    			return webHelper.redirect(null, e.getLocalizedMessage());
    		}
    		
    		/* 3)View 처리 */
    		model.addAttribute("keyword", keyword);
    		model.addAttribute("output", output);
    		model.addAttribute("pageData", pageData);
    		
    		
    		return new ModelAndView("professor/list_ajax");
    		}
    	
    	/* 상세페이지 */
    	@RequestMapping(value="/professor/view_ajax.do", method = RequestMethod.GET)
    	public ModelAndView view(Model model,
    			@RequestParam(value="profno", defaultValue="0") int profno) {
    		/* 1)유효성 검사 */
    		//이 값이 존재하지 않는다면 데이터 조회가 불가능하므로 반드시 필수값으로 처리해야 한다.
    		if(profno ==0) {
    			return webHelper.redirect(null, "교수번호가 없습니다.");
    		}
    		
    		/* 2)데이터 조회하기 */
    		//데이터 조회에 필요한 조건값을 Beans에 저장하기
    		Professor input = new Professor();
    		input.setProfno(profno);
    		
    		//조회결과를 저장할 객체 선언
    		Professor output = null;
    		
    		try {
    			//데이터 조회
    			output = professorService.getProfessorItem(input);
    		}catch(Exception e) {
    			return webHelper.redirect(null, e.getLocalizedMessage());
    		}
    		
    		/* 3)View 처리 */
    		model.addAttribute("output", output);
    		return new ModelAndView("professor/view_ajax");
    	}
    	
    	/* 작성 폼 페이지 */
    	@RequestMapping(value="/professor/add_ajax.do", method = RequestMethod.GET)
    	public ModelAndView add(Model model) {
    		
    		/* 학과목록 조회하기 */
    		//조회 결과를 저장할 객체 선언
    		List<Department> output = null;
    		
    		try {
    			//데이터 조회 --> 검색조건 없이 모든 학과 조회
    			output = departmentService.getDepartmentList(null);
    		}catch(Exception e) {
    			return webHelper.redirect(null, e.getLocalizedMessage());
    		}
    		
    		//View에 추가
    		model.addAttribute("output", output);
    		return new ModelAndView("professor/add_ajax");
    	}
    	
    
    	
    	/* 수정 폼 페이지 */
    	@RequestMapping(value="/professor/edit_ajax.do", method = RequestMethod.GET)
    	public ModelAndView edit(Model model,
    			@RequestParam(value="profno", defaultValue="0")int profno) {
    		
    		/* 1)파라미터 유효성 검사 */
    		//이 값이 존대하지 않는다면 데이터 조회가 불가능하므로 반드시 필수값으로 처리해야 한다.
    		if(profno == 0) {
    			return webHelper.redirect(null, "교수번호가 없습니다.");
    		}
    		
    		/* 2)데이터 조회하기 */
    		//데이터 조회에 필요한 조건값을 Beans에 저장하기
    		Professor input = new Professor();
    		input.setProfno(profno);
    		
    		//교수 조회 결과를 저장할 객체 선언
    		Professor output = null;
    		
    		//학과목록을 선택할 수 있는 드롭다운을 위한 조회결과를 저장할 객체 선언
    		List<Department> deptList = null;
    		
    		try {
    			//교수 기본 정보 조회
    			output = professorService.getProfessorItem(input);
    			//드롭다운을 위한 학과목록 조회
    			deptList = departmentService.getDepartmentList(null);
    		}catch(Exception e) {
    			return webHelper.redirect(null, e.getLocalizedMessage());
    		}
    		
    		/* 3)View 처리 */
    		model.addAttribute("output", output);
    		model.addAttribute("deptList", deptList);
    		return new ModelAndView("professor/edit_ajax");
    		
    	}
    	
    	
    	
    	
    	
    }
    

     


    ProfessorRestController.java

    더보기
    package study.spring.springhelper.controllers;
    
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.web.bind.annotation.PathVariable;
    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.RestController;
    
    import study.spring.springhelper.helper.PageData;
    import study.spring.springhelper.helper.RegexHelper;
    import study.spring.springhelper.helper.WebHelper;
    import study.spring.springhelper.model.Professor;
    import study.spring.springhelper.service.DepartmentService;
    import study.spring.springhelper.service.ProfessorService;
    
    @RestController
    public class ProfessorRestController {
    	/* WebHelper 주입 */
    	// --> import org.springframework.beans.factory.annotation.Autowired;
    	// --> import study.spring.springhelper.helper.WebHelper;
    	@Autowired WebHelper webHelper;
    	
    	/* RegexHelper 주입 */
    	// -->import study.spring.springhelper.helper.RegexHelper;
    	@Autowired RegexHelper regexHelper;
    	
    	/* Service 패턴 구현체 주입 */
    	// --> import study.spring.springhelper.service.ProfessorService;
    	@Autowired ProfessorService professorService;
    	
    	// -->import study.spring.springhelper.servie.DepartmentService
    	@Autowired DepartmentService departmentService;
    	
    	/* 목록페이지 */
    	@RequestMapping(value="/professor", method=RequestMethod.GET)
    	public Map<String, Object> get_list(
    			//검색어
    			@RequestParam(value="keyword", required=false) String keyword,
    			//페이지 구현에서 사용할 현재 페이지 번호
    			@RequestParam(value="page", defaultValue="1") int nowPage){
    		/* 1) 페이지 구현에 필요한 변수값 생성 */
    		int totalCount = 0; 	//전체 게시글 수
    		int listCount = 10;		//한 페이지당 표시할 목록 수
    		int pageCount = 5;		//한 그룹당 표시할 페이지 번호 수
    		
    		/* 2)데이터 조회하기 */
    		//조회에 필요한 조건값(검색어)를 Beans에 담는다.
    		Professor input = new Professor();
    		input.setName(keyword);
    		
    		List<Professor> output = null; // 조회결과가 저장될 객체
    		PageData pageData = null;		//페이지 번호를 계산한 결과가 저장될 객체
    		
    		try {
    			//전체 게시글 수 조회
    			totalCount = professorService.getProfessorCount(input);
    			//페이지 번호 계산 --> 계산결과를 로그로 출력될 것이다.
    			pageData = new PageData(nowPage, totalCount, listCount, pageCount);
    			
    			//SQL의 LIMIT절에서 사용될 값을 Beans의 static 변수에 저장
    			Professor.setOffset(pageData.getOffset());
    			Professor.setListCount(pageData.getListCount());
    			
    			//데이터 조회하기
    			output = professorService.getProfessorList(input);
    		}catch(Exception e) {
    			return webHelper.getJsonError(e.getLocalizedMessage());
    		}
    		/* 3)JSON 출력하기 */
    		Map<String, Object> data = new HashMap<String, Object>();
    		data.put("keyword", keyword);
    		data.put("item", output);
    		data.put("meta", pageData);
    		return webHelper.getJsonData(data);
    		
    	}
    	
    	/* 상세페이지 */
    	@RequestMapping(value="/professor/{profno}", method=RequestMethod.GET)
    	public Map<String, Object> get_item(@PathVariable("profno") int profno){
    		
    		/* 1) 데이터 조회하기 */
    		//데이터 조회에 필요한 조건값을 Beans에 저장하기
    		Professor input = new Professor();
    		input.setProfno(profno);
    		
    		//조회결과를 저장할 객체 선언
    		Professor output = null;
    		
    		try {
    			//데이터 조회
    			output = professorService.getProfessorItem(input);
    		}catch(Exception e) {
    			return webHelper.getJsonError(e.getLocalizedMessage());
    		}
    		
    		/* 2)JSON 출력하게 */
    		Map<String, Object> data = new HashMap<String, Object>();
    		data.put("item", output);
    
    		return webHelper.getJsonData(data);
    		
    	}
    	
    	/* 작성 폼에 대한 action 페이지 */
    	@RequestMapping(value="/professor", method=RequestMethod.POST)
    	public Map<String, Object> post(
    			@RequestParam(value="name", required=false) String name,
    			@RequestParam(value="userid", required=false) String userid,
    			@RequestParam(value="position", required=false) String position,
    			@RequestParam(value="sal", defaultValue="0") int sal,
    			@RequestParam(value="hiredate", required=false) String hiredate,
    			@RequestParam(value="comm", required=false) Integer comm,
    			@RequestParam(value="deptno", defaultValue="0") int deptno){
    		
    		/* 1)사용자가 입력한 파라미터에 대한 유효성 검사 */
    		//일반 문자열 입력 컬럼 --> String으로 파라미터가 선언되어 있는 겨우는 값이 입력되지 않으면 빈 문자열로 처리된다.
    		if(name.equals(""))					{return webHelper.getJsonWarning("이름을 입력하세요."); }
    		if(!regexHelper.isKor(name))		{return webHelper.getJsonWarning("이름은 한글만 가능합니다."); }
    		if(userid.equals(""))				{return webHelper.getJsonWarning("아이디를 입력하세요."); }
    		if(!regexHelper.isEngNum(userid))	{return webHelper.getJsonWarning("아이디는 영어와 숫자로만 가능합니다."); }
    		if(hiredate.equals(""))				{return webHelper.getJsonWarning("입사일을 입력하세요"); }
    		
    		//null을 허용하는 형태인 경우 int에 대응하는 Integer로 처리하였다
    		if(position == null)				{return webHelper.getJsonWarning("직급을 입력하세요.");}
    		
    		//숫자형으로 선언된 파라미터()
    		if(sal == 0) 						{return webHelper.getJsonWarning("급여를 입력하세요");}
    		if(sal < 0)  						{return webHelper.getJsonWarning("급여는 0보다 작을 수 없습니다.");}
    		if(comm < 0)  						{return webHelper.getJsonWarning("보직수당은 0보다 작을 수 없습니다.");}
    		if(deptno == 0)  					{return webHelper.getJsonWarning("소속 학과 번호를 입력하세요");}
    		
    		/* 2) 데이터 저장하기 */
    		Professor input = new Professor();
    		input.setName(name);
    		input.setUserid(userid);
    		input.setPosition(position);
    		input.setSal(sal);
    		input.setHiredate(hiredate);
    		input.setComm(comm);
    		input.setDeptno(deptno);
    		
    		//저장된 결과를 조회하기 위한 객체
    		Professor output = null;
    		
    		try {
    			//데이터 저장
    			//--> 데이터 저장에 성공하면 파라미터로 전달하는 input 객체에 Pk갑이 저장된다.
    			professorService.addProfessor(input);
    			
    			//데이터 조회
    			output = professorService.getProfessorItem(input);
    		}catch(Exception e) {
    			return webHelper.getJsonError(e.getLocalizedMessage());
    		}
    		
    		/* 3)결과를 확인하기 위한 JSON 출력 */
    		Map<String, Object> map = new HashMap<String, Object>();
    		map.put("item", output);
    		return webHelper.getJsonData(map);
    		
    		
    	}
    	
    	/* 수정 폼에 대한 action 페이지 */
    	@RequestMapping(value="/professor", method=RequestMethod.PUT)
    	public Map<String, Object> put(
    			@RequestParam(value="profno", defaultValue="0") int profno,
    			@RequestParam(value="name", required=false) String name,
    			@RequestParam(value="userid", required=false) String userid,
    			@RequestParam(value="position", required=false) String position,
    			@RequestParam(value="sal", defaultValue="0") int sal,
    			@RequestParam(value="hiredate", required=false) String hiredate,
    			@RequestParam(value="comm", required=false) Integer comm,
    			@RequestParam(value="deptno", defaultValue="0") int deptno){
    		
    		/* 1)사용자가 입력한 파라미터 유효성 검사 */
    		if(profno == 0) 					{return webHelper.getJsonWarning( "교수번호가 없습니다.");}
    		if(name == null) 					{return webHelper.getJsonWarning( "교수 이름을 입력하세요.");}
    		if(!regexHelper.isKor(name)) 		{return webHelper.getJsonWarning( "교수 이름은 한글만 가능합니다.");}
    		if(userid == null) 					{return webHelper.getJsonWarning( "교수 아이디를 입력하세요.");}
    		if(!regexHelper.isEngNum(userid)) 	{return webHelper.getJsonWarning( "교수 아이디는 영어와 숫자로만 가능합니다..");}
    		if(position == null) 				{return webHelper.getJsonWarning( "직급을 입력하세요.");}
    		if(sal == 0) 						{return webHelper.getJsonWarning( "급여를 입력하세요.");}
    		if(sal < 0) 						{return webHelper.getJsonWarning( "급여는 0보다 작을 수 없습니다.");}
    		if(hiredate == null) 				{return webHelper.getJsonWarning( "입사일을 입력하세요.");}
    		if(comm < 0) 						{return webHelper.getJsonWarning( "보직수당은 0보다 작을 수 없습니다.");}
    		if(deptno == 0) 					{return webHelper.getJsonWarning( "소속 학과 번호를 입력하세요.");}
    		
    		/* 2) 데이터 수정하기 */
    		//수정할 값들을 Beans에 담는다.
    		Professor input = new Professor();
    		input.setProfno(profno);
    		input.setName(name);
    		input.setUserid(userid);
    		input.setPosition(position);
    		input.setSal(sal);
    		input.setHiredate(hiredate);
    		input.setComm(comm);
    		input.setDeptno(deptno);
    		
    		//수정된 결과를 조회하기 위한 객체
    		Professor output = null;
    		
    		try {
    			//데이터 수정
    			professorService.editProfessor(input);
    			//수정결과 조회
    			output = professorService.getProfessorItem(input);
    		}catch(Exception e) {
    			return webHelper.getJsonError(e.getLocalizedMessage());
    		}
    		/* 3)결과를 확인하기 위한 JSON 출력 */
    		Map<String, Object> map = new HashMap<String, Object>();
    		map.put("item", output);
    		return webHelper.getJsonData(map);
    		
    		
    	}
    	
    	/* 삭제처리 */
    	@RequestMapping(value="/professor", method=RequestMethod.DELETE)
    	public Map<String, Object> delete(
    			@RequestParam(value="profno", defaultValue="0") int profno){
    		/* 1)파라미터 유효성 검사 */
    		//이 값이 존재하지 않는다면 데이터 삭제가 불가능하므로 반드시 필수값으로 처리해야 한다.
    		if(profno == 0) {
    			return webHelper.getJsonWarning("교수 번호가 없습니다.");
    		}
    		/* 2)데이터 삭제하기 */
    		//데이터 삭제에 필요한 조건값을 Beans에 저장하기
    		Professor input = new Professor();
    		input.setProfno(profno);
    		
    		try {
    			professorService.deleteProfessor(input);// 데이터 삭제
    		}catch(Exception e) {
    			return webHelper.getJsonError(e.getLocalizedMessage());
    		}
    		/* 3)결과를 확인하기 위한 JSON 출력 */
    		//확인할 대상이 삭제된 결과값만 OK로 전달
    		return webHelper.getJsonData();
    		
    	}
    }
    
    

    이렇다 일단 위의 컨트롤러와 연결된 jsp 파일들을 보면

    이와 같은데 ProfessorController와 ProfessorAjaxController가 똑같은 기능을 하는데 다른 방법인것 같고 ProfessorRestController는 어떤 기능을 하는지 고민해보는 시간이 필요하였다.

     

    고민은 잠시 접어 두기로 했다

    mangkyu.tistory.com/49 << 여기에 @Controller와 @RestController 차이 확인.

     

    그냥 ProfessorController로 하는 것으로 일단 정함 가만 보니까 저 둘의 차이가 ajax를 쓰고 안쓰고의 방법의 차이 같다.

     

전설의 개발자