Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
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
Archives
Today
Total
관리 메뉴

아님말고

[mysql] 이전 이후 변경된 값 비교하기 본문

Java

[mysql] 이전 이후 변경된 값 비교하기

스타박씨 2023. 12. 26. 14:14

게시판의 이전값과 현재값의 변경 된 내용 확인하기

 

DB 조회하기

select
	case x
        when 1 then '제목'
        when 2 then '이메일'
        when 3 then '내용'
        end as chgColumnNm
        ,
	case x
        when 1 then bv.subject
        when 2 then bv.email
        when 3 then bv.contents
        end as beforeVal
        ,
	case x
        when 1 then av.subject
        when 2 then av.email
        when 3 then av.contents
        end as afterVal     
  from 
  	(select * 
           from board
          where idx = #{afterIdx}) av
        ,
  	(select * 
           from board
          where idx < #{afterIdx}
          order by idx desc
          limit 1) bv
        ,
  	(select 1 as x
         union all select 2 as x
         union all select 3 as x) b

 

DB 조회 결과에서 변경 요소 확인하기

//현재 idx값으로 이전 idx 데이터와 비교 조회하기
List<BoardVO> list = BoardRepository.selectBoardChange(afterIdx);

//변경없는 요소 제거
list.removeIf(t -> t.getAfterVal().equals(t.getBeforeVal()));

 

'Java' 카테고리의 다른 글

SoketExcepton connection reset 문제  (0) 2023.12.12
Kafka + Windows 설치 및 테스트  (0) 2023.08.23
[AWS] DynamoDB + local 설치  (0) 2023.08.22
Swagger + Spring Boot 3  (0) 2023.08.18
spring cloud gateway 에서의 swagger 사용시 주의  (0) 2023.08.09
Comments