MiniDao 是一款轻量级JAVA持久层框架,基于 SpringJdbc freemarker 实现,具备Mybatis一样的Sql分离和逻辑标签能力。Minidao产生的初衷是为了解决Hibernate项目,在复杂SQL具备Mybatis一样的灵活能力,同时支持事务同步。
当前版本:v1.7.1 | 2021-03-29
源码下载An powerful enhanced toolkit of SpringJdbc for simplify development
具有以下特征:
@MiniDao
publicinterfaceEmployeeDao{
@Arguments({"employee"})
@Sql("select*fromemployee")
List<Map<String,Object>>getAll(Employeeemployee);
@Sql("select*fromemployeewhereid=:id")
Employeeget(@Param("id")Stringid);
@Sql("select*fromemployeewhereempno=:empnoandname=:name")
MapgetMap(@Param("empno")Stringempno,@Param("name")Stringname);
@Sql("SELECTcount(*)FROMemployee")
IntegergetCount();
intupdate(@Param("employee")Employeeemployee);
voidinsert(@Param("employee")Employeeemployee);
@ResultType(Employee.class)
publicMiniDaoPage<Employee>getAll(@Param("employee")Employeeemployee,@Param("page")intpage,@Param("rows")introws);
}
2. SQL文件[EmployeeDao_getAllEmployees.sql]
SELECT*FROMemployeewhere1=1
<#ifemployee.age?exists>
andage=:employee.age
</#if>
<#ifemployee.name?exists>
andname=:employee.name
</#if>
<#ifemployee.empno?exists>
andempno=:employee.empno
</#if>
3. 接口和SQL文件对应目录
publicclassClient{
publicstaticvoidmain(Stringargs[]){
Beanfactoryfactory=newClassPathXmlApplicationContext("applicationContext.xml");
EmployeeDaoemployeeDao=(EmployeeDao)factory.getBean("employeeDao");
Employeeemployee=newEmployee();
Stringid=UUID.randomUUID().toString().replaceAll("-","").toUpperCase();
employee.setId(id);
employee.setEmpno("A001");
employee.setSalary(newBigDecimal(5000));
employee.setBirthday(newDate());
employee.setName("scott");
employee.setAge(25);
//调用minidao方法插入
employeeDao.insert(employee);
}
}
Copyright © 2024 妖气游戏网 www.17u1u.com All Rights Reserved