一个简单的HelloSpringMVC程序
先在web,xml中注册一个前端控制器(DispatcherServlet)
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://.kuang.controller"/> <mvc:default-servlet-handler/> <mvc:annotation-driven/> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" id="internalResourceViewResolver"> <property name="prefix" value="/WEB-INF/jsp/"/> <property name="suffix" value=".jsp"/> </bean> </beans>contorller
@Controller //说明这类被Spring托管了 @RequestMapping("/hello") public class HelloController { @RequestMapping("/h1") //这个注解会执行视图解析器 public String hello(Model model){ model.addAttribute("msg","helloSpringMVCAnnotation"); return "hello"; } }以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。