<div class="owl-carousel owl-3-slider">
<!-- 사진 썸네일 알고리즘 -->
<%
InfoDAO idao = new InfoDAO();
String info_cate = "사진";
ArrayList<InfoDTO> pic_list = idao.topFive(info_cate);
for (int i = 0; i < pic_list.size(); i++) {
int info_num = pic_list.get(i).getInfo_num();
String htmlString = idao.show(info_num);
// 정규 표현식 패턴
String pattern = "<img\\s+[^>]*>";
// 정규 표현식 패턴에 매칭되는 부분을 찾아서 저장할 변수
StringBuilder imgTags = new StringBuilder();
// 정규 표현식에 매칭되는 부분을 찾기 위한 Matcher 객체 생성
Matcher matcher = Pattern.compile(pattern).matcher(htmlString);
// 맨 앞에있는 img태그만
if (matcher.find()) {
imgTags.append(matcher.group());
}
// imgTags가 비어있는 경우, 다음 반복으로 넘어감
if (imgTags.toString().isEmpty()) {
continue;
}
%>
<div class="item">
<a class="media-thumb reqlogin" href="Info_DetailPage.jsp?info_num=<%=pic_list.get(i).getInfo_num()%>&info_title=<%=pic_list.get(i).getInfo_title()%>&info_brief=<%=pic_list.get(i).getInfo_brief()%>&info_fee=<%=pic_list.get(i).getInfo_fee()%>&infouser_id=<%=pic_list.get(i).getUser_id()%>">
<div class="media-text">
<h2><%=pic_list.get(i).getInfo_title()%></h2>
<span class="location"><%=pic_list.get(i).getInfo_brief()%></span>
</div>
<div id="test111">
<%=imgTags%>
</div>
</a>
</div>
<%}%>
</div>
SummerNote API를 사용하여 글 작성부분에 글 + 이미지 를 넣을 경우 html 태그 통째로 저장됨
<img> 태그만 짤라서 썸네일 구현
DAO, Mapper
public ArrayList<InfoDTO> topFive(String info_cate) {
SqlSession session = sqlSessionFactory.openSession(true);
List<InfoDTO> top_five = session.selectList("topFive", info_cate);
session.close();
return (ArrayList<InfoDTO>) top_five;
}
<select id="topFive" parameterType="String" resultType="InfoDTO">
select *
from info_trade
where info_num in (
select info_num
from(
select info_num
from trade_his
where trade_cate = #{info_cate}
group by info_num
order by count(info_num) desc)
where <![CDATA[rownum <= 5]]>)
</select>
'프로젝트 코드리뷰 > Travel Maker' 카테고리의 다른 글
Travel Maker - 기타기능 (0) | 2023.08.25 |
---|---|
Travel Maker - 프로필사진 실시간 업로드 (0) | 2023.08.25 |
Travel Maker - 글 조회 제한 기능 (0) | 2023.08.25 |
Travel Maker - 반응형 웹 (미완성) (0) | 2023.08.25 |
Travel Maker - 평점시스템 (0) | 2023.08.25 |