본문 바로가기
목차
MySQL

MySQL null값을 유의하자

by 지각생 2022. 2. 19.
728x90

<select id="getWritingList" resultType="com.MyBlog.Dto.Board">
		select * from board
		<where>
			<if test="query !=null and query != ''">
				${field} like '%${query}%'
			</if>

			and
			<if test="categoryName != ''">
				categoryName = #{categoryName}
			</if>

			<if test="categoryName ==''">
				categoryName like '%${categoryName}%'
			</if>
			and
			<if test="uri != '/index/category' ">
				nickName like '%%'
			</if>

			<if test="uri =='/index/category'">
				nickName = #{nickName}
			</if>

			and
			<if test="uri =='/index/category' or uri =='/index' ">
				channelName like '%%'
			</if>

			<if test="uri !='/index/category' and uri !='/index' ">
				channelName = #{channelName}
			</if>

			and pub = #{pub}
			order by ${order} ${desc}
			limit #{offset}, #{size}
		</where>
	</select>

 

지금은 해결 했으나

 

에러의 발단은

 

1. 쿼리 문 작성 중에 channelName 컬럼 기본 값은  null -> '' 로 변경 . 즉 공백값

 

2. 그 후 쿼리문에서는 channelName의 null값은 고려하지 않았다.

 

3. 그러나 기존에 생성된 null값에 의해 2 페이지로 넘어가도 null값 입력된 수의 갯수만큼 

 

게시글 개수가 일치하지 않았음.

 

==> DB table에 channelName컬럼 null data삭제

로 해결

728x90

댓글