자신 이 쓴 오픈 소스 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";
    }

좋은 웹페이지 즐겨찾기