自己写的开源MVC-easyMVC分享
简介
基本风格是按照spring mvc做的,在后期会加入一些新的特性,封装成易于自己项目使用的mvc框架。
github地址:
https://github.com/tangyanbo/easymvc
功能简介:
1. 支持将客户端参数封装成对象,类型自动转换
2. 支持注解,配置controller和方法@RequestMapping
3. 方法中可以对request和response进行访问
4. 支持jstl
5. 可配置编码
6. controller方法的参数可以任意调换
7. 404报错提醒
8. restfull支持@PathVariable
快速使用入门
jar包:
在dist目录中copy easymvc.jar和依赖jar包到web项目中
在web项目中,resources目录下建立mvc-servlet.xml
<beans>
<!-- 编码 -->
<constant name="charsetEncoding">utf-8</constant> <!-- 扫描的目录 -->
<scan base-package="com.easymvc.controller"/> </beans>
web.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";
}
自己写的开源MVC-easyMVC分享的更多相关文章
- 分享一实战性开源MVC框架<Linux、Windows跨平台开发so easy>
一.引子 开源地址 https://github.com/564064202/Moon.Mvc 欢迎加入开发 .NET Core微软还在发力,但作为商用还有一段距离,很多开发库尚不能用于.NET ...
- 分享一个c#写的开源分布式消息队列equeue
分享一个c#写的开源分布式消息队列equeue 前言 equeue消息队列中的专业术语 Topic Queue Producer Consumer Consumer Group Broker 集群消费 ...
- 屌丝程序员的梦想 (六) 我也写个开源CMS
离开上家公司之后,我没急着找下家公司,一直以来都是为公司做各个细小的功能却没有属于自己的完整的项目 思来想去,我准备用自己熟悉的thinkphp 和 extjs写一个开源的cms,从用户系统,文章系统 ...
- EQueue - 一个C#写的开源分布式消息队列的总体介绍(转)
源: EQueue - 一个C#写的开源分布式消息队列的总体介绍 EQueue - 一个纯C#写的分布式消息队列介绍2 EQueue - 详细谈一下消息持久化以及消息堆积的设计
- RFID系统 免费开源代码 开发,分享[申明:来源于网络]
RFID系统 免费开源代码 开发,分享[申明:来源于网络] 地址:http://www.codeforge.cn/s/0/RFID%E7%B3%BB%E7%BB%9F
- 如果我写一个开源的HIS软件
HIS也称为医院信息管理系统,如果我要写一个 开源的,会成吗?为什么要这么做?出于对这个行业的担忧及其当前该行业的一些问题的思考.我曾跟两个HIS供应商讨论过这个话题,但可以感受到他们在利益面前,最终 ...
- 一步一步手写GIS开源项目-(2)地图平移缩放实现
系列文章目录 一步一步手写GIS开源项目-(1)500行代码实现基础GIS展示功能 一步一步手写GIS开源项目-(2)地图平移缩放实现 项目github地址:https://github.com/Hu ...
- 实用的开源百度云分享爬虫项目yunshare - 安装篇
今天开源了一个百度云网盘爬虫项目,地址是https://github.com/callmelanmao/yunshare. 百度云分享爬虫项目 github上有好几个这样的开源项目,但是都只提供了爬虫 ...
- 【开源.NET】 分享一个前后端分离的轻量级内容管理框架
开发框架要考虑的面太多了:安全.稳定.性能.效率.扩展.整洁,还要经得起实践的考验,从零开发一个可用的框架,是很耗时费神的工作.网上很多开源的框架,为何还要自己开发?我是基于以下两点: 没找到合适的: ...
随机推荐
- [总结]其他杂项数学相关(定理&证明&板子)
目录 写在前面 一类反演问题 莫比乌斯反演 快速莫比乌斯变换(反演)与子集卷积 莫比乌斯变换(反演) 子集卷积 二项式反演 内容 证明 应用举例 另一形式 斯特林反演 第一类斯特林数 第二类斯特林数 ...
- 从Spring-Session源码看Session机制的实现细节
Re:从零开始的Spring Session(一) Re:从零开始的Spring Session(二) Re:从零开始的Spring Session(三) 去年我曾经写过几篇和 Spring Sess ...
- RowFilter遇上特殊字符*%'[]\
开发时,时不时需要分析DataView的数据.计算,过滤等 .但是处理的值有可能会遇上是带有特殊字符*.%.'.[.]和\ .需要手动在表达式中,处理这些特殊字符,需要再使用"[" ...
- WPF ContextMenu的使用
<Grid.ContextMenu > <ContextMenu> <MenuItem Header="增加" Click="MenuIte ...
- 在net中json序列化与反序列化
准备好饮料,我们一起来玩玩JSON,什么是Json:一种数据表示形式,JSON:JavaScript Object Notation对象表示法 Json语法规则: 数据在键值对中 数据由逗号分隔 花括 ...
- sqlserver 删除表中数据 id 从1开始
TRUNCATE TABLE TbName --TbName是表名 但如果TbName中某些字段与其它表有主外键关系,会报错: 无法截断表 'Plants',因为该表正由 FOREIGN KE ...
- [日常] Go语言圣经-基于select的多路复用习题
练习 8.8: 使用select来改造8.3节中的echo服务器,为其增加超时,这样服务器可以在客户端10秒中没有任何喊话时自动断开连接. reverb3.go package main import ...
- springboot —— 多数据源
本文主要介绍如何在一个springboot项目配置两个数据源(mysql和oracle): 1.引进相关依赖 <!-- https://mvnrepository.com/artifact/my ...
- 【 js 基础 】【读书笔记】关于this
this 关键字是 Javascript 中很特别的一个关键字,被自动定义在所有函数的作用域中.this提供了一种更优雅的方式隐式“传递”一个对象的引用.今天就来说说 this 的指向问题. this ...
- 《JavaScript DOM 编程艺术》读书笔记
<JS DOM 编程艺术>笔记 一. 三种节点 元素节点.文本节点.属性节点 二. 获取元素 1.document.getElementById 2.(element)document.g ...