当前位置: 首页 > 知识库问答 >
问题:

Spring MVC。雄猫。我可以打开index.jsp,但不打开hello.html。

贾飞鸿
2023-03-14

在Eclipse中运行TomCat。我在浏览器http://localhost:8080/springmvc/index.jsp中键入,然后看到“Hello World!”。

@Controller
public class WebController {

@GetMapping("/hello")
public String hello() {
    return "hello";
}}

我的配置

@Configuration
@ComponentScan("ru.neutrino")
@EnableWebMvc
public class WebConfig implements WebMvcConfigurer {

private final ApplicationContext applicationContext;

@Autowired
public WebConfig(ApplicationContext applicationContext) {
    this.applicationContext = applicationContext;
}

@Bean
public SpringResourceTemplateResolver templateResolver() {
    SpringResourceTemplateResolver templateResolver = new SpringResourceTemplateResolver();
    templateResolver.setApplicationContext(applicationContext);
    templateResolver.setPrefix("/WEB-INF/views/");
    templateResolver.setSuffix(".html");
    return templateResolver;
}

@Bean
public SpringTemplateEngine templateEngine() {
    SpringTemplateEngine templateEngine = new SpringTemplateEngine();
    templateEngine.setTemplateResolver(templateResolver());
    templateEngine.setEnableSpringELCompiler(true);
    return templateEngine;
}

@Override
public void configureViewResolvers(ViewResolverRegistry registry) {
    ThymeleafViewResolver resolver = new ThymeleafViewResolver();
    resolver.setTemplateEngine(templateEngine());
    registry.viewResolver(resolver);
}}

共有1个答案

卓胜
2023-03-14

controller类级别缺少@RequestMapping批注。

@Controller
@RequestMapping("/web")
public class WebController {

   @GetMapping("/hello")
   public String hello() {
      return "hello";
   }
 }

尝试访问http://localhost:8080/springmvc/web/hello

 类似资料:
  • 问题内容: 如何使用该URL打开index.jsp ,如何使用此类超链接 并转到index.jsp()? 这是我的web.xml: 这是我的myApp-servlet.xml: 提前致谢! 问题答案: 只需添加带有适当处理程序方法的 假设在。

  • 我的iOS项目使用Xcode 5完美地打开,编译、创建归档文件时没有任何问题。但每当我尝试使用Xcode 6打开时,Xcode 6就会崩溃,并显示以下消息: 提前谢谢。 --------------------进程:Xcode[1017]路径:/Applications/Xcode。app/Contents/MacOS/Xcode标识符: com。苹果dt。Xcode版本:6.0。1(6528)生

  • 模仿天猫 app 中可打开的列表样式。即点击列表任意一行,被点击的列表行(cell)会下拉打开,展示更多内容。Demo中列表下拉打开显示更多按钮,每个按钮能响应点击事件。 [Code4App.com]

  • 安装vue3之后(启用TS、JSX、pinia)但打开route.ts文件,一直报错提示: 在vite.config.js 文件中已经有写了at的别名 fileURLToPath(new URL('./src', import.meta.url))。 提示找不到,但实际上是存在的,并且webstorm里面点进去是可以打开对应的文件,但一直报红色。

  • 问题内容: 如果我从未检查过Go通道的状态,可以永远保持打开状态(永远不关闭通道)可以吗?会导致内存泄漏吗?下列代码可以吗? 问题答案: 可以永远保持Go频道永远不关闭。当不再使用该通道时,将对其进行垃圾回收。 请注意,只有当接收器正在寻找关闭通道时,才需要关闭通道。关闭通道是通道上的控制信号,指示没有更多数据跟随。 设计问题:通道关闭

  • 我们的开发团队正在开发新的页面模板,其中包括对这些页面上的定位器的大量更改。这些新页面处于切换状态,因此在我们的测试环境中,它们可能随时存在,也可能不存在,这取决于它们是否被切换打开或关闭。标头中有一个id,我可以用它来标识新页面模板是否被切换。谁能告诉我处理这件事的最好方法。理想情况下,我希望将新的定位器添加到相关的页面对象,而不是将它们放在属性文件中。 当前定位器和Web元素: 新模板上的新定