View on GitHub

Minidao

J2EE 持久层轻量级解决方案

Download this project as a .zip file Download this project as a tar.gz file

MiniDao

MiniDao简介及特征

MiniDao是Jeecg自己的持久化解决方案,集成了Hibernate实体维护和Mybaits SQL分离的两大优势。 具有以下特征:

※向下兼容Hibernate实体维护方式,实体的增删改查SQL自动生成

接口和SQL文件对应目录

github

接口定义[EmployeeDao.java]

public interface EmployeeDao {
@Arguments("employee")
public List<Map> 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>

测试代码

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<Map> 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"));
    }
}
}

技术交流