springmvc之RequestMapping注解既可以修饰类也可以修饰方法
@RequestMapping不仅可以修饰类,也可以修饰方法。
总而言之,用@RequestMapping标识的是请求的URL地址。例如:
package com.gong.springmvc.handlers; import org.springframework.stereotype.Controller; import 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"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <a href="springmvc/test">springmvc test</a> </body> </html>
相关推荐
JudeJoo 2020-08-21
meleto 2020-08-15
itjavashuai 2020-08-15
zhongliwen 2020-07-05
haidaoxianzi 2020-07-04
小鱿鱼 2020-06-26
haidaoxianzi 2020-06-17
MicroBoy 2020-06-17
牧场SZShepherd 2020-06-17
neweastsun 2020-06-16
haidaoxianzi 2020-06-14
zhongliwen 2020-06-13
@RequestBody注解实现接收http请求的json数据,将json数据转换为java对象进行绑定。加上@ResponseBody注解,就不会走视图解析器,不会返回页面,目前返回的json数据。
DumbbellYang 2020-06-13
csuzxm000 2020-06-09
haidaoxianzi 2020-06-03
qingjiuquan 2020-05-30
84560296 2020-05-30
咻pur慢 2020-05-27