티스토리 뷰
728x90
- 날짜로 검색
- 포맷
- LocalDateTime 객체에 시간 입력 하는 방법
if(startDateTime == null && endDateTime != null){
startDateTime = LocalDateTime.of(1970, Month.JANUARY, 1,0,0);
BooleanExpression dateCondition = qRollbook.createDate.between(startDateTime, endDateTime);
conditions = defaultConditions.and(dateCondition);
System.out.println(conditions);
} else if( startDateTime != null && endDateTime == null){
endDateTime = LocalDateTime.of(2060, Month.DECEMBER, 31, 12, 59);
BooleanExpression dateCondition = qRollbook.createDate.between(startDateTime, endDateTime);
conditions = defaultConditions.and(dateCondition);
System.out.println(conditions);
if(search.getRollbookDate() != null){
String yearMonthStr = search.getRollbookDate().substring(0, 7); // 'yyyy-MM' 부분만 추출
YearMonth yearMonth = YearMonth.parse(yearMonthStr);
LocalDateTime startOfMonth = yearMonth.atDay(1).atStartOfDay();
LocalDateTime endOfMonth = yearMonth.atEndOfMonth().atTime(23, 59, 59);
BooleanExpression dateCondition = qRollbook.createDate.between(startOfMonth, endOfMonth);
conditions = conditions.and(dateCondition);
}
위 코드에서 substring(0, 7) 부분은 문자열의 처음부터 7번째 인덱스 직전까지의 부분문자열을 반환합니다. 따라서 '2023-09-01'에서 '2023-09' 부분만 반환합니다.
그런 다음 이 값을 YearMonth.parse() 메소드에 전달하여 YearMonth 객체를 생성합니다.
- 검색 최종
/** 날짜로 검색 **/
if(search.getRollbookDate() != null && !search.getRollbookDate().isEmpty()){
String yearMonthStr = search.getRollbookDate().substring(0, 7); // 'yyyy-MM' 부분만 추출
YearMonth yearMonth = YearMonth.parse(yearMonthStr);
LocalDateTime startOfMonth = yearMonth.atDay(1).atStartOfDay();
LocalDateTime endOfMonth = yearMonth.atEndOfMonth().atTime(23, 59, 59);
BooleanExpression dateCondition = qRollbook.createDate.between(startOfMonth, endOfMonth);
conditions = conditions.and(dateCondition);
}
위 코드에서 !search.getRollbookDate().isEmpty() 부분은 getRollbookDate() 메소드가 빈 문자열('')을 반환하는지 확인합니다. 만약 getRollbookDate() 메소드가 null이거나 빈 문자열을 반환한다면 날짜 범위 조건을 생성하지 않고 기존의 검색 조건만 사용합니다.
또한 이러한 방식으로 처리하면 입력된 문자열이 'yyyy-MM' 형식에 맞지 않는 경우에도 예외가 발생하지 않습니다. 왜냐하면 'yyyy-MM' 형식에 맞지 않는 문자열은 무시되고 기존의 검색 조건만 사용되기 때문입니다. 하지만 이렇게 하면 사용자가 잘못된 형식의 날짜를 입력했음에도 불구하고 그 사실을 알 수 없게 됩니다. 따라서 잘못된 형식의 날짜를 입력한 경우 사용자에게 오류 메시지를 표시하는 등의 추가적인 처리가 필요할 수 있습니다.
- queryDsl 코드 공부
- 날짜별 조회 하는 기준인데 자세히 이해 안됨;
if (search.getStartDateTime() != null) {
LocalDateTime startOfDay = search.getStartDate().atStartOfDay();
conditions = conditions.and(qDocumentApproval.updateDate.goe(startOfDay));
}
if (search.getEndDateTime() != null) {
LocalDateTime endOfDay = search.getEndDate().atTime(23, 59, 59);
conditions = conditions.and(qDocumentApproval.createDate.loe(endOfDay));
}
위 코드에서는 LocalDate.parse() 메소드를 사용하여 문자열 값을 LocalDate 객체로 변환합니다. 그리고 이 객체의 atStartOfDay() 및 atTime() 메소드를 사용하여 그 날의 시작과 종료 시각을 나타내는 LocalDateTime 객체를 얻습니다.
그리고 이 두 날짜/시간 사이에 있는 데이터만 선택하는 새로운 조건을 생성하여 기존의 검색 조건과 결합합니다.
여기서 가정한 것은 'createDate' 및 'updateDate' 필드가 LocalDateTime 형식임입니다. 만약 다른 이름의 필드나 다른 형식의 필드를 사용한다면 적절히 수정해야 합니다.
- 전자결재, 전자결재 관리자 날짜 검색 추가
- selectBox 에 들어있는 번호 받아오는 방법
// 클래스 명을 넣어 주고
let checkboxes = document.getElementsByClassName("modify-chk");
let rollbookNo = 0;
// 포문으로 돌리면서 checkBox 에있는 값을 반영해주면 됨 끝~
for(let i=0; i<checkboxes.length; i++){
if(checkboxes[i].checked){
rollbookNo = checkboxes[i].value;
console.log(rollbookNo)
}
}
728x90
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 셀프로젝트
- 다른데서 react
- reactApp
- 제약조건
- ID
- 아이디
- C
- 셀렉트박스
- 다중체크박스 처리
- @reqeustBody
- JPA
- SCP
- th:selected
- @RequestParam
- selectbox
- optional
- commit 에러
- CheckBox
- App
- findFirstBy
- 받아오기
- 서버전송
- react 시작 오류
- reactStart
- React
- C언어
- 체크박스
- 씹어먹는 C 언어
- mircrosoft visual studio
- @Builder
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함