{"id":21158906,"url":"https://github.com/yaccc/dreamvc","last_synced_at":"2025-07-09T13:34:04.949Z","repository":{"id":23227217,"uuid":"26584611","full_name":"Yaccc/Dreamvc","owner":"Yaccc","description":":zap:A simple and support the restful structure of the Java MVC framework, I have little talent and less learning, we hope the exhibitions","archived":false,"fork":false,"pushed_at":"2016-10-15T11:17:39.000Z","size":5259,"stargazers_count":63,"open_issues_count":0,"forks_count":24,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-05T00:51:14.597Z","etag":null,"topics":["framework","learning","mvc"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Yaccc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-11-13T11:25:20.000Z","updated_at":"2022-08-17T02:25:37.000Z","dependencies_parsed_at":"2022-08-09T03:00:03.183Z","dependency_job_id":null,"html_url":"https://github.com/Yaccc/Dreamvc","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/Yaccc/Dreamvc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yaccc%2FDreamvc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yaccc%2FDreamvc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yaccc%2FDreamvc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yaccc%2FDreamvc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Yaccc","download_url":"https://codeload.github.com/Yaccc/Dreamvc/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yaccc%2FDreamvc/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264468311,"owners_count":23613082,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["framework","learning","mvc"],"created_at":"2024-11-20T12:38:14.279Z","updated_at":"2025-07-09T13:34:03.999Z","avatar_url":"https://github.com/Yaccc.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"Dreamvc\n=================================== \nA simple and support the restful structure of the Java MVC framework, I have little talent and less learning, we hope the exhibitions\n\u003e`Dreamvc` combines the ideas of `Struts2` and `SpringMVC` framework，But `Dreamvc` has two entries(filter and servlet)，`Dreamvc` combines the template mechanism of `Python-flask` framework，Achieve their own template，Self expanding，At present, the `JSP` and `velocity` templates are implemented by Dreamvc.Dreamvc provides the developer's IOC interface can be combined with any IOC framework，Dreamvc uses the `Struts2` interceptor mechanism(Stack)，Annotation convenient way，Matching algorithm can be fuzzy matching / precision matching，The parameters of the method are injected into the `javassist` or `Spring framework`.\n\n####IOC factory interface\n- As long as the implementation of this interface, you can let Dramvc and any IOC container\n```java\npackage org.majorxie.dreamvc.ioc.factory;\nimport java.util.List;\nimport javax.servlet.ServletConfig;\nimport javax.servlet.ServletContext;\n/**\n *IOC Factory\n * @author xiezhaodong(majorxie@139.com)\n *2014-10-24\n */\npublic interface IocFactory {\n\t/**\n\t * init config\n\t */\n\tvoid init(ServletContext context);\n\t/**\n\t * destory\n\t */\n\tvoid destroy();\n\t/**\n\t *get all controller\n\t */\n\tList\u003cObject\u003e getControllers()throws Exception;\n\t/**\n\t * get all interceptors\n\t */\n\tList\u003cObject\u003e getInterceptors();\n\t/**\n\t * init others object from IOC\n\t */\n\tList\u003cObject\u003e getOthers();\n}\n```\n- Then the implementation of full path incoming classes on the line in `web.xml`, I implemented a default `Springioc` (below)\n```xml\n\u003cinit-param\u003e\n\t\u003cparam-name\u003econtainer\u003c/param-name\u003e\n\t\u003cparam-value\u003eorg.majorxie.dreamvc.ioc.factory.SpringIocFactory\u003c/param-value\u003e\n\u003c/init-param\u003e\n```\n####Template mode integration, default JSP template\n- Combined with the idea of flask framework. So that users can choose their own templates such as JSP/velocity/freemarker, etc., as long as the successor to the template factory (as follows)\n```java\npackage org.majorxie.dreamvc.template;\nimport org.majorxie.dreamvc.tag.Contextconfig.StrategyConfig;\n/**\n * Python flask framework, abstract a template method\n * @author xiezhaodong\n *2014-11-14\n */\npublic abstract class TemplateFactory {\n\tprivate static TemplateFactory instance;\n\tpublic static void setInstance(TemplateFactory instance) {\n\t\tTemplateFactory.instance = instance;\n\t}\n\tpublic static TemplateFactory getInstance(){\n\t\treturn instance;\n\t}\n\tpublic abstract void init(StrategyConfig config);\n\tpublic abstract Template initTemplate(String path,ForwardType type) throws Exception;\n}\n```\n- Achieve this interface, complete the implementation of the template (see the implementation of the JSP template specifically)\n```java\npackage org.majorxie.dreamvc.template;\nimport java.util.Map;\nimport javax.servlet.http.HttpServletRequest;\nimport javax.servlet.http.HttpServletResponse;\npublic interface Template {\n\tvoid handleRender(HttpServletRequest req,HttpServletResponse resp,Map\u003cString, Object\u003e models)throws Exception;\n\n}\n```\n```xml\n \u003c/init-param\u003e\n\t    \u003cinit-param\u003e\n\t    \u003cparam-name\u003etemplate\u003c/param-name\u003e\n\t    \u003cparam-value\u003eorg.majorxie.dreamvc.template.JspTemplateFactory\u003c/param-value\u003e\n \u003c/init-param\u003e\n```\n\u003eIf you are using the default `jsp` template, you can give this parameter, dreamvc will automatically help you select the JSP template\n\n###How to use\n- Construction of the project with `pom.xml`, which is necessary for the three party packages and construction (example/example2.0 is a complete example). as follows\n```xml\n1. git clone git@github.com:Yaccc/Dreamvc.git\n2. cd Dreamvc \u0026 mvn  install\n```\n- add dependencies and the necessary configuration to pom.xml\n```xml\n\u003cdependency\u003e\n      \u003cgroupId\u003eorg.majorxie.dreamvc\u003c/groupId\u003e\n      \u003cartifactId\u003emvc-core\u003c/artifactId\u003e\n      \u003cversion\u003e1.0-SNAPSHOT\u003c/version\u003e\n\u003c/dependency\u003e\n....Omit the spring configuration\n```\n- Define your controller to `applicationContext.xml`\n```xml\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003cbeans \n....\n\u003cbean id=\"myController\" class=\"your_Controller\"\u003e\u003c/bean\u003e\u003c!--add controller --\u003e\n\u003c!--add your interceptor--\u003e\n\u003c!--\u003cbean id=\"interceptor1\" class=\"example.interceptor.Interceptor_01\"\u003e\u003c/bean\u003e--\u003e\n\u003c!--\u003cbean id=\"interceptor_02\" class=\"example.interceptor.Interceptor_02\"\u003e\u003c/bean\u003e--\u003e\n\t\n\u003c/beans\u003e\n```\n- The simplest `web.xml` configuration (see `example`).\n```xml\n \u003c!-- Configuration file location, the default is /WEB-INF/applicationContext.xml --\u003e\n    \u003ccontext-param\u003e\n        \u003cparam-name\u003econtextConfigLocation\u003c/param-name\u003e\n        \u003cparam-value\u003e/WEB-INF/applicationContext.xml\u003c/param-value\u003e\n    \u003c/context-param\u003e\n    \u003c!-- The Spring context listener --\u003e\n    \u003clistener\u003e\n        \u003clistener-class\u003eorg.springframework.web.context.ContextLoaderListener\u003c/listener-class\u003e\n    \u003c/listener\u003e\n    \u003cfilter\u003e\n        \u003cfilter-name\u003eDispatcherFilter\u003c/filter-name\u003e\n        \u003cfilter-class\u003eorg.majorxie.dreamvc.mvc.dispatcher.DispatcherFilter\n        \u003c/filter-class\u003e\u003c!-- Select filter to enter, or select servlet to enter (as above) --\u003e\n        \u003cinit-param\u003e\n            \u003cparam-name\u003econtainer\u003c/param-name\u003e\n            \u003cparam-value\u003eorg.majorxie.dreamvc.ioc.factory.SpringIocFactory\u003c/param-value\u003e\u003c!-- Select springioc as the IOC container --\u003e\n        \u003c/init-param\u003e\n        \u003cinit-param\u003e\n            \u003cparam-name\u003eCodeEnhancement\u003c/param-name\u003e\n            \u003cparam-value\u003eSpringAsm\u003c/param-value\u003e\u003c!-- Choose SpringAsm or javassist --\u003e\n\n        \u003c/init-param\u003e\n        \u003cinit-param\u003e\n            \u003cparam-name\u003etemplate\u003c/param-name\u003e\n            \u003cparam-value\u003e\u003c/param-value\u003e\u003c!-- Select the template for the return of the template here and not automatically select the JSP template --\u003e\n        \u003c/init-param\u003e\n    \u003c/filter\u003e\n \u003cfilter-mapping\u003e\n        \u003cfilter-name\u003eDispatcherFilter\u003c/filter-name\u003e\n        \u003curl-pattern\u003e*.do\u003c/url-pattern\u003e\n    \u003c/filter-mapping\u003e\n```\n- `Controller` how to write, how to use the template?\n```java\n@Controller//Using controller annotations to indicate the class or implement the controller interface\npublic class ConTest {\n    @RequestURI(\"/login.do\")//It is suggested that the.Do is similar to /user/login/check.do, and the best parameters are passed, and no delivery will be reported to 404.\n\tpublic Renderer hehe(String name,int  s) throws IOException{//Bean is currently not supported, as long as the traditional parameters\n\t\t\t//Pass, function return value can make String, void, render.render said only template currently has /JsonTemplate/TextTemplate/\n\t\t\t//JSP template TemplateRender, the default jump is forword jump, you can see the constructor using FORWARD.Rediect set the client jump\n\t\t\t//Server side jump can pass the map object, you can also like the following way\n\t\t\tTemplateRender render=new TemplateRender(\"WEB-INF/pages/test.jsp\");\n\t\t\trender.addVaule(\"posts\", \"qwoeqwe\");\n\t\t\treturn render;\n\t}\n\n\t@RequestURI(\"/check.do\")\n\tpublic void haha() {\n\t\ttry {\n\t\t\tSystem.out.println(\"do something...\");\n\t\t\t} catch (Exception e) {\n\t\t\t    e.printStackTrace();\n\t\t\t}\n\t}\n}\n```\n\u003eIf you want to get servletapi, you can get the request object in `ActionContext.getHttpServletRequest (), and the other is the same, see the `example` project\n\n#### The use of the interceptor\nFirst, you must implement the `Interceptor` interface or the `AbstractInterceptor` class to implement the `doInterceptor () and `afterInterceptor () method, and must be used.`InterceptorURI` comment to specify the path to intercept, as follows\n```java\n@InterceptorURI(url=\"/login.do\")\npublic class Interceptor_02 extends AbstractInterceptor {\n\n\t\t\t@Override\n\t\t\tpublic boolean doInterceptor() {\n\t\t\t\tSystem.out.println(\"strat——02\");\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\t@Override\n\t\t\tpublic void afterInterceptor() {\n\t\t\t\tSystem.out.println(\"end_02\");\n\t\t\t}\n}\n@InterceptorURI(url=\"/*\")\npublic class LoginInterceptor implements Interceptor {\n\t\t\tpublic void destory() {\n\t\t\t}\n\t\t\tpublic void init() {\n\t\t\t}\n\t\t\tpublic boolean doInterceptor() {\n\t\t\t\tSystem.out.println(\"login_start\");\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tpublic void afterInterceptor() {\n\t\t\t\tSystem.out.println(\"login_end\");\n\t\t\t}\n}\n```\n`interceptor` `true` will return to the release, the execution of the next interceptor, `false` does not return a corresponding executing method\nAnd the highest degree of matching path will be a priority，While blocking the path of the relative length must be less than or equal to the path length. Equal to the uncertain path with `*` instead of\nFor example, the path is `/user/login/check.do`\nSo I can use `/*/*/check.do` to intercept it,You can also use the `/user/*/check.do` to match, if the short path to the end of the star, then the front of the path should be relatively the same.\n\n- [English document](https://github.com/xiexiaodong/Dreamvc/blob/master/README.md)\n- [中文文档](https://github.com/xiexiaodong/Dreamvc/blob/master/README_ZH_CN.md)\n\t\t\n\n  \n  \n  \n  \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyaccc%2Fdreamvc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyaccc%2Fdreamvc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyaccc%2Fdreamvc/lists"}