kodvel
1.0.0
该项目的目的是提供一个简单的MVC结构来组织您的servlet应用程序。
Post类可以使用index方法来显示所有帖子, view单个帖子, edit编辑帖子表格,以邮寄请求保存帖子store 。 git clone https://github.com/rezve/kodvel.git
cd kodvel
├── Web Pages
│ ├── WEB-INF
│ │ ├── views # define your views in this folder (JSP files)
│ │ └── web.xml
│ └── resources # static resources (css,js,image, etc)
│
├── Source Packages
│ ├── app
│ │ ├── config # project configuration
│ │ ├── controllers # all the controller classes
│ │ ├── models # all models (Beans)
│ │ └── routes # register your routes here
│ └── Kodvel # system files
└── ...
步骤1:让我们首先在view/blog文件夹中创建一个简单的JSP视图
< %@page contentType="text/html" pageEncoding="UTF-8"% >
< %@ taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" % >
< html >
< head >
< meta http-equiv =" Content-Type " content =" text/html; charset=UTF-8 " >
< title > Blog </ title >
</ head >
< body >
< h1 > List of Posts </ h1 >
</ body >
</ html > SETP 2:现在,在app/controllers文件夹中创建一个控制器类。这将有助于我们的观点。
public class Blog extends Controller {
public void index ( HttpServletRequest req , HttpServletResponse res ) {
req . setAttribute ( "posts" , posts );
view ( "blog/posts" , req , res );
}
public void create ( HttpServletRequest req , HttpServletResponse res ) {
view ( "blog/create" , req , res );
}
...
}注意:控制器内部的所有方法(用于处理用户请求)都必须具有这两个参数。
我们已经完成了第一个控制器。现在注册它以接收用户请求。
步骤3:在app/routes/web.java中定义路由
public void registerRouter () {
...
Router . get ( "/blog" , new Blog (), "index" );
Router . get ( "/blog/create" , new Blog (), "create" );
}在这里,我们注册了我们的index方法,用于处理/blog的所有请求,并为/blog/create URL create方法。
完毕!让我们访问http:// localhost:8080/kodvel/blog
您将在浏览器中看到您的观点。
List of Posts
所以这是流动:
请阅读有关我们的行为准则的详细信息以及向我们提交拉的请求的过程的详细信息。
我们使用SEMVER进行版本控制。有关可用的版本,请参见此存储库上的标签。
另请参阅参与该项目的贡献者列表。
该项目已根据MIT许可证获得许可 - 有关详细信息,请参见许可证文件。