springmvc之RequestMapping注解既可以修饰类也可以修饰方法
发布时间:2020-12-15 01:12:59 所属栏目:大数据 来源:网络整理
导读:@RequestMapping不仅可以修饰类,也可以修饰方法。 总而言之,用@RequestMapping标识的是请求的URL地址。例如: package com.gong.springmvc.handlers; import org.springframework.stereotype.Controller; org.springframework.web.bind.annotation.Request
@RequestMapping不仅可以修饰类,也可以修饰方法。 总而言之,用@RequestMapping标识的是请求的URL地址。例如: package com.gong.springmvc.handlers; import org.springframework.stereotype.Controller; org.springframework.web.bind.annotation.RequestMapping; @RequestMapping("/springmvc") @Controller public class SpringmvcTest { private static final String SUCCESS = "success"; @RequestMapping("/test") public String test() { System.out.println("RequestmMapping"); return SUCCESS; } } 此时在jsp中访问就需要这么访问请求: <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"htmlheadmeta http-equiv="Content-Type" content="text/html; charset=UTF-8"title>Insert title here</body> a href="springmvc/test">springmvc testa> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |