我对 SpringMVC 很陌生,现在我正在尝试使用本教程构建一个简单的应用程序:http : //websystique.com/springmvc/spring-4-mvc-helloworld-tutorial-annotation-javaconfig-full-example/ 我已经检查过 基本 SpringMvC 控制器不起作用,这似乎不是我的问题,即使我插入应用程序名称,我的应用程序也不可用。我使用基于注释的配置和 Tomcat 9。
我有三个类: MainController.java
package mvc_webapp.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
@RequestMapping("/")
public class MainController {
@RequestMapping(method = RequestMethod.GET)
public String sayHello() {
return "index";
}
@RequestMapping(value = "/index", method = RequestMethod.GET)
public String indexPage() {
return "index";
}
}
博客配置.java
package mvc_webapp.configuration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.JstlView;
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "mvc_webapp")
public class BlogConfiguration {
@Bean
public ViewResolver viewResolver() {
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setViewClass(JstlView.class);
viewResolver.setPrefix("WEB-INF/views/");
viewResolver.setSuffix(".html");
return viewResolver;
}
}
jeck猫
相关分类