Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/edagarli/Nicole
自己动手写个框架
https://github.com/edagarli/Nicole
Last synced: 16 days ago
JSON representation
自己动手写个框架
- Host: GitHub
- URL: https://github.com/edagarli/Nicole
- Owner: edagarli
- License: gpl-3.0
- Created: 2016-01-22T03:13:48.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2019-01-20T08:07:47.000Z (almost 6 years ago)
- Last Synced: 2024-08-01T08:06:30.543Z (3 months ago)
- Language: Java
- Homepage:
- Size: 91.8 KB
- Stars: 11
- Watchers: 4
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Nicole
>只是用来理解mvc相关原理练手的
## 使用说明
整个项目核心是DispatcherServlet与HelperLoader
DispatcherServlet主要处理Request,Response分发,其实就是Servlet核心枢纽
HelperLoader用于项目启动时候加载到内存,包含:
* ClassHelper
* BeanHelper
* AopHelper
* IocHelper
* ControllerHelper顾名思义,就知道啥意思。
项目本身已经有一个简单的DatabaseHelper(Dao层)。不过为了实践下类似mybatis的SQL怎么去搞的,项目本身额外也包含了一个可以独立于项目之外可以单独使用的Dao层,见Dao包。
### 独立的Dao层使用说明
轻量级持久层解决方案,类Mybatis的SQL方式,事务统一管理。 具有以下特征:
* 1.O/R mapping不用设置xml,零配置便于维护
* 2.不需要了解JDBC的知识
* 3.SQL语句和java代码的分离
* 4.可以自动生成SQL语句
* 5.接口和实现分离,不用写持久层代码,用户只需写接口,以及某些接口方法对应的sql 它会通过AOP自动生成实现类
* 6.支持自动事务处理和手动事务处理
* 7.支持与hibernate轻量级无缝集成
* 8.整合了Hibernate+mybatis的两大优势,支持实体维护和SQL分离
* 9.SQL支持脚本语言### 接口定义[EmployeeDao.java]
@Dao
public interface EmployeeDao {
@Arguments("employee")
public List getAllEmployees(Employee employee);
@Arguments("empno")
Employee getEmployee(String empno);
@Arguments({"empno","name"})
Map getMap(String empno,String name);@Sql("SELECT count(*) FROM employee")
Integer getCount();@Arguments("employee")
int update(Employee employee);@Arguments("employee")
void insert(Employee employee);
}
### SQL文件[EmployeeDao_getAllEmployees.sql]
SELECT * FROM employee where 1=1
<#if employee.age ?exists>
and age = :employee.age
#if>
<#if employee.name ?exists>
and name = :employee.name
#if>
<#if employee.empno ?exists>
and empno = :employee.empno
#if>### Dao接口配置
examples.dao.*
### 测试代码
public class Client {
public static void main(String args[]) {
BeanFactory factory = new ClassPathXmlApplicationContext(
"applicationContext.xml");
EmployeeDao employeeDao = (EmployeeDao) factory.getBean("employeeDao");
Employee employee = new Employee();
List list = employeeDao.getAllEmployees(employee);
for(Map mp:list){
System.out.println(mp.get("id"));
System.out.println(mp.get("name"));
System.out.println(mp.get("empno"));
System.out.println(mp.get("age"));
System.out.println(mp.get("birthday"));
System.out.println(mp.get("salary"));
}
}
}