I am able to access http://localhost/manage/welcome page. But not able to get the html. it just returns the string.
@Endpoint(id="welcome")
@Component
public class UtilClass {
@ReadOperation
public String logger() {
return "<html><table>sampletable</table></html>";
}
}
Please suggest any way to load html content without using @Controller/ @RestController or thyleaf
CodePudding user response:
I don't understand why you don't want to use @Controller
@ReadOperation
has a parameter to set output content type in 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>";
}
}