자신 이 쓴 오픈 소스 MVC - easyMVC 공유
8837 단어 mvc
기본 스타일 은 spring mvc 에 따라 만 든 것 으로 후기 에 새로운 특성 을 추가 하여 자신의 프로젝트 에 사용 하기 쉬 운 mvc 프레임 워 크 로 밀봉 합 니 다.
github 주소:
https://github.com/tangyanbo/easymvc
기능 소개:
1. 클 라 이언 트 매개 변 수 를 대상 으로 봉인 하 는 것 을 지원 합 니 다. 형식 자동 변환 2. 주 해 를 지원 합 니 다. controller 와 방법 @ RequestMapping 3. 방법 에서 request 와 response 를 방문 할 수 있 습 니 다. jstl 5 를 지원 합 니 다. 인 코딩 6. controller 방법 을 설정 할 수 있 는 매개 변 수 는 7. 404 오류 알림 8. restfull 지원 @ PathVariable
쾌속 사용 입문
jar 가방:
dist 디 렉 터 리 에서 copy easymvc. jar 와 jar 에 의존 하여 웹 프로젝트 에 패키지 합 니 다.
웹 프로젝트 에서 resources 디 렉 터 리 에 mvc - servlet. xml 을 만 듭 니 다.
<beans>
<!-- -->
<constant name="charsetEncoding">utf-8</constant>
<!-- -->
<scan base-package="com.easymvc.controller"/>
</beans>
웹. xml 설정:
<servlet>
<servlet-name>EasymvcInitServlet</servlet-name>
<display-name>EasymvcInitServlet</display-name>
<load-on-startup>1</load-on-startup>
<description></description>
<servlet-class>com.easymvc.servlet.EasymvcInitServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>EasymvcInitServlet</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
Controller:
@Controller //Controller
public class TestController {
@RequestMapping(value = "/test.html")
public String test(Model model,User user,HttpServletRequest request,HttpServletResponse response){
System.out.println("controller:"+user.getName());
List<User> list = new ArrayList<User>();
for(int i=0;i<2;i++){
User user1 = new User();
user1.setName(" "+i);
list.add(user1);
}
model.addAttribute("list", list);
System.out.println(request);
System.out.println(response);
return "test";
}
}
jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<style type="text/css">
div{
padding:5px;
}
</style>
</head>
<body>
<div style="color: green">
<form action="test.html" method="POST">
<div>
name: <input name="name" type="text"/>
</div>
<div>
orderInfo.orderId: <input name="orderInfo.orderId" type="text"/>
</div>
<div>
orderInfo.user.name:<input name="orderInfo.user.name" type="text"/>
</div>
<div>
sex: <input name="sex" type="text"/>
</div>
<div>
birthDate: <input name="birthDate" type="text"/>
</div>
<div>
type: <input name="type" type="text"/>
</div>
<div>
amt: <input name="amt" type="text"/>
</div>
<div>
status: <input name="status" type="text"/>
</div>
<input type="submit">
</form>
</div>
</body>
</html>
restfull 지원:
@RequestMapping(value = "/test/{userId}/test3.html")
public String test3(@PathVariable("userId") String userId){
System.out.println("======================="+userId);
return "test";
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
클린 아키텍처의 Presenter를 이해하기 어려운 것은 MVC 2가 아니기 때문에클린 아키텍처에는 구체적인 클래스 구성 예를 보여주는 다음 그림이 있습니다. 이 그림 중에서 Presenter와 Output Boundary(Presenter의 인터페이스)만 구체 구현을 이미지하는 것이 매우 어렵다...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.