Project Introduction

MiniDao is a lightweight JAVA persistence layer framework, based on SpringJdbc + freemarker implementation, with the same SQL separation and logical labeling capabilities as Mybatis. The original intention of Minidao is to solve the Hibernate project. It has the same flexibility as Mybatis in complex SQL and supports transaction synchronization.

current version: v1.9.0 | 2022-09-02

Source code download

upgrade log

  • The version number of the upgrade dependency is consistent with the version number of jeecgboot, focusing on upgrading jsqlparser and refactoring incompatible methods
  • Upgrade springframework dependency to 5.3.18 and synchronize with jeecgboot
  • Upgrade spring-boot-starter dependency to 2.6.6, sync with jeecgboot
  • Upgrade javassist dependency to 3.25.0-GA
  • Upgrade jsqlparser dependency to 4.3
  • Upgrade the ognl version number to solve the error problem
  • SqlServer paging problem is not supported
  • Support user-defined data sources
  • SqlServer2012 (used by derby), PostgreSql, Shentong, Hsql, mysql paging optimization, if there are paging keywords, wrap them with select
  • There is no need to write the reflection breaking method, remove fields [j].setAccessible(true)
  • SQL Server table name keyword query failed

Technical Documentation

MiniDao Features

An powerful enhanced toolkit of SpringJdbc for simplify development

Has the following characteristics:

  • O/R mapping does not need to set xml, zero configuration is easy to maintain
  • No knowledge of JDBC is required
  • Separation of SQL statements and java code
  • Only interface definition is required, no interface implementation is required
  • SQL supports scripting language (powerful scripting language, freemarker syntax)
  • Supports lightweight and seamless integration with hibernate
  • Supports automatic transaction processing and manual transaction processing
  • Better performance than Mybatis
  • Easier to use than Mybatis
  • SQL supports annotation methods
  • SQL supports independent file mode. The naming rules of SQL files are: class name_method name; SQL files are easier to locate and facilitate later maintenance. The larger the project, the more obvious this advantage is.
  • SQL tags take Basic syntax of Freemarker

Code experience

1. Interface Definition [EmployeeDao.java]


@MiniDao
public interface EmployeeDao {

 @Arguments({ "employee"})
 @Sql("select * from employee")
 List<Map<String,Object>> getAll(Employee employee);

 @Sql("select * from employee where id = :id")
 Employee get(@Param("id") String id);

 @Sql("select * from employee where empno = :empno and  name = :name")
 Map getMap(@Param("empno")String empno,@Param("name")String name);

 @Sql("SELECT count(*) FROM employee")
 Integer getCount();

 int update(@Param("employee") Employee employee);

 void insert(@Param("employee") Employee employee);
 
 @ResultType(Employee.class)
 public MiniDaoPage<Employee> getAll(@Param("employee") Employee employee,@Param("page")  int page,@Param("rows") int rows);

}

2. SQL file [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>

3. Interface and SQL file corresponding directory

4. Test the code


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();
	String id = UUID.randomUUID().toString().replaceAll("-", "").toUpperCase();
	employee.setId(id);
	employee.setEmpno("A001");
	employee.setSalary(new BigDecimal(5000));
	employee.setBirthday(new Date());
	employee.setName("scott");
	employee.setAge(25);
	//调用minidao方法插入
	employeeDao.insert(employee);
}
}

#MiniDao #version #released #lightweight #Java #persistence #framework #News Fast Delivery

Leave a Comment

Your email address will not be published. Required fields are marked *