簡體   English   中英

我如何為 Spring 啟動應用程序做谷歌站點地圖

[英]How can I do Google Sitemap for Spring boot Application

我在雲服務器Digital Ocean上部署了一個spring應用。

我嘗試使用https://www.xml-sitemaps.com/生成 sitemap.xml 文件,但它只給了我一頁。 可以在https://hostname.com上訪問

我希望我的站點地圖有類似的東西

  1. https://hostname.com/page1
  2. https://hostname.com/page2

我如何為 Spring Boot 應用程序中的 war 文件中捆綁的其他頁面制作站點地圖。

如果您正在查看控制器中提到的導出 URL,那么您可以從RequestMappingHandlerMapping獲取 URL 列表。

@RestController
public class TestController {

    @Autowired
    private RequestMappingHandlerMapping re;

    @GetMapping("/sitemap.xml")
    public String getSitemap() {
        Map<RequestMappingInfo, HandlerMethod> handlerMethods = re.getHandlerMethods();
        List<String> urls = new ArrayList<>();
        for (Entry<RequestMappingInfo, HandlerMethod> entry : handlerMethods.entrySet()) {
            urls.addAll((entry.getKey().getPatternsCondition().getPatterns()));
        }
        // Construct XML response from urls and return it
    }

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM