搭建和使用Spring MVC框架的方法如下:
<dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>5.3.9</version> </dependency> <!-- 配置Spring MVC --> <mvc:annotation-driven /> <mvc:default-servlet-handler /> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/views/" /> <property name="suffix" value=".jsp" /> </bean> @Controller @RequestMapping("/example") public class ExampleController { @RequestMapping("/hello") public String hello(Model model) { model.addAttribute("message", "Hello Spring MVC!"); return "hello"; } } <!DOCTYPE html> <html> <head> <title>Hello</title> </head> <body> <h1>${message}</h1> </body> </html> 以上是使用Spring MVC框架搭建和使用的基本方法。根据具体需求,还可以使用其他功能和特性,如数据绑定、表单验证、拦截器等。