[英]Display a String in a view returned by a Spring Boot Thymeleaf controller
我在视图中挣扎,我需要在视图上显示API函数的返回值:
弹簧控制器代码
@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
是一个API函数,它返回String
。
我需要在视图index.html
上显示它。 非常感谢你。
如下更新您的方法:
@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;
}
我所做的修改是:用@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";
}
在百里香
<div th:text="${drive}"></div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.