귤치치
40
2021-01-30 16:20:43 작성 2021-01-30 16:25:14 수정됨
1
163

404 잘못된 요청 사원정보 입력하는데 값이 안 넘어가는 것 같아요 도무지 왜 그런지 모르겠어요 ㅠㅠ



이거는 controller이구요.

package edu.bit.ex.emp.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import edu.bit.ex.emp.service.EmpService;
import edu.bit.ex.emp.vo.DeptVO;
import edu.bit.ex.emp.vo.EmpVO;
import lombok.AllArgsConstructor;
import lombok.extern.log4j.Log4j;

@Log4j
@AllArgsConstructor
@Controller
public class EmpController {
	
	private EmpService empService;
	
	@GetMapping("/list")
	public void list(Model model) {
		log.info("list");
		model.addAttribute("list",empService.getList());	
	}
	
	@GetMapping("/insert_view")
	public void insert_view(Model model1,Model model2) {
		log.info("insert_view");

		model1.addAttribute("emp",empService.getEmp());
		model2.addAttribute("dept",empService.getDept());
	}
	
	@PostMapping("/insert")
	public String insert(EmpVO empVO,DeptVO deptVO,Model model) {
		log.info("insert");
		empService.writeEmp(empVO);
		//empService.writeDept(deptVO);
		return "redirect:list";
	}

}
package edu.bit.ex.emp.service;

import java.util.List;

import org.springframework.stereotype.Service;

import edu.bit.ex.emp.mapper.EmpMapper;
import edu.bit.ex.emp.vo.DeptVO;
import edu.bit.ex.emp.vo.EmpDeptVO;
import edu.bit.ex.emp.vo.EmpVO;

import lombok.AllArgsConstructor;
import lombok.extern.log4j.Log4j;
import lombok.extern.log4j.Log4j2;


@Log4j
@AllArgsConstructor
@Service
public class EmpServiceImpl implements EmpService{
	
	private EmpMapper mapper;
	
	@Override
	public List<EmpVO> getEmp() {
		log.info("List<EmpDeptVO> getEmp()");
		return mapper.getEmp();
	}

	@Override
	public List<DeptVO> getDept() {
		log.info("List<EmpDeptVO> getDept()");
		return mapper.getDept();
	}

	@Override
	public List<EmpDeptVO> getList() {
		log.info("List<EmpDeptVO> getList()");
		return mapper.getList();

	}

	@Override
	public void writeEmp(EmpVO empVO) {
		log.info("writeEmp");
		
		mapper.writeEmp(empVO);
	}

	@Override
	public void writeDept(DeptVO deptVO) {
		log.info("writeDept");
		mapper.writeDept(deptVO);
	}

}

package edu.bit.ex.emp.mapper;

import java.util.List;

import edu.bit.ex.emp.vo.DeptVO;
import edu.bit.ex.emp.vo.EmpDeptVO;
import edu.bit.ex.emp.vo.EmpVO;

public interface EmpMapper {

	public List<EmpVO> getEmp();

	public List<DeptVO> getDept();

	public List<EmpDeptVO> getList();

	public void writeEmp(EmpVO empVO);

