일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- go 대기그룹
- air 환경변수
- go air
- gin middleware
- 골랑 고퍼
- go clean architecture
- go middleware
- go 맥 air
- 고루틴 채널
- go 환경변수
- go air 환경변수
- 신입개발자
- clean architecture middleware
- 좀비고루틴
- 2년차개발자
- golang gopher
- go
- go panic
- go channel
- gin recovery
- gin logger
- go 맥
- go 캐릭터
- go디자인패턴
- go 맥 air 환경변수
- go 마스코트
- gopath 환경변수
- go recover
- 개발자
- git
Archives
- Today
- Total
뽀미의 개발노트
mybatis에서 if and 쓸 때 + jstl에서 if and 쓸 때 본문
mapper에서 mybatis 문법 쓸 때 if 조건문으로 쿼리문 조금씩 다르게 날릴때는
if 에서 || && 이런거 말고 and 랑 or 로 써야함!!
<select id="getArticles" resultType="Article">
<if test="boardId == 2 or boardId == 5">
WITH AMG AS (
</if>
SELECT A.*, M.name AS writerName, IFNULL(G.groupName,'전체') AS groupName
FROM article AS A
INNER JOIN `member` AS M
ON A.memberId = M.id
LEFT JOIN `group` AS G
ON A.classId = G.id
WHERE boardId = #{boardId}
<if test="boardId != 2 and boardId != 5">
ORDER BY A.id DESC;
</if>
<if test="boardId == 2">
)
SELECT AMG.*, IF(COUNT(H.hwMsg) = 0, '미검사','검사') AS 'hwChk'
FROM AMG
LEFT JOIN `homework` AS H
ON AMG.id = H.relId
GROUP BY AMG.id
ORDER BY AMG.id DESC;
</if>
<if test="boardId == 5">
)
SELECT AMG.*, F.id AS fileId
FROM AMG
LEFT JOIN `file` AS F
ON AMG.id = F.relId
GROUP BY AMG.id
ORDER BY AMG.id DESC;
</if>
</select>
예를 들어 이렇게 말이다!!
나는 하나의 list로 네개의 보드를 구분해서 관리하고 있어서 쿼리문을 다르게 날릴 필요가 있다.
각자 성격이 달라서 list 페이지를 나누고 싶었으나 그러면 수정 삭제 목록 버튼 링크도 다 수정해줘야하기에 저렇게 나눠서 했다. (성격이 너무 다른 하나의 보드만 따로 뺐다.)
참고한 블로그
https://java119.tistory.com/42
[MyBatis] 동적 쿼리 if문 문법 총 정리
시작하기에앞서 참고 자료 *ibatis 비교문 지원 태그 isNull : "널일경우" isNotNull : "널이아닐경우" isEmpty : "공백일경우" isNotEmpty : "공백이아닐경우" isGreaterTan : ">" isGreaterEqual : ">=" isLessThan : "" 괄호를
java119.tistory.com
또한 html에서 c태그중 <c:if test="~"> 이거 쓸 때는 and랑 or 어떻게 쓰냐?!
이때는 그냥 || 랑 && 써도 된다고 한다.
<c:if test="${article.boardId == 2 && rq.getLoginedMember().getAuthLevel() == 1}">
<c:choose>
<c:when test="${homeworks.isEmpty() }">
<div>
<a class="homeworkChk btn btn-success mr-2"
onclick="getStudentsByClass(${article.id},${article.classId});">과제검사</a>
</div>
</c:when>
<c:otherwise>
<div>
<a class="getHws btn btn-success btn-outline mr-2">과제확인</a>
</div>
</c:otherwise>
</c:choose>
</c:if>
요렇겡!!!
참고한 블로그
[Jsp] jstl if문에서 and와 or문 사용하는 방법
jstl if문에서 and와 or문 사용하는 방법 and ... or ... 출처: https://yangyag.tistory.com/112 [Hello Brother!]
kmhan.tistory.com
'Trouble_Shooting' 카테고리의 다른 글
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured. 오류 해결 (1) | 2023.06.15 |
---|---|
import에서 type이 not accessible 하다는 문제 (아직 해결 못함) (0) | 2023.06.14 |
ajax에서 promise 쓰기 (0) | 2023.06.09 |
table에서 th z-index 처리하기 (2) | 2023.06.08 |
mysql에서 WITH AS 자꾸 오류 났던 이유... (3) | 2023.05.28 |