简体   繁体   中英

How can I do Google Sitemap for Spring boot Application

I have a spring application deployed on the cloud server, digital ocean.

i tried to generate the sitemap.xml file using https://www.xml-sitemaps.com/ but it only gives me one page. which can be access on https://hostname.com

i would like my sitemap to have something like

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

how can i make a sitemap for other pages which are bundle in a war file in a spring boot application.

If you are looking at exporting URLs mentioned in controllers, then you can get the URLs list from RequestMappingHandlerMapping .

@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
    }

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM