使用注解开发SpringMVC



web.xml:

<?xml version="1.0" encoding="UTF-8"?>


    
    
        springmvc
        org.springframework.web.servlet.DispatcherServlet
        
        
            contextConfigLocation
            classpath:springmvc-servlet.xml
        
        1
    
    
        springmvc
        /
    



springmvc-servlet.xml:

<?xml version="1.0" encoding="UTF-8"?>


    
    

    
    

    
    

    
    
        
        
    



HelloController:

package com.kakafa.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class HelloController {

    @RequestMapping("/hello")
    public String hello(Model model){
        //封装数据
        model.addAttribute("msg","Hello,Damon!");
        return "hello";//会被视图解析器处理,路径为:WEB-INF/jsp/hello.jsp
    }
}


hello.jsp:

<%@ page contentType="text/html;charset=UTF-8" language="java" %>


    Title


${msg}