SpringMVC 의 경로 매개 변수 와 URL 매개 변수 인 스 턴 스 기반
2.경로 매개 변수 실현 방식(하나의 Controller 방법)
@RequestMapping(value="/page/{name}/{age}",method=RequestMethod.GET)
public String getName(ModelMap map,@PathVariable("name") String name,@PathVariable("age") int age)
{
map.addAttribute("name",name);
map.addAttribute("age",age);
return "name";
}
3.name.jsp 파일 만 들 기
<%@page pageEncoding="UTF-8"%>
<html>
<head>
<meta charset="UTF-8">
<title>test</title>
</head>
<body>
<div>
:${name}<br/>
:${age}
</div>
</body>
</html>
4.브 라 우 저 에서 이 controller 를 요청 합 니 다.http://localhost:8080/page/xiaoming/18
주의해 야 할 것 은 제 가 사용 하 는 편집 기 는 IDEA 플래그 십 버 전 입 니 다.
5.contrller 에서 요청 매개 변 수 를 받 아들 이 는 실현(contrller)
@RequestMapping(value="/result",method=RequestMethod.GET)
public String resultParam(ModelMap map,@RequestParam String name,@RequestParam int age)
{
map.addAttribute("name",name);
map.addAttribute("age",age);
return "result";
}
6.result.jsp 파일 만 들 기
<%@page pageEncoding="UTF-8">
<html>
<head>
<meta charset="UTF-8">
<title> </title>
</head>
<body>
:${name}<br/>
:${age}
</body>
</html>
6.브 라 우 저 에서 이 controller 요청http://localhost:8080/result?name=xiaoming&age=20
보충:spring mvc 의 선택 가능 한 경로 파라미터
spring mvc 에서@PathVariable 을 주석 하면 경로 인 자 를 얻 을 수 있 지만 경로 인 자 를 선택 하고 싶다 면?
@GetMapping({"/get/{offset}/{count}","/get/{offset}","/get/{offset}","/get"})
public void getGoods(@PathVariable(required = false) Integer offset,@PathVariable(required = false) Integer count){
System.out.println("offset:"+offset+"
count:"+count+"
");
}
이 예 에서 offset 과 count 는 모두 선택 할 수 있 지만 count 가 존재 할 때 offset 는 반드시 존재 해 야 합 니 다.이상 은 개인 적 인 경험 이 므 로 여러분 에 게 참고 가 되 기 를 바 랍 니 다.여러분 들 도 저 희 를 많이 응원 해 주시 기 바 랍 니 다.만약 잘못 이 있 거나 완전히 고려 하지 않 은 부분 이 있다 면 아낌없이 가르침 을 주시 기 바 랍 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
ssm 프레임워크 업로드 이미지 로컬 및 데이터베이스에 저장 예시본고는 ssm 프레임워크 업로드 이미지를 로컬과 데이터베이스에 저장하는 예시를 소개하고 주로 Spring+SpringMVC+MyBatis 프레임워크를 사용하여 ssm 프레임워크 업로드 이미지의 실례를 실현했다. 구체...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.