ํฐ์คํ ๋ฆฌ ๋ทฐ
PostMapper.xml
<?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="com.hastagram.myapp.post.repository.IPostDAO">
<!-- ResultMap ์์ฑ -->
<resultMap type="com.hastagram.myapp.post.model.PostVO" id="PostResultMap">
<id property="postNo" column="post_no"/>
<result property="caption" column="caption"/>
<result property="regDate" column="reg_date"/>
<result property="userNo" column="user_no"/>
<result property="fileId" column="file_id" />
<result property="fileName" column="file_name" />
<result property="fileSize" column="file_size" />
<result property="fileContentType" column="file_content_type" />
</resultMap>
<resultMap type="com.hastagram.myapp.users.model.UsersVO" id="UsersResultMap">
<id property="userNo" column="user_no"/>
<result property="id" column="id"/>
</resultMap>
<!-- ๊ฒ์๋ฌผ ๋ฑ๋ก๊ณผ ํ์ผ ์ฒจ๋ถ -->
<insert id="insertPost">
insert into posts(caption, user_no, file_name, file_size, file_content_type, file_data)
values(#{caption}, #{userNo}, #{fileName}, #{fileSize}, #{fileContentType}, #{fileData})
</insert>
</mapper>
IPostDAO.java
package com.hastagram.myapp.post.repository;
import com.hastagram.myapp.post.model.PostsVO;
public interface IPostDAO {
//๊ฒ์๋ฌผ ๋ฑ๋ก(์ฌ์ง ์ฒจ๋ถํ์ผ ํฌํจ)
void insertPost(PostsVO post) throws Exception;
}
IPostsDAOTest.java
package com.hastagram.myapp.poststest;
import javax.inject.Inject;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.hastagram.myapp.posts.model.PostsVO;
import com.hastagram.myapp.posts.repository.IPostsDAO;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations= {"classpath:/spring/mvc-config.xml"})
public class PostsDAOTest {
//DAO ๊ฐ์ฒด
@Inject
private IPostsDAO postDAO;
//๊ฒ์๊ธ ๋ฑ๋ก ํ
์คํธ
@Test
public void insertTest() throws Exception{
for(int i=1; i<=10; i++) {
byte[] fileData = new byte[1024];
PostsVO post = new PostsVO();
post.setCaption(i + "๋ฒ์งธ post");
post.setUserNo(i);
post.setFileName("care.jpg");
post.setFileSize(379228);
post.setFileContentType("image/jpeg");
post.setFileData(fileData);
postDAO.insertPost(post);
}
}
}
ํ
์คํธ๋ฅผ ํ๋๋ฐ ์ด๋ฐ ์ค๋ฅ๊ฐ ๋ฐ์ํ๋ค. ๊ทธ ์ ์ ๋ค๋ฅธ ์ค๋ฅ๋ ์์๋๋ฐ ์คํ๋ก ์ธํ ์ค๋ฅ๋ค์ด์ด์ ์์ ํ๋ค.
Cannot add or update a child row: ์ด์ฉ๊ณ ์ ์ฉ๊ณ
์ฐธ์กฐ ๋ฌด๊ฒฐ์ฑ์ ๋ฐ๋ผ ์ฐธ์กฐํค๋ ํญ์ ๋ถ๋ชจํค์ ํด๋นํ๋ ๊ฐ๋ง ๋ฃ์ ์ ์๋ค. ์ฐธ์กฐ ๋ฐ๋ ํ ์ด๋ธ(posts)์ ๋จผ์ ๊ฐ์ ๋ฃ์ด์ ์๊ธฐ๋ ์ค๋ฅ๋ผ๊ณ ํ๋ค. ๊ทธ๋์ ์ฐ์ ์ฐธ์กฐ ์ ์ฝ ์กฐ๊ฑด์ ์ง์ฐ๊ณ ํ ์คํธ๋ฅผ ํ๋๋ ๋ฐ์ดํฐ๊ฐ ๋ฌด์ฌํ ๋ค์ด๊ฐ๋ค. ๊ทผ๋ฐ ์๊ฐ์ ํด๋ณด๋ ๊ตณ์ด ๋ ํ ์ด๋ธ๊ฐ์ ์ฐธ์กฐ ๊ด๊ณ๋ฅผ ๋ง๋ค์ง ์์๋ ๋ ๊ฒ๊ฐ๋ค๋ ์๊ฐ์ ํ๋ค. ํ์์ ๋ชจ๋ ์ ๋ณด๊ฐ ํ์ํ๊ฒ ์๋๊ณ ํ์ ์์ด๋๋ง ํ์ํ๋๊น ๊ทธ๋ฅ user_no๋ก ์์ด๋๋ง ์กฐํํด๋ ๋์ง ์์๊น.
- Total
- Today
- Yesterday
- ๋ณ๋ช ์ฒ๋ฆฌ
- Java
- ์ดํด๋ฆฝ์ค ์ค์น
- java jdk ์ค์น
- ๊ฒ์๋ฌผ์กฐํ
- ๊ฒ์ํ ์ญ์
- ์คํ๋ง๋ถํธ ์๋์์ฑ
- ์ ์ฒด๊ฒ์๋ฌผ ์กฐํ
- java ํ๊ฒฝ๋ณ์
- ์จ๋ฆฌ์์ค
- ์๋ฃ๊ตฌ์กฐ
- typeAliases
- ๊ฒ์ํ๋ง๋ค๊ธฐ
- ์ดํด๋ฆฝ์ค ํ๊ธ ์ธ์ฝ๋ฉ
- ๋ถํธ ์๋์์ฑ
- Algorithm
- ์๋ฐ
- ๊ฒ์๋ฌผ ์ญ์
- ๊ฐ๋ฐ
- tomcat์ค์น
- ์๊ณ ๋ฆฌ์ฆ
- mysql์ค์น
- ๊ฐ๋ฐํ๊ฒฝ๊ตฌ์ถ
- ๊ฒ์ํ ์กฐํ
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |