SpringMVC注解有哪些具体用途?

更新于
2026-10-12 08:23:01
1阅读来源:SEO资讯
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计486个文字,预计阅读时间需要2分钟。

SpringMVC注解有哪些具体用途?

java@Controllerpublic class HelloWorld { private String s;}

SpringMVC注解有哪些具体用途?

@Controller将目标类标识为一个请求处理器,@RequestMapping映射请求

import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @Controller public class HelloWorld { private static String success="success"; @RequestMapping("/helloworld") public String hello() { System.out.println("Hello World"); return success; } } web.xml配置文件

springDispatcherServlet org.springframework.web.servlet.DispatcherServlet

contextConfigLocation

classpath:springmvc.xml 1 springDispatcherServlet / HiddenHttpMethodFilter org.springframework.web.filter.HiddenHttpMethodFilter HiddenHttpMethodFilter /* springmvc.xml配置文件

请求页面index.jsp

<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="ISO-8859-1"%> Insert title here Hello World
testParamAndHeader
testAntPath
testPathVariable

Test Get
返回的成功页面success.jsp

<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="ISO-8859-1"%> Insert title here

Success

ModelAndView: ${requestScope.studentMsg } Map: ${requestScope.users } Map: ${requestScope.xixi } SessionAttributes: ${sessionScope.user } SessionAttributes: ${sessionScope.msg }

本文共计486个文字,预计阅读时间需要2分钟。

SpringMVC注解有哪些具体用途?

java@Controllerpublic class HelloWorld { private String s;}

SpringMVC注解有哪些具体用途?

@Controller将目标类标识为一个请求处理器,@RequestMapping映射请求

import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @Controller public class HelloWorld { private static String success="success"; @RequestMapping("/helloworld") public String hello() { System.out.println("Hello World"); return success; } } web.xml配置文件

springDispatcherServlet org.springframework.web.servlet.DispatcherServlet

contextConfigLocation

classpath:springmvc.xml 1 springDispatcherServlet / HiddenHttpMethodFilter org.springframework.web.filter.HiddenHttpMethodFilter HiddenHttpMethodFilter /* springmvc.xml配置文件

请求页面index.jsp

<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="ISO-8859-1"%> Insert title here Hello World
testParamAndHeader
testAntPath
testPathVariable

Test Get
返回的成功页面success.jsp

<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="ISO-8859-1"%> Insert title here

Success

ModelAndView: ${requestScope.studentMsg } Map: ${requestScope.users } Map: ${requestScope.xixi } SessionAttributes: ${sessionScope.user } SessionAttributes: ${sessionScope.msg }