	public void writeDept(DeptVO deptVO);

}

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
  PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="edu.bit.ex.emp.mapper.EmpMapper">
   
   <select id="getEmp" resultType="edu.bit.ex.emp.vo.EmpVO">
   <![CDATA[
      select * from emp
   ]]>
   </select>
   
     <select id="getDept" resultType="edu.bit.ex.emp.vo.DeptVO">
   <![CDATA[
      select * from dept
   ]]>
   </select>
   
      <select id="getList" resultType="edu.bit.ex.emp.vo.EmpDeptVO">
   <![CDATA[
      select * from emp,dept where emp.deptno = dept.deptno
   ]]>
   </select>
   
  	<insert id="writeEmp" parameterType="edu.bit.ex.emp.vo.EmpVO">
   <![CDATA[
      INSERT
        INTO EMP (EMPNO, ENAME, JOB, HIREDATE, SAL, COMM, DEPTNO)
        VALUES (#{empno}, #{ename}, #{job}, #{hiredate}, #{sal}, #{comm}, #{deptno})
   ]]>
   </insert>
   
    <insert id="writeDept" >
   <![CDATA[
     insert into dept (deptno) values (#{deptno})
   ]]>
   </insert>
   
   
	
   
</mapper>

package edu.bit.ex.emp.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Data
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class DeptVO {
//	이름     널?       유형           
//			------ -------- ------------ 
//			DEPTNO NOT NULL NUMBER(2)    
//			DNAME           VARCHAR2(14) 
//			LOC             VARCHAR2(13) 
	
	private int deptno;
	private String dname;
	private String loc;
	
}


package edu.bit.ex.emp.vo;

import java.sql.Timestamp;

import org.springframework.stereotype.Service;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.extern.log4j.Log4j;

@NoArgsConstructor
@AllArgsConstructor
@Data
@Getter
@Setter
public class EmpVO {
//	이름       널?       유형           
//			-------- -------- ------------ 
//			EMPNO    NOT NULL NUMBER(4)    
//			ENAME             VARCHAR2(10) 
//			JOB               VARCHAR2(9)  
//			MGR               NUMBER(4)    
//			HIREDATE          DATE         
//			SAL               NUMBER(7,2)  
//			COMM              NUMBER(7,2)  
//			DEPTNO            NUMBER(2)    
	
	private int empno;
	private String ename;
	private String job;
	private int mgr;
	private Timestamp hiredate;
	private int sal;
	private int comm;
	private int deptno;

}
이거는 insert_view 이구요

<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>사원 정보 입력</title>
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

	<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
	<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
	<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  
  	<script>
		$( function() {
			$( "#datepicker" ).datepicker();
		} );
  </script>

</head>
<body>
	<h1>사원 정보 입력</h1>
	<hr width="250" align="left"/>
	<form action="insert" method="post">
		사원번호<input type="text" name="empno"><br/>
		사원이름<input type="text" name="ename"><br/>
		사원직급<input type="text" name="job"><br/>
		매니저&nbsp;&nbsp; 
		<select name="mgr">
			<c:forEach var="emp" items="${emp}">
				<option value="${emp.mgr}">(${emp.empno})${emp.ename}</option>
			</c:forEach>
		</select><br/>
		입사일&nbsp;&nbsp;  <input id="datepicker" type="text" name="hiredate"><br/>
		급여&nbsp; &nbsp; &nbsp; <input type="text" name="sal"><br/>
		커미션  &nbsp;  <input type="text" name="comm"><br/>
		부서	&nbsp;&nbsp; &nbsp;  
		<select name="deptno">
			<c:forEach var="dept" items="${dept}">
				<option value="${dept.deptno}">(${dept.deptno})${dept.dname}</option>
			</c:forEach>
		</select><br/>
		<br/>
		<input type="submit" value="입력">
	</form>
</body>
</html>
이거는 list 입니다

<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>empList</title>

</head>
<body>
	<table border="1">
		<tr>
			<td>사람번호</td>
			<td>사람이름</td>
			<td>직무(업무)</td>
			<td>상사(이름)</td>
			<td>입사일</td>
			<td>급여</td>
			<td>커미션</td>
			<td>부서번호</td>
			<td>부서이름</td>
			<td>부서위치</td>
			<td>관리</td>
		</tr>
		<c:forEach items="${list}" var="dto">
		<tr>
			<td>${dto.empno}</td>
			<td>${dto.ename}</td>
			<td>${dto.job}</td>
			<td>${dto.mgr}</td>
			<td>${dto.hiredate}</td>
			<td>${dto.sal}</td>
			<td>${dto.comm}</td>
			<td>${dto.deptno}</td>
			<td>${dto.dname}</td>
			<td>${dto.loc}</td>
			<td>수정</td>
		</c:forEach>
		</tr>
		<tr>
			<td colspan="11"><input type="button" value="사원입력"></td>
		</tr>
	</table>
</body>
</html>





리스트에서 사원정보 입력으로 잘 넘어와서 입력을 누르면 안나와요ㅠㅠ
밑에 write 라고 info 가 안뜨는 걸로 봐서 실행이 아예 안되나 본데 왜 그런지 도무지 모르겠어요 ㅠㅠㅠㅠ 값이 안 넘어가는 건지 마이바티스가 잘 못된건지 하나도 모르겠어요ㅠㅠㅠ
제발 가르쳐주세요 공부한지 이제 두달 되었어요 오류날 때마다 멘붕이에요 ㅠㅠㅠ










0
  • 답변 1

  • Carefully
    415
    2021-01-30 21:21:11

    400 에러면.. 파라미터 불일치인듯한데

    1. 화면에서 입력누르면 넘어가기전에 값 제대로 맞게 들어갔는지 확인

    2. 컨트롤러로 값 제대로 넘어오는지 확인

    3. 쿼리까지 값 제대로 넘어가는지 확인

    디버깅을 돌리시거나 각각 콘솔창에 출력해보시면 될거에요, 그리고 값 확인하는거는 자료형도 맞는지 확인하시구요. db에 int로 해놓고 정작 넘기는건 string으로 넘긴다던지.. 몇번 겪어보면 환장합니다 ㅋㅋ

  • 로그인을 하시면 답변을 등록할 수 있습니다.