Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yaccc/dreamvc
:zap:A simple and support the restful structure of the Java MVC framework, I have little talent and less learning, we hope the exhibitions
https://github.com/yaccc/dreamvc
framework learning mvc
Last synced: 2 months ago
JSON representation
:zap:A simple and support the restful structure of the Java MVC framework, I have little talent and less learning, we hope the exhibitions
- Host: GitHub
- URL: https://github.com/yaccc/dreamvc
- Owner: Yaccc
- Created: 2014-11-13T11:25:20.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2016-10-15T11:17:39.000Z (over 8 years ago)
- Last Synced: 2024-11-11T10:48:17.244Z (3 months ago)
- Topics: framework, learning, mvc
- Language: Java
- Homepage:
- Size: 5.02 MB
- Stars: 63
- Watchers: 5
- Forks: 23
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Dreamvc
===================================
A simple and support the restful structure of the Java MVC framework, I have little talent and less learning, we hope the exhibitions
>`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`.####IOC factory interface
- As long as the implementation of this interface, you can let Dramvc and any IOC container
```java
package org.majorxie.dreamvc.ioc.factory;
import java.util.List;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
/**
*IOC Factory
* @author xiezhaodong([email protected])
*2014-10-24
*/
public interface IocFactory {
/**
* init config
*/
void init(ServletContext context);
/**
* destory
*/
void destroy();
/**
*get all controller
*/
List getControllers()throws Exception;
/**
* get all interceptors
*/
List getInterceptors();
/**
* init others object from IOC
*/
List getOthers();
}
```
- Then the implementation of full path incoming classes on the line in `web.xml`, I implemented a default `Springioc` (below)
```xmlcontainer
org.majorxie.dreamvc.ioc.factory.SpringIocFactory```
####Template mode integration, default JSP template
- 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)
```java
package org.majorxie.dreamvc.template;
import org.majorxie.dreamvc.tag.Contextconfig.StrategyConfig;
/**
* Python flask framework, abstract a template method
* @author xiezhaodong
*2014-11-14
*/
public abstract class TemplateFactory {
private static TemplateFactory instance;
public static void setInstance(TemplateFactory instance) {
TemplateFactory.instance = instance;
}
public static TemplateFactory getInstance(){
return instance;
}
public abstract void init(StrategyConfig config);
public abstract Template initTemplate(String path,ForwardType type) throws Exception;
}
```
- Achieve this interface, complete the implementation of the template (see the implementation of the JSP template specifically)
```java
package org.majorxie.dreamvc.template;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public interface Template {
void handleRender(HttpServletRequest req,HttpServletResponse resp,Map models)throws Exception;}
```
```xml
template
org.majorxie.dreamvc.template.JspTemplateFactory
```
>If you are using the default `jsp` template, you can give this parameter, dreamvc will automatically help you select the JSP template###How to use
- 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
```xml
1. git clone [email protected]:Yaccc/Dreamvc.git
2. cd Dreamvc & mvn install
```
- add dependencies and the necessary configuration to pom.xml
```xmlorg.majorxie.dreamvc
mvc-core
1.0-SNAPSHOT....Omit the spring configuration
```
- Define your controller to `applicationContext.xml`
```xml
```
- The simplest `web.xml` configuration (see `example`).
```xml
contextConfigLocation
/WEB-INF/applicationContext.xml
org.springframework.web.context.ContextLoaderListener
DispatcherFilter
org.majorxie.dreamvc.mvc.dispatcher.DispatcherFilter
container
org.majorxie.dreamvc.ioc.factory.SpringIocFactory
CodeEnhancement
SpringAsm
template
DispatcherFilter
*.do
```
- `Controller` how to write, how to use the template?
```java
@Controller//Using controller annotations to indicate the class or implement the controller interface
public class ConTest {
@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.
public Renderer hehe(String name,int s) throws IOException{//Bean is currently not supported, as long as the traditional parameters
//Pass, function return value can make String, void, render.render said only template currently has /JsonTemplate/TextTemplate/
//JSP template TemplateRender, the default jump is forword jump, you can see the constructor using FORWARD.Rediect set the client jump
//Server side jump can pass the map object, you can also like the following way
TemplateRender render=new TemplateRender("WEB-INF/pages/test.jsp");
render.addVaule("posts", "qwoeqwe");
return render;
}@RequestURI("/check.do")
public void haha() {
try {
System.out.println("do something...");
} catch (Exception e) {
e.printStackTrace();
}
}
}
```
>If you want to get servletapi, you can get the request object in `ActionContext.getHttpServletRequest (), and the other is the same, see the `example` project#### The use of the interceptor
First, 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
```java
@InterceptorURI(url="/login.do")
public class Interceptor_02 extends AbstractInterceptor {@Override
public boolean doInterceptor() {
System.out.println("strat——02");
return true;
}@Override
public void afterInterceptor() {
System.out.println("end_02");
}
}
@InterceptorURI(url="/*")
public class LoginInterceptor implements Interceptor {
public void destory() {
}
public void init() {
}
public boolean doInterceptor() {
System.out.println("login_start");
return true;
}
public void afterInterceptor() {
System.out.println("login_end");
}
}
```
`interceptor` `true` will return to the release, the execution of the next interceptor, `false` does not return a corresponding executing method
And 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
For example, the path is `/user/login/check.do`
So 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.- [English document](https://github.com/xiexiaodong/Dreamvc/blob/master/README.md)
- [中文文档](https://github.com/xiexiaodong/Dreamvc/blob/master/README_ZH_CN.md)