【发布时间】:2019-01-25 08:27:01
【问题描述】:
我在视图中苦苦挣扎,我需要在视图上显示我的 API 函数的返回:
Spring 控制器代码
@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是一个返回String的API函数。
我需要在我的视图index.html 上显示它。
非常感谢你。
【问题讨论】:
-
使用
@RestController?或将@ResponseBody添加到您的控制器方法中? -
@Keijack 是其中之一。拥有
@RestController已经将@ResponseBody添加到您的方法中。* Types that carry this annotation are treated as controllers where * {@link RequestMapping @RequestMapping} methods assume * {@link ResponseBody @ResponseBody} semantics by default. -
你会在没有ajax请求的情况下使用这个方法吗?如果是这样,那么您将获得带有该方法返回的字符串的空白页面。
-
是的,我得到了空白页,到目前为止我有 0 次 ajax 经验。你能给我一些线索吗?
-
@Pijotrek 是的,你是对的,所以我使用
or。
标签: java spring-boot thymeleaf