Class LinkBuilder
java.lang.Object
io.leandev.appfuse.web.link.LinkBuilder
-
Constructor Summary
ConstructorsConstructorDescriptionLinkBuilder(Class<?> controller) LinkBuilder(org.apache.hc.core5.net.URIBuilder uriBuilder) -
Method Summary
Modifier and TypeMethodDescriptionstatic LinkBuildertoHref()生成相對路徑的 hreftoUri()withContext(String context) 設定可選的 context 前綴org.springframework.hateoas.Linkorg.springframework.hateoas.Link
-
Constructor Details
-
LinkBuilder
-
LinkBuilder
public LinkBuilder(org.apache.hc.core5.net.URIBuilder uriBuilder)
-
-
Method Details
-
linkTo
-
withContext
設定可選的 context 前綴- Parameters:
context- 前綴路徑(例如 "app1" 或 "v1/api")- Returns:
- 新的 LinkBuilder 實例
-
slash
-
toUri
-
toHref
生成相對路徑的 href
設計理念:刻意移除前導斜線以生成相對路徑,支援 reverse proxy 架構。 優勢:
- 避免暴露內部網路拓撲(host、port、context path)
- 無需配置 ForwardedHeaderFilter 或 server.use-forward-headers
- 客戶端可自行決定完整 URL 的組合策略
- 同一回應在不同環境(dev/staging/prod)都適用
- Returns:
- 相對路徑字串(例如 "api/users/123")
-
withRel
-
withSelfRel
public org.springframework.hateoas.Link withSelfRel()
-