我可以訪問 http://localhost/manage/welcome 頁面。但是無法獲取html。它只回傳字串。
@Endpoint(id="welcome")
@Component
public class UtilClass {
@ReadOperation
public String logger() {
return "<html><table>sampletable</table></html>";
}
}
請建議任何不使用 @Controller/ @RestController 或 thyleaf 加載 html 內容的方法
uj5u.com熱心網友回復:
我不明白你為什么不想使用@Controller
@ReadOperation 有一個引數來設定 spring boot 2.xx 中的輸出內容型別。
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
@Endpoint(id = "welcome")
@Component
public class UtilClass {
@ReadOperation(produces = MediaType.TEXT_HTML_VALUE)
public String logger() {
return "<html>"
"<table>"
" <thead><tr>"
" <th>ID</th><th>Name</th></tr>"
"</thead>"
" <tbody><tr>"
" <td>1</td><td>Arfat</td></tr>"
"</tbody>"
"</table>"
"</html>";
}
}

轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/345750.html
上一篇:JPA-過濾結果
