[英]Display a String in a view returned by a Spring Boot Thymeleaf controller
I am struggling with my view, I need to display the return of my API function on my view: 我在视图中挣扎,我需要在视图上显示API函数的返回值:
Spring Controller Code 弹簧控制器代码
@Controller
public class mainController {
@RequestMapping(value = {"/"}, method = RequestMethod.GET)
public String index() throws IOException, GeneralSecurityException {
DriveQuickstart drive = new DriveQuickstart("c:/temp/credentials.json");
String res = drive.checkFile("cwg");
return res;
drive.checkFile
is an API function which returns a String
. drive.checkFile
是一个API函数,它返回String
。
I need to display it on my view index.html
. 我需要在视图index.html
上显示它。 thank you very mutch. 非常感谢你。
Update your method as below: 如下更新您的方法:
@RestController
public class mainController {
@RequestMapping(value = "/", method = RequestMethod.GET)
public String index() throws IOException, GeneralSecurityException {
DriveQuickstart drive = new DriveQuickstart("c:/temp/credentials.json");
String res = drive.checkFile("cwg");
return res;
}
The modification i did is: replaced @Controller
with @RestController
and updated @RequestMapping
我所做的修改是:用@RestController
替换@Controller
并更新@RequestMapping
@GetMapping("/")
public String index(Model model) throws IOException, GeneralSecurityException {
DriveQuickstart drive = new DriveQuickstart("c:/temp/credentials.json");
model.addAttribute("drive", drive)
return "/routeToTemplate";
}
in thymeleaf 在百里香
<div th:text="${drive}"></div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.