【发布时间】:2018-02-08 16:34:33
【问题描述】:
我正在尝试使用 Spring 从 Angular 创建一个翻译器。所以在春天我创建了这个端点
package com.vir.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import com.vir.exception.ApiError;
import com.vir.model.iTranslator;
import com.vir.service.iTranslateProcessorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
@RestController
@RequestMapping("/api")
@Api(tags = "iTranslate")
public class iTranslateController {
@Autowired
@Qualifier("iTranslatorService")
private iTranslateProcessorService itranslateProcessorService;
@ApiOperation(value = "Translate a text input.")
@ApiResponse(code = 400, message = "Generic error", response = ApiError.class)
@PostMapping(value = "/iTranslate", produces = MediaType.APPLICATION_JSON_VALUE)
public iTranslator iTranslate(@RequestBody(required = true) String text, @RequestBody(required = true) String target) {
return itranslateProcessorService.process(text, target);
}
}
我还制作了 ItranslateProcessorService 接口,它将调用 iTranslator 模型。我的问题是,在该模型中,我在哪里调用 google API?如何使它返回谷歌 API 返回的翻译或 json 文件? Here is the documentation of the google API
任何指向正确方向的方法都会有所帮助,谢谢。
【问题讨论】:
标签: java spring api backend google-translate