쇼핑몰 사이트맵 xml 자동 생성

This commit is contained in:
이대환
2026-09-08 13:56:17 +09:00
parent 53f5f0d3bb
commit 3a42bff138
5 changed files with 189 additions and 0 deletions

View File

@@ -3,6 +3,7 @@ package com.wb.domainserver.domain.admin.store.sopmal.mapper;
import java.util.List;
import com.wb.domainserver.domain.admin.store.sopmal.vo.Shop;
import com.wb.domainserver.domain.gcone.goods.goods.vo.BOGoodsVO;
import com.wb.domainserver.domain.gcone.promtn.coupon.vo.BOCouponVO;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
@@ -202,4 +203,7 @@ public interface BOMaSopmalMapper {
/*전체 쇼핑몰 목록*/
List<DataMap> selectSopmalList();
// XML 수정 임시
public List<DataMap> selectSitemapXml(String sopmalCd);
}

View File

@@ -19,6 +19,7 @@ import com.wb.domainserver.domain.admin.sys.menu.vo.BOMaMenuVO;
import com.wb.domainserver.domain.gcone.goods.goodsinfo.mapper.BOGoodsinfoMapper;
import com.wb.domainserver.domain.gcone.goods.goodsinfo.vo.BOGoodsInfoVO;
import lombok.Data;
import org.apache.commons.text.StringEscapeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -984,4 +985,43 @@ public class BOMaSopmalService {
return mapper.selectSopmalList();
}
/**
* 사이트맵 XML
* @param sopmalCd
* @return
*/
@Transactional
public String selectSitemapXml(String sopmalCd) {
List<DataMap> resultList = new ArrayList<>();
StringBuilder xml = new StringBuilder();
try {
xml.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
xml.append("<?xml-stylesheet type=\"text/css\" href=\"https://www.xml-sitemaps.com/css/sitemap.css\"?>");
xml.append("<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\" xmlns:xhtml=\"http://www.w3.org/1999/xhtml\">\n");
resultList = mapper.selectSitemapXml(sopmalCd);
for (DataMap data : resultList) {
xml.append(" <url>");
xml.append(" <loc>")
.append(StringEscapeUtils.escapeXml11(String.valueOf(data.get("targetUrl"))))
.append("</loc>");
xml.append(" <lastmod>")
.append(StringEscapeUtils.escapeXml11(String.valueOf(data.get("lastModified"))))
.append("</lastmod>");
xml.append(" <priority>")
.append(StringEscapeUtils.escapeXml11(String.valueOf(data.get("priority"))))
.append("</priority>");
xml.append(" </url>");
}
xml.append("</urlset>");
} catch (WnbtRestException wre){
throw new WnbtRestException(wre.getMessage());
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return xml.toString();
}
}

View File

@@ -198,6 +198,20 @@ public class MainController {
}
/**
* 사이트맵 XML
* @return
*/
@Policy(AuthPolicy.PUBLIC)
@RequestMapping(value="/sitemap", produces = MediaType.APPLICATION_XML_VALUE)
public ResponseEntity<String> selectSitemapXml() {
AnonymousUser user = MemberJwtContextHolder.getMemberInfo();
String xml = boMaSopmalService.selectSitemapXml(user.getSopmalCd());
return ResponseEntity.ok().contentType(MediaType.APPLICATION_XML).body(xml);
}
/**
* 비회원 휴대폰번호 확인
* @return OrdrDtlR.jsp