包结构
1.导入相关依赖
org.springframework
spring-webmvc
5.1.9.RELEASE
javax.servlet
servlet-api
2.5
javax.servlet.jsp
jsp-api
2.2
javax.servlet
jstl
1.2
2.配置web.xml
<?xml version="1.0" encoding="UTF-8"?>
springmvc
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:springmvc-servlet.xml
1
springmvc
/
encoding
org.springframework.web.filter.CharacterEncodingFilter
encoding
utf-8
encoding
/*
3.SpringMVC配置文件
<?xml version="1.0" encoding="UTF-8"?>
4.Controller
package com.song.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class HelloController {
@RequestMapping("/hello")
public String hello(Model model) {
// 封装数据
model.addAttribute("msg", "Hello,SpringMVCAnnotation");
return "hello"; //会被视图解析器处理
}
}
5.view
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
Title
${msg}
常见问题