java - Spring MVC:无法连接到 Rest 服务
问题描述
编写了一个spring controller
Get 方法并尝试用邮递员调用它但出现错误
Could not get any response
There was an error connecting to https://localhost:8081/MyPortal/shared?video0=14&video1=15.
即使我尝试调试,调用也不会转到控制器方法。不知道发生了什么。
这是控制器代码:
@Controller
public class SharedLinkController {
@Autowired
VideoService videoService;
@RequestMapping("/shared")
public ModelAndView getSharedVideo(HttpServletRequest request, HttpServletResponse response,
@RequestParam(value="video0", required=false) Long video0,
@RequestParam(value="video1", required=false) Long video1,
@RequestParam(value="video2", required=false) Long video2,
@RequestParam(value="video3", required=false) Long video3){
List<Lab> videos = new ArrayList<Lab>();
// some processing with video0, video1 etc....
ModelAndView model = new ModelAndView("index");
model.addObject("videos", videos);
return model;
}
}
这就是我尝试调用 API 的方式:
https://localhost:8081/MyPortal/shared?video0=14&video1=15
我不想让它成为一个RestController
,因为我需要将呼叫重定向到网页。代码有什么问题吗?
请建议。
解决方案
您是否有一个扫描基本包并将您的控制器注册为 bean 的类,如下所示?
@SpringBootApplication(scanBasePackages= "se.yourpackage.src")
@EnableAutoConfiguration
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
没关系 RestController,但你需要添加 requestmapping
@RequestMapping("/MyPortal")
public class SharedLinkController {
您可能还需要在名为的文件中添加视图文件的路径
应用程序属性
例如:
spring.mvc.view.prefix=/WEB-INF/view/
spring.mvc.view.suffix=.jsp
推荐阅读
- twitter-bootstrap - Bootstrap / vue 响应式“蛇”列,其中交替的“行”被反转
- flutter - 颤振中的小部件回调
- git - Windows 上的 Reposurgeon
- javascript - 单击选择标签时禁用手风琴打开
- azure-ad-b2c - 自定义 SAML 策略解密方法
- flutter - 带有 setState 的对话框中的 listView
- rust - 解构期权
> 在 Rust 的 match 语句中 - java - 从命令行覆盖spring config服务器配置
- c# - 生成 DataTable 对象以作为值 (TVP) 传递给存储的采购输入对于计算列/标识失败
- php - 在第一次响应之前第二次使用 php curl 代码