[Spring_Error]java.sql.SQLIntegrityConstraintViolationException: Column 'content' cannot be null
스프링으로 웹 게시판 만들다가 아래와 같은 오류를 맞딱드렸음.
org.springframework.dao.DataIntegrityViolationException:
### Error updating database. Cause: java.sql.SQLIntegrityConstraintViolationException: Column 'content' cannot be null
### The error may exist in com/wsy/wsyweb/mapper/BoardMapper.xml
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: insert into tbl_board(title, content, writer) values(?, ?, ?)
### Cause: java.sql.SQLIntegrityConstraintViolationException: Column 'content' cannot be null
; Column 'content' cannot be null; nested exception is java.sql.SQLIntegrityConstraintViolationException: Column 'content' cannot be null
컬럼 content는 null이 되면 안 된다는 뜻.
MySQL에서 생성한 테이블의 content 열이 NN(Not Null) 설정되어 있기 때문에 데이터를 받아와야하는데
데이터를 받아오지 못하는 것.
<!-- 글 등록 -->
<insert id="insert">
insert into tbl_board(title, content, writer)
values(#{title}, #{content}, #{writer})
<!-- bno 자동 증가, regdate/updatedate는 자동입력 -->
</insert>
내 경우엔,
register.jsp - 입력 폼을 생성해 사용자가 데이터를 입력하게끔하는 곳에서
<input> 태그에 name 설정을 안 해줬기 때문.
<table class="tbl-content">
<tr> <!--★-->
<th colspan="3"><input type="text" class="title-txt" name="title" placeholder="제목을 입력하세요."></th>
</tr>
<tr>
<td class="tbl-field-form">작성자</td>
<td class="tbl-field-form-writer">
<input type="text" id="writer" name="writer"><!--★-->
</td>
<td class="tbl-content-btn"></td>
</tr>
<tr>
<td class="tbl-content-content" colspan="3">
<textarea name="content" rows="7" cols="150" placeholder="내용을 입력하세요."></textarea>
</td> <!--★-->
</tr>
<tr>
<td colspan="3">
<button type="submit" class="board-btn">등록</button> <!-- 버튼누를 경우, controller -->
</td>
</tr>
</table>
name 설정할 때, 쿼리문의 이름과 같게 해야 함. 아니면 못 가져옴.