ç¹æ§
- 强大çÂÂCRUDæÂÂä½Âï¼Âå 置éÂÂè¿Â注堥 LazyLambdaStream 对象å³å¯å®Âç°表åÂÂçÂÂ大é¨åÂÂCRUDæÂÂä½Â
- æ¯æÂÂLambdaå½¢å¼ÂçÂÂè°Âç¨@éÂÂè¿ÂLambda表达å¼Âï¼Âæ¹便çÂÂç¼ÂÃ¥ÂÂÃ¥ÂÂç±»æ¥询æ¡件
- å 置åÂÂ页æ¥询ï¼ÂéÂÂè¿ÂæÂÂé åÂÂ页对象æ¥询æ°æ®ç»Â计åÂÂ页æÂȾ°
- æ¯æÂÂå¤Âç§Âæ°æ®åºÂï¼Âæ¯æÂÂMySQL
æ¯æÂÂæ°æ®åºÂ
ä»»ä½Âè½使ç¨ LazyLambdaStreamè¿Âè¡ÂCRUDï¼Â并ä¸Âæ¯æÂÂæ ÂÃ¥ÂÂSQLçÂÂæ°æ®åºÂï¼Âå ·ä½Âæ¯æÂÂæ åµå¦Âä¸Â
- MySQL
代ç ÂæÂÂ管
Giteeï½ÂGithub
Ã¥ÂÂä¸Âè´¡ç®
欢è¿ÂÃ¥ÂÂä½ÂÃ¥ÂÂå¦ä¸Âèµ·åÂÂä¸Âå®ÂÃ¥ÂÂwu-database-lazy-starter
- è´¡ç®代ç Âï¼Â代ç Âå°åÂÂwu-database-lazy-starterï¼Â欢è¿ÂæÂÂ交IssueæÂÂè Pull Requests
æÂÂç¨ÂãÂÂæ¡Âä¾ÂãÂÂ使ç¨è åÂÂÃ¥ÂÂ
- æÂÂæÂÂ
çÂÂæÂŒÂÂè½
-
Lazy-DB æ¯ä¸Â款éÂÂ对æÂÂ人快éÂÂå¼ÂÃ¥ÂÂçÂÂORMæ¡Âæ¶
-
æ¯æÂÂå®Âä½Âç±»åÂÂå°Âæ°æ®è¿Âè¡Âæ°æ®åºÂCRUDæÂÂä½Â
-
æ°å¢Âçµæ§æ°æ®æÂÂå ¥æ´æ°(èªå¨è¿Â滤空å¼)
-
æ°å¢Âé Â置导åºæ°æ®忽çÂ¥æÂÂå®ÂÃ¥ÂÂ段
spring.datasource.ignore-exported-fields: – id -
æ°å¢Âé Â置声æÂÂ导åºæ°æ®ä¸ÂçÂÂç¹æ®ÂÃ¥ÂÂ符
spring.datasource.special-fields: – ASC -
æ°å¢Â@LazyScanèªå¨æ«æÂÂå®Âä½ÂÃ¥ÂÂ建表
-
æ°å¢Âèªå¨填堠表æ°æ®
-
æ°å¢ÂÃ¥ÂÂ建表æ¹æ³Â
-
æ°å¢Âæ´æ°表åÂÂ段æ¹æ³Â
-
ä¿®å¤Âæ°æ®æÂÂå ¥å¸Âå°Âç±»åÂÂãÂÂæ°åÂÂç±»åÂÂÃ¥ÂÂ段 Ã¥ÂÂ符串æ´æ¹为->Ã¥ÂÂå§Âæ°æ®类åÂÂ
-
æ°å¢ÂéÂÂÃ¥ÂÂå·¥ç¨ÂÃ¥ÂÂè½çÂÂæÂÂ对åºÂçÂÂJava class æ¯æÂÂmybatis éÂÂé Â
-
使ç¨Spring è¿Âè¡ÂäºÂç©管çÂÂ
-
ä¿®å¤Âæ°æ®为null æ¶æ§è¡Âsql æ°æ®为 “null” é®é¢Â
-
æ°å¢Âèªå¨è¿Â滤nullÃ¥ÂÂ段çÂÂupsertæÂ¥å£
å¿«éÂÂå¼Âå§Â
æÂÂ们å°ÂéÂÂè¿Âä¸Â个ç®ÂÃ¥ÂÂç Demo æÂ¥éÂÂè¿° wu-database-lazy-starter çÂÂ强大åÂÂè½ï¼Âå¨æ¤ä¹ÂÃ¥ÂÂï¼ÂæÂÂ们åÂÂ设æ¨已ç»Âï¼Â
- æÂ¥æ Java å¼ÂÃ¥ÂÂç¯å¢Â以åÂÂç¸庠IDE
- çÂÂæ Spring Boot
- çÂÂæ Maven
ç°æÂÂä¸Âå¼ User 表ï¼Â堶表ç»ÂæÂÂå¦Âä¸Âï¼Â
id | name | annual_salary | |
---|---|---|---|
1 | å´å°Â亠| 18 | test1@lazy.com |
2 | å´丠| 20 | test2@lazy.com |
3 | å´å°Âå | 28 | test3@lazy.com |
4 | å´å°Â亠| 21 | test4@lazy.com |
5 | å´å°Âå  | 24 | test5@lazy.com |
堶对åºÂçÂÂæ°æ®庠Schema èÂÂæ¬å¦Âä¸Âï¼Â
DROP TABLE IF EXISTS user;
CREATE TABLE user
(
id BIGINT(20) NOT NULL COMMENT '主é®ID',
name VARCHAR(30) NULL DEFAULT NULL COMMENT 'å§ÂÃ¥ÂÂ',
annual_salary INT(11) NULL DEFAULT NULL COMMENT 'å¹´èª',
email VARCHAR(50) NULL DEFAULT NULL COMMENT 'é®箱',
PRIMARY KEY (id)
);
堶对åºÂçÂÂæ°æ®庠Data èÂÂæ¬å¦Âä¸Âï¼Â
DELETE FROM user;
INSERT INTO user (id, name, annual_salary, email) VALUES
(1, 'å´å°ÂäºÂ', 18, 'test1@lazy.com'),
(2, 'å´ä¸Â', 20, 'test2@lazy.com'),
(3, 'å´å°ÂÃ¥ÂÂ', 28, 'test3@lazy.com'),
(4, 'å´å°ÂäºÂ', 21, 'test4@lazy.com'),
(5, 'å´å°ÂÃ¥Â
Â', 24, 'test5@lazy.com');
Ã¥ÂÂå§ÂÃ¥ÂÂå·¥ç¨Â
Ã¥ÂÂ建ä¸Â个空ç Spring Boot å·¥ç¨Âï¼Âå·¥ç¨Âå°Â以 MySQL ä½Â为é»Â认æ°æ®åºÂè¿Âè¡Âæ¼Â示ï¼Â
æ·»å ä¾ÂèµÂ
å¼Âå ¥ Spring Boot Starter ç¶工ç¨Âï¼Â
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.7</version>
<relativePath/>
</parent>
å¼Âå ¥ spring-boot-starterãÂÂspring-boot-starter-testãÂÂwu-database-lazy-starterãÂÂmysql ä¾ÂèµÂ
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--æÂÂ人ä¾ÂèµÂ-->
<dependency>
<groupId>top.wu2020</groupId>
<artifactId>wu-database-lazy-starter</artifactId>
<version>1.0.8-JDK1.8</version>
</dependency>
<!--mysql-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
</dependencies>
é Âç½®
å¨ application.yml é Âç½®æÂÂ件ä¸Âæ·»å mysql æ°æ®åºÂçÂÂç¸堳é Âç½®ï¼Â
# DataSource Config
spring:
datasource:
username: root
password: root
url: jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
driver-class-name: com.mysql.cj.jdbc.Driver
Spring Boot å¯å¨类ï¼Â
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
ç¼Âç Â
ç¼ÂÃ¥ÂÂå®Âä½Âç±» User.javaï¼Âæ¤å¤Â使ç¨亠Lombok ç®ÂÃ¥ÂÂ代ç Âï¼Â
@Data
public class User {
private Long id;
private String name;
private Integer annualSalary;
private String email;
}
å¼Âå§Â使ç¨
æ·»å æµÂè¯Âç±»ï¼Âè¿Âè¡ÂÃ¥ÂÂè½æµÂè¯Âï¼Â
@SpringBootTest
public class SampleTest {
@Autowired
LazyLambdaStream lazyLambdaStream;
@Test
public void testSelect() {
System.out.println(("----- selectAll method test ------"));
// çÂÂÃ¥ÂÂäºÂæ§è¡Âsql select * from sys_user
Collection<User> userList = lazyLambdaStream.select(LazyWrappers.<User>lambdaWrapper()).collection();
Assert.assertEquals(5, userList.size());
userList.forEach(System.out::println);
}
}
å°Âç»Â
éÂÂè¿Â以ä¸Âå 个ç®ÂÃ¥ÂÂçÂÂæ¥骤ï¼ÂæÂÂ们就å®Âç°亠User 表ç CRUD Ã¥ÂÂè½ï¼ÂçÂÂè³迠XML æÂÂ件é½ä¸Âç¨ç¼ÂÃ¥ÂÂï¼Â
å®Âè£Â
å ¨æ°ç wu-database-lazy-starter 1.0.8-JDK1.8 çÂÂ挺亠JDK8ï¼ÂæÂÂä¾Â亠lambda å½¢å¼ÂçÂÂè°Âç¨ï¼ÂæÂÂ以å®Â裠éÂÂæ MP3.0 è¦Âæ±Âå¦Âä¸Âï¼Â
- JDK 8+
- Maven or Gradle
Spring Boot
Mavenï¼Â
<dependency>
<groupId>top.wu2020</groupId>
<artifactId>wu-database-lazy-starter</artifactId>
<version>1.0.8-JDK1.8</version>
</dependency>
é Âç½®
wu-database-lazy-starter çÂÂé Âç½®å¼Â常çÂÂç®ÂÃ¥ÂÂï¼ÂæÂÂ们仠éÂÂè¦Âä¸ÂäºÂç®ÂÃ¥ÂÂçÂÂé Âç½®å³å¯使ç¨ wu-database-lazy-starter çÂÂ强大åÂÂè½ï¼Â
Spring Boot å·¥ç¨Â
- é Âç½®yaml
# DataSource Config
spring:
datasource:
username: root
password: root
url: jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
driver-class-name: com.mysql.cj.jdbc.Driver
注解
::: tip æ¾ÂÂå°Âä»Âç» wu-database-lazy-starter 注解å ç¸堳类详解ï¼Âæ´å¤Â详ç»ÂæÂÂè¿°å¯ç¹åÂȾÂ¥çÂÂæºÂç Â注éÂÂï¼ :::
- æÂÂè¿°
- 使ç¨ä½Â置对象
@LazyTable
@LazyTable(tableName="sys_user")
public class User {
private Long id;
private String name;
private Integer annualSalary;
private String email;
}
å±Âæ§ | ç±»å | å¿ é¡»æÂÂå® | é»Â认å¼ | æÂÂè¿° |
---|---|---|---|---|
tableName | String | å¦ | “” | 表å |
schema | String | å¦ | “” | schema |
comment | String | å¦ | “” | 表注é |
perfectTable | boolean | å¦ | “false” | å®ÂÃ¥ÂÂ表 |
smartFillField | boolean | å¦ | false | æºè½填堠beanå±Âæ§ éÂÂ对æ°æ®溠å¦Âmysqlæ¥询ç»ÂæÂÂãÂÂhttp请æ±Âç»ÂæÂÂä¸Âå å«çÂÂæ°æ®åÂÂ段ä¸ÂÃ¥ÂÂå½ÂÃ¥ÂÂ对象丠|
@LazyTableFieldId
@LazyTable(tableName="sys_user")
public class User {
@LazyTableFieldId
private Long id;
private String name;
private Integer annualSalary;
private String email;
}
å±Âæ§ | ç±»å | å¿ é¡»æÂÂå® | é»Â认å¼ | æÂÂè¿° |
---|---|---|---|---|
value | String | å¦ | “” | Ã¥ÂÂ段å |
name | String | å¦ | “” | Ã¥ÂÂ段å |
comment | String | å¦ | “” | Ã¥ÂÂ段注é |
type | String | å¦ | “” | Ã¥ÂÂ段äºÂç±»åÂÂï¼ÂvarcharãÂÂintçÂÂï¼ |
indexType | LayerField.LayerFieldType | å¦ | LayerField.LayerFieldType.ID | ç´¢å¼Âç±»å |
idType | IdType | å¦ | AUTOMATIC_ID | 主é®èªå¢Âç±»å |
LayerFieldType
å¼ | æÂÂè¿° |
---|---|
FIELD_TYPE | Ã¥ÂÂ段类å |
ID | æ°æ®庠ID |
UNIQUE | å¯ä¸Âæ§索张|
AUTOMATIC | èªå¨ç |
IdType
å¼ | æÂÂè¿° |
---|---|
AUTOMATIC_ID | 主é®ID é»Â认èª墠|
INPUT_ID | è¾Â堥主é® |
@LazyTableField
@LazyTable(tableName="sys_user")
public class User {
private Long id;
private String name;
@LazyTableField("salary")
private Integer annualSalary;
private String email;
}
å±Âæ§ | ç±»å | å¿ é¡»æÂÂå® | é»Â认å¼ | æÂÂè¿° |
---|---|---|---|---|
value | String | å¦ | “” | Ã¥ÂÂ段å |
name | String | å¦ | “” | Ã¥ÂÂ段å |
comment | String | å¦ | “” | Ã¥ÂÂ段注é |
columnType | String | å¦ | “” | Ã¥ÂÂ段äºÂç±»åÂÂï¼ÂvarcharãÂÂintçÂÂï¼ |
exist | boolean | å¦ | true | æ¯å¦åÂÂå¨ |
indexType | LayerField.LayerFieldType | å¦ | LayerField.LayerFieldType.ID | ç´¢å¼Âç±»å |
idType | IdType | å¦ | AUTOMATIC_ID | 主é®èªå¢Âç±»å |
å¿«éÂÂæµÂè¯Â
èªå¨导堥 wu-database-lazy-starter æµÂè¯ÂæÂÂéÂÂç¸堳é Âç½®ãÂÂ
示ä¾Âå·¥ç¨Â
æºÂç Âï¼Âð wu-database-lazy-starter-simple(opens new window)
使ç¨æÂÂç¨Â
æ·»å æµÂè¯Âä¾ÂèµÂ
Maven:
<dependency>
<groupId>top.wu2020</groupId>
<artifactId>wu-database-lazy-starter</artifactId>
<version>1.0.8-JDK1.8</version>
</dependency>
Gradleï¼Â
compile group: 'top.wu2020', name: 'wu-database-lazy-starter', version: '1.0.8-JDK1.8'
ç¼ÂÃ¥ÂÂæµÂè¯Âç¨ä¾Â
@Autowired
private LazyOperation lazyMysqlOperation;
/**
* ç¨æ·信æ¯ç®ÂÃ¥ÂÂæÂÂÃ¥Â
Â¥
*/
@ApiOperation("ç¨æ·信æ¯ç®ÂÃ¥ÂÂæÂÂÃ¥Â
Â¥")
@PostMapping("/lazy/upsert")
public void lazyUpsert() {
SysUser sysUser = new SysUser();
sysUser.setUsername("å°ÂæÂÂ¥");
sysUser.setPassword("1234");
sysUser.setId(1L);
// Ã¥ÂÂæ§è¡Âsql insert into sys_user (user_name,password,id) values("å°ÂæÂÂ¥","1234","1") ON DUPLICATE KEY UPDATE
user_name=values (user_name),password=values (password),id=values (id)
lazyMysqlOperation.upsert(sysUser);
}
æ ¸å¿ÂÃ¥ÂÂè½
代ç ÂçÂÂæÂÂå¨
å¿«éÂÂå¼Âå§Â
å®Âè£Â
<dependency>
<groupId>top.wu2020</groupId>
<artifactId>wu-database-lazy-starter</artifactId>
<version>1.0.8-JDK1.8</version>
</dependency>
::: tip ç´æ¥使ç¨mavenå¼Â堥项ç®ï¼ÂéÂÂè¿Âé Âç½®æÂÂ件å 载çÂÂæÂÂ代砠:::
é Âç½®æÂÂ件
spring:
lazy:
enable-reverse-engineering: true # Ã¥Â
Â许éÂÂÃ¥ÂÂå·¥ç¨Â
reverse-engineering:
enable-lazy: false # ä¸ÂÃ¥Â
Â许lazyç³»åÂÂ注解
enable-lombok-accessors: false # ä¸ÂÃ¥Â
Â许 lombok.accessors
enable-lombok-data: false # ä¸ÂÃ¥Â
Â许 lombok.data
package-name: com.wu.lazy # Ã¥ÂÂ
Ã¥ÂÂ
enable-swagger: false # ä¸ÂÃ¥Â
Â许 swagger
使ç¨
å¯å¨Spring-bootçÂÂå¯å¨类å³å¯
æÂÂÃ¥ÂÂ
Â
CRUD æÂ¥å£
upsert
/**
* æ¹éÂÂæ´æ°æÂÂæÂÂÃ¥Â
Â¥
*
* @param objects
* @param <T>
*/
<T> void upsert(Object... objects);
Ã¥ÂÂæ°说æÂÂ
ç±»å | Ã¥ÂÂæ°å | æÂÂè¿° |
---|---|---|
Object… | objects | ä»»æÂÂå®Âä½Â对象 |
upsert æ¡Âä¾Â
public static void main(String[] args) {
LazyLambdaStream lazyLambdaStream = LazyLambdaStreamFactory.createLazyLambdaStream(
"127.0.0.1",
3306,
"acw",
"root",
"wujiawei"
);
DataBaseUser dataBaseUser = new DataBaseUser();
dataBaseUser.setUsername("username");
dataBaseUser.setAddress("å°åÂÂ");
dataBaseUser.setAge(18);
// Ã¥ÂÂæ§è¡ÂSQL: insert into user (id,username,birthday,sex,age,age_type,address_id) VALUES (null,'username',null,null,18,null,null) ON DUPLICATE KEY UPDATE
//id=values (id),username=values (username),birthday=values (birthday),sex=values (sex),age=values (age),age_type=values (age_type),address_id=values (address_id)
lazyLambdaStream.upsert(dataBaseUser);
}
insert
/**
* æÂÂÃ¥Â
Â¥ Ã¥ÂÂ个/list
*
* @param t
* @param <T>
*/
<T> void insert(T t);
Ã¥ÂÂæ°说æÂÂ
ç±»å | Ã¥ÂÂæ°å | æÂÂè¿° |
---|---|---|
T | t | å®Âä½Â对象 |
insert æ¡Âä¾Â
public static void main(String[] args) {
LazyLambdaStream lazyLambdaStream = LazyLambdaStreamFactory.createLazyLambdaStream(
"127.0.0.1",
3306,
"acw",
"root",
"wujiawei"
);
DataBaseUser dataBaseUser = new DataBaseUser();
dataBaseUser.setUsername("username");
dataBaseUser.setAddress("å°åÂÂ");
dataBaseUser.setAge(18);
// Ã¥ÂÂæ§è¡ÂSQL: INSERT INTO user(username,birthday,sex,age,age_type,address_id)values(null,'username',null,null,'18',null,null)
lazyLambdaStream.insert(dataBaseUser);
}
smartUpsert
/**
* æ´æ°æÂÂèÂÂ
æÂÂÃ¥Â
¥åÂÂ个 Ã¥ÂȎ¤空å¼ãÂÂ对æ¯Â表
* å¤Â个æ°æ®æ§è½ä¼ÂæÂ
¢ï¼Âä¸Âç»Â常使ç¨
*/
Object smartUpsert(Object... t);
Ã¥ÂÂæ°说æÂÂ
ç±»å | Ã¥ÂÂæ°å | æÂÂè¿° |
---|---|---|
Object… | t | ä»»æÂÂå®Âä½Â对象 |
smartUpsert æ¡Âä¾Â
public static void main(String[] args) {
LazyLambdaStream lazyLambdaStream = LazyLambdaStreamFactory.createLazyLambdaStream(
"127.0.0.1",
3306,
"acw",
"root",
"wujiawei"
);
DataBaseUser dataBaseUser = new DataBaseUser();
dataBaseUser.setUsername("username");
dataBaseUser.setAddress("å°åÂÂ");
dataBaseUser.setAge(18);
// 没æÂÂ表ä¼Âèªå¨åÂÂ建表
/**
* -- âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂ
* -- create table user ç¨æ·信æ¯表
* -- add by wujiawei 2022-11-12
* -- âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂ
* CREATE TABLE IF NOT EXISTS `user` (
* address_id int(11) COMMENT 'null'
* ,age int(11) COMMENT ''
* ,age_type int(11) COMMENT ''
* ,birthday varchar(255) COMMENT ''
* ,id int(11) not null AUTO_INCREMENT COMMENT ''
* ,sex varchar(255) COMMENT ''
* ,username varchar(255) COMMENT ''
* ,PRIMARY KEY (id) USING BTREE
* , UNIQUE KEY `a_a_u` (`age`,`age_type`,`username`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='ç¨æ·信æ¯表';
* -- ------end
* -- âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂ
*/
// å æ§è¡ÂSQL: insert into user (id,username,age) VALUES (null,'username',18) ON DUPLICATE KEY UPDATE
// id=values (id),username=values (username),age=values (age)
lazyLambdaStream.smartUpsert(dataBaseUser);
}
upsertRemoveNull
/**
* æ´æ°æÂÂèÂÂ
æÂÂÃ¥Â
¥åÂÂ个æ§衠åÂȎ¤空å¼
* å¤Â个æ°æ®æ§è½ä¼ÂæÂ
¢ï¼Âä¸Âç»Â常使ç¨
*/
Object upsertRemoveNull(Object... t);
Ã¥ÂÂæ°说æÂÂ
ç±»å | Ã¥ÂÂæ°å | æÂÂè¿° |
---|---|---|
Object… | t | ä»»æÂÂå®Âä½Â对象 |
upsertRemoveNull æ¡Âä¾Â
public static void main(String[] args) {
LazyLambdaStream lazyLambdaStream = LazyLambdaStreamFactory.createLazyLambdaStream(
"127.0.0.1",
3306,
"acw",
"root",
"wujiawei"
);
Address address = new Address();
address.setId(1L);
address.setLongitude(1.2d);
// æ§è¡ÂSQL: insert into address (id,latitude,longitude) VALUES (1,'0.0','1.2') ON DUPLICATE KEY UPDATE
// id=values (id),latitude=values (latitude),longitude=values (longitude)
lazyLambdaStream.upsertRemoveNull(address);
List<Address> addresses = new ArrayList<>();
for (int i = 0; i < 10; i++) {
Address addressa = new Address();
address.setId(1L);
address.setLongitude(1.2d);
addresses.add(addressa);
}
// æ§è¡ÂSQL: insert into address (id,name,latitude,longitude) VALUES (null,null,'0.0','0.0'),(null,null,'0.0','0.0'),(null,null,'0.0','0.0'),(null,null,'0.0','0.0'),(null,null,'0.0','0.0'),(null,null,'0.0','0.0'),(null,null,'0.0','0.0'),(null,null,'0.0','0.0'),(null,null,'0.0','0.0'),(null,null,'0.0','0.0') ON DUPLICATE KEY UPDATE
// id=values (id),name=values (name),latitude=values (latitude),longitude=values (longitude)
lazyLambdaStream.upsert(addresses);
}
lazyPage
/**
* Ã¥ÂÂ页æ¥询
*
* @param <T>
* @return
*/
<T> Page<T> lazyPage(@NonNull Page lazyPage, @NonNull Class returnType, String sql, Object... params);
Ã¥ÂÂæ°说æÂÂ
ç±»å | Ã¥ÂÂæ°å | æÂÂè¿° |
---|---|---|
Page | lazyPage | Ã¥ÂÂ页对象 |
Class | returnType | è¿ÂÃ¥ÂÂæ°æ®类å |
String | sql | æ§è¡ÂçÂÂsqlè¯ÂÃ¥ÂÂ¥ |
Object… | params | sqlæ§è¡ÂÃ¥ÂÂæ° |
lazyPage æ¡Âä¾Â
public static void main(String[] args) {
LazyLambdaStream lazyLambdaStream = LazyLambdaStreamFactory.createLazyLambdaStream(
"127.0.0.1",
3306,
"acw",
"root",
"wujiawei"
);
// æ§è¡ÂSQL: select user.* from user where user.age > 18 and user.sex = 'ç·'
Page<DataBaseUser> dataBaseUserLazyPage = lazyLambdaStream.selectPage(LazyWrappers.<DataBaseUser>lambdaWrapper()
.gt(DataBaseUser::getAge, 18)
.eq(DataBaseUser::getSex, "ç·"),
new Page<>(1, 10)
);
System.out.println(dataBaseUserLazyPage);
}
executeSQL
/**
* @param sql
* @param t
* @param params
* @param <T>
* @return
*/
<T> List<T> executeSQL(String sql, Class t, Object... params);
Ã¥ÂÂæ°说æÂÂ
ç±»å | Ã¥ÂÂæ°å | æÂÂè¿° |
---|---|---|
Class | t | è¿ÂÃ¥ÂÂæ°æ®类å |
String | sql | æ§è¡ÂçÂÂsqlè¯ÂÃ¥ÂÂ¥ |
Object… | params | sqlæ§è¡ÂÃ¥ÂÂæ° |
executeSQL æ¡Âä¾Â
public static void main(String[] args) {
LazyLambdaStream lazyLambdaStream = LazyLambdaStreamFactory.createLazyLambdaStream(
"127.0.0.1",
3306,
"acw",
"root",
"wujiawei"
);
// æ§è¡ÂSQL: select user.* from user where user.age > 18 and user.sex = 'ç·'
List<DataBaseUser> dataBaseUsers = lazyLambdaStream.executeSQL("select user.* from user where user.age > %s and user.sex = '%s'", DataBaseUser.class, 18, "ç·");
System.out.println(dataBaseUsers);
}
executeSQLForBean
/**
* description æ§è¡ÂSQL è¿ÂÃ¥ÂÂæÂÂå®Âç±»åÂÂ
*
* @param
* @return
* @exception/throws
* @author Jiawei Wu
* @date 2020/12/29 ä¸ÂÃ¥ÂÂ1:44
*/
<T> T executeSQLForBean(String sql, Class t, Object... params);
Ã¥ÂÂæ°说æÂÂ
ç±»å | Ã¥ÂÂæ°å | æÂÂè¿° |
---|---|---|
Class | t | è¿ÂÃ¥ÂÂæ°æ®类å |
String | sql | æ§è¡ÂçÂÂsqlè¯ÂÃ¥ÂÂ¥ |
Object… | params | sqlæ§è¡ÂÃ¥ÂÂæ° |
executeSQLForBean æ¡Âä¾Â
public static void main(String[] args) {
LazyLambdaStream lazyLambdaStream = LazyLambdaStreamFactory.createLazyLambdaStream(
"127.0.0.1",
3306,
"acw",
"root",
"wujiawei"
);
// æ§è¡ÂSQL: select user.* from user where user.age > 18 and user.sex = 'ç·' limit 1
DataBaseUser dataBaseUser = lazyLambdaStream.executeSQLForBean("select user.* from user where user.age > %s and user.sex = '%s' limit 1", DataBaseUser.class, 18, "ç·");
System.out.println(dataBaseUser);
}
perfect
/**
* describe å®ÂÃ¥ÂÂ表
*
* @param entityClasss class 对象æ°ç»Â
* @return
* @author Jia wei Wu
* @date 2022/1/2 5:05 ä¸ÂÃ¥ÂÂ
**/
<T> T perfect(@NonNull Class... entityClasss);
Ã¥ÂÂæ°说æÂÂ
ç±»å | Ã¥ÂÂæ°å | æÂÂè¿° |
---|---|---|
Class… | entityClasss | å®Âä½Â对象 |
perfect æ¡Âä¾Â
Â
public static void main(String[] args) {
LazyLambdaStream lazyLambdaStream = LazyLambdaStreamFactory.createLazyLambdaStream(
"127.0.0.1",
3306,
"acw",
"root",
"wujiawei"
);
LazyDatabaseJsonMessage.dataSourceType = DataSourceType.MySQL;
// å®ÂÃ¥ÂÂ表ç»ÂæÂÂ
lazyLambdaStream.perfect(Address.class);
}
createTable
/**
* describe Ã¥ÂÂ建表
*
* @param
* @return
* @author Jia wei Wu
* @date 2022/1/2 7:48 ä¸ÂÃ¥ÂÂ
**/
<T> T createTable(@NonNull Class... entityClasss);
Ã¥ÂÂæ°说æÂÂ
ç±»å | Ã¥ÂÂæ°å | æÂÂè¿° |
---|---|---|
Class… | entityClasss | å®Âä½Â对象 |
createTable æ¡Âä¾Â
public static void main(String[] args) {
LazyLambdaStream lazyLambdaStream = LazyLambdaStreamFactory.createLazyLambdaStream(
"127.0.0.1",
3306,
"acw",
"root",
"wujiawei"
);
LazyDatabaseJsonMessage.dataSourceType = DataSourceType.MySQL;
// Ã¥ÂÂ建表
lazyLambdaStream.createTable(Address.class);
}
updateTable
/**
* describe æ´æ°表
*
* @param
* @return
* @author Jia wei Wu
* @date 2022/1/2 7:48 ä¸ÂÃ¥ÂÂ
**/
<T> T updateTable(@NonNull Class... entityClasss);
Ã¥ÂÂæ°说æÂÂ
ç±»å | Ã¥ÂÂæ°å | æÂÂè¿° |
---|---|---|
Class… | entityClasss | å®Âä½Â对象 |
updateTable æ¡Âä¾Â
public static void main(String[] args) {
LazyLambdaStream lazyLambdaStream = LazyLambdaStreamFactory.createLazyLambdaStream(
"127.0.0.1",
3306,
"acw",
"root",
"wujiawei"
);
LazyDatabaseJsonMessage.dataSourceType = DataSourceType.MySQL;
// æ´æ°表
lazyLambdaStream.updateTable(Address.class);
}
execute
/**
* æ§è¡ÂæÂÂä½Â
*
* @param persistenceRepository
* @return
*/
List<Object> execute(PersistenceRepository persistenceRepository);
Ã¥ÂÂæ°说æÂÂ
ç±»å | Ã¥ÂÂæ°å | æÂÂè¿° |
---|---|---|
PersistenceRepository | persistenceRepository | é¢Âæ§è¡ÂSQLéÂÂè¦ÂçÂÂå±Âæ§ |
execute æ¡Âä¾Â
// 使ç¨ç¸å½Âçµ活ãÂÂæ³åÂÂç©就åÂÂç©
executeOne
/**
* æ§è¡ÂæÂÂä½Â
*
* @param persistenceRepository
* @return
*/
Object executeOne(PersistenceRepository persistenceRepository);
Ã¥ÂÂæ°说æÂÂ
ç±»å | Ã¥ÂÂæ°å | æÂÂè¿° |
---|---|---|
PersistenceRepository | persistenceRepository | é¢Âæ§è¡ÂSQLéÂÂè¦ÂçÂÂå±Âæ§ |
executeOne æ¡Âä¾Â
public static void main(String[] args) {
LazyLambdaStream lazyLambdaStream = LazyLambdaStreamFactory.createLazyLambdaStream(
"127.0.0.1",
3306,
"acw",
"root",
"wujiawei"
);
PersistenceRepository persistenceRepository = PersistenceRepositoryFactory.create();
persistenceRepository.setQueryString("select user.* from user where user.age > 18 and user.sex = 'ç·' limit 1");
persistenceRepository.setExecutionType(LambdaTableType.SELECT);
persistenceRepository.setResultClass(DataBaseUser.class);
// æ§è¡ÂSQL: select user.* from user where user.age > 18 and user.sex = 'ç·' limit 1
DataBaseUser dataBaseUser = (DataBaseUser) lazyLambdaStream.executeOne(persistenceRepository);
System.out.println(dataBaseUser);
}
èªæÂÂæÂÂ人çÂÂæÂÂä½ÂæÂ¥å£
saveSqlFile
/**
* @param nameDatabase æ°æ®åºÂå é»Â认å½ÂÃ¥ÂÂè¿ÂæÂ¥æ°æ®
* System.getProperty("user.dir") æ°æ®æÂÂ件å°åÂÂ
* @return ä¿ÂÃ¥ÂÂæ°æ®å°æΡæ°æ®
* description æ°æ®åºÂæ°æ®åÂÂå¨å°sqlæÂÂ件(å é¤表åÂÂãÂÂÃ¥ÂÂ建表 æ°æ®使ç¨upsert)
* @author Jiawei Wu
* @date 2021/1/31 6:40 ä¸ÂÃ¥ÂÂ
**/
void saveSqlFile(String nameDatabase);
Ã¥ÂÂæ°说æÂÂ
ç±»å | Ã¥ÂÂæ°å | æÂÂè¿° |
---|---|---|
String | nameDatabase | æ°æ®åºÂå é»Â认å½ÂÃ¥ÂÂè¿ÂæÂ¥æ°æ® |
saveSoftSqlFile
/**
* @param nameDatabase æ°æ®åºÂå é»Â认å½ÂÃ¥ÂÂè¿ÂæÂ¥æ°æ®
* System.getProperty("user.dir") æ°æ®æÂÂ件å°åÂÂ
* @return ä¿ÂÃ¥ÂÂæ°æ®å°æΡæ°æ®
* description æÂÂÃ¥ÂÂå½¢ æ°æ®åºÂæ°æ®åÂÂå¨å°sqlæÂÂ件(表åÂÂå¨ä¸Âå é¤ æ°æ®使ç¨upsert)
* @author Jiawei Wu
* @date 2021/1/31 6:40 ä¸ÂÃ¥ÂÂ
**/
void saveSoftSqlFile(String nameDatabase);
Ã¥ÂÂæ°说æÂÂ
ç±»å | Ã¥ÂÂæ°å | æÂÂè¿° |
---|---|---|
String | nameDatabase | æ°æ®åºÂå é»Â认å½ÂÃ¥ÂÂè¿ÂæÂ¥æ°æ® |
saveUpsertSqlFile
/**
* describe 导åºå¢ÂéÂÂå¼Âæ´æ°æ°æ®
*
* @param nameDatabase æ°æ®åºÂå é»Â认å½ÂÃ¥ÂÂè¿ÂæÂ¥æ°æ®
* System.getProperty("user.dir") æ°æ®æÂÂ件å°åÂÂ
* @return ä¿ÂÃ¥ÂÂæ°æ®å°æΡæ°æ®
* @author Jia wei Wu
* @date 2022/4/9 22:57
**/
void saveUpsertSqlFile(String nameDatabase);
Ã¥ÂÂæ°说æÂÂ
ç±»å | Ã¥ÂÂæ°å | æÂÂè¿° |
---|---|---|
String | nameDatabase | æ°æ®åºÂå é»Â认å½ÂÃ¥ÂÂè¿ÂæÂ¥æ°æ® |
stuffed
/**
* èªå¨填åÂ
Â
æ°æ®
* SELECT
* *
* FROM
* information_schema.COLUMNS
* WHERE
* TABLE_SCHEMA = 'lazy'
* AND TABLE_NAME = 'sys_user';
*
* @param schema æ°æ®åºÂ
* @param table 表
* @param num æ°éÂÂ
*/
void stuffed(String schema, String table, Long num);
/**
* èªå¨填åÂ
Â
æ°æ®
* SELECT
* *
* FROM
* information_schema.COLUMNS
* WHERE
* TABLE_SCHEMA = 'lazy'
* AND TABLE_NAME = 'sys_user';
*
* @param table class 对åºÂæ°æ®åºÂç»ÂæÂÂçÂÂclass
* @param num æ°éÂÂ
*/
void stuffed(Class table, Long num);
Ã¥ÂÂæ°说æÂÂ
ç±»å | Ã¥ÂÂæ°å | æÂÂè¿° |
---|---|---|
String | schema | æ°æ®åºÂå |
String | table | 表å |
Long | num | æ°é |
stuffedAll
/**
* å¡ÂÃ¥Â
¥æÂÂæÂÂæ°æ®
*
* @param num
*/
void stuffedAll(Long num);
Ã¥ÂÂæ°说æÂÂ
ç±»å | Ã¥ÂÂæ°å | æÂÂè¿° |
---|---|---|
Long | num | Ã¥ÂÂå¨æ°æ®æ°é |
stuffedJava
/**
* describe æ ¹æ®表æÂÂÃ¥ÂÂ建åºJavaæÂÂ件
*
* @param schema æ°æ®åºÂ
* @param tableName 表åÂÂ
* @return
* @author Jia wei Wu
* @date 2022/1/23 12:23 ä¸ÂÃ¥ÂÂ
**/
void stuffedJava(String schema, String tableName);
Ã¥ÂÂæ°说æÂÂ
ç±»å | Ã¥ÂÂæ°å | æÂÂè¿° |
---|---|---|
String | schema | æ°æ®庠|
String | tableName | 表å |