Fred Feng

A passionate Java programmer

Just a passionate Java programmer and Like coding and reading


Download the theme

FastJDBC - Quick development kit based on spring-boot-starter-jdbc

fastjdbc-spring-boot-starter, which is a jdbc quick development kit based on the SpringBoot framework. It is actually a secondary encapsulation of the NamedJdbcTemplate provided by the spring framework, and provides an annotation-based API configuration method to operate SQL. At the same time, you can still use spring's spring-boot-starter-data-jdbc function.

Compatibility

  • JDK 1.8 (or later)
  • SpringBoot Framework 2.2.x (or later)

Install

<dependency>
	<groupId>com.github.paganini2008.springdessert</groupId>
	<artifactId>fastjdbc-spring-boot-starter</artifactId>
	<version>2.0.3</version>
</dependency>

Quick Start

@Dao
public interface UserDao {

	@Insert("insert into tb_user(username,password,age) values (:username,:password,:age)")
	int saveUser(@Example User user);

	@Update("update tb_user set username=:username, password=:password where id=:id")
	int updateUser(@Example User user);

	@Update("delete from tb_user where id=:id")
	int deleteUser(@Arg("id") int id);
	
	@Batch("insert into tb_user(username,password,age) values (:username,:password,:age)")
	int batchSaveUser(@Args List<User> userList);

	@Get("select * from tb_user where id=:id")
	User getById(@Arg int id);
	
	@Query("select * from tb_user order by create_time desc")
	List<Map<String, Object>> queryUser();

    @Query("select * from tb_user where 1=1 @sql order by create_time desc")
	List<Map<String, Object>> queryUserByCondition(@Sql String whereCondition, @Example Map<String,Object> queryExample);

	@Select("select * from tb_user order by create_time desc")
	ResultSetSlice<User> selectUser();

}

Description:

  1. @Insert returns the primary key ID, which can be of type int or long
  2. @Update returns the number of affected rows, it can execute insert, update, delete statements
  3. @Batch returns the number of affected rows
  4. @Get can return an object or a single value, just set the attribute javaType=true
  5. @Query and @Select are very similar. @Query returns a list without pagination. @Select supports both pagination and lists. It returns a ResultSetSlice object. This object is extremely powerful. Friends who are interested can study it.
  6. The sql statement is written in the same way as the NamedParameterJdbcTemplate in the Spring framework, and the sql statement is actually executed through it.

Finally,add @DaoScan into your code and make it work, for example, XXXConfiguration.java

@DaoScan(basePackages = "com.yourcompany.project.base.dao")
@Configuration(proxyBeanMethods = false)
public class XXXConfiguration {

}

Git Repository:https://github.com/paganini2008/springdessert.git

Recent Articles

Vortex - A High Performance Distributed Streaming Computing Framework

Vortex SeriesVortex is a lightweight distributed streaming computing framework. It is based on memory computing, which is suitable for high availability, high concurrency and real-time computing business scenarios.Vortex is developed based on Spri...…

Read More
Earlier Articles

Devtools Beans Streaming - A practical Java LINQ Tool

devtools-beans-streaming provide a approach like SQL query to tackle a Java object list. For example, searching specific attribute value, counting or aggregating some objects by attribute value (Similar to LINQ in C#)Install:<dependency> ...…

Read More