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:
- @Insert returns the primary key ID, which can be of type int or long
- @Update returns the number of affected rows, it can execute insert, update, delete statements
- @Batch returns the number of affected rows
- @Get can return an object or a single value, just set the attribute
javaType=true
- @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. - The
sql
statement is written in the same way as theNamedParameterJdbcTemplate
in the Spring framework, and thesql
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