This commit is contained in:
开源海哥 2023-04-07 18:18:01 +08:00
parent bd1980fb7b
commit 3964754f8c
22 changed files with 176 additions and 122 deletions

View File

@ -9,7 +9,7 @@
<dependency> <dependency>
<groupId>com.mybatis-flex</groupId> <groupId>com.mybatis-flex</groupId>
<artifactId>mybatis-flex-codegen</artifactId> <artifactId>mybatis-flex-codegen</artifactId>
<version>1.0.7</version> <version>1.0.8</version>
</dependency> </dependency>
``` ```

View File

@ -25,7 +25,7 @@ CREATE TABLE IF NOT EXISTS `tb_account`
<dependency> <dependency>
<groupId>com.mybatis-flex</groupId> <groupId>com.mybatis-flex</groupId>
<artifactId>mybatis-flex-core</artifactId> <artifactId>mybatis-flex-core</artifactId>
<version>1.0.7</version> <version>1.0.8</version>
</dependency> </dependency>
``` ```

View File

@ -9,7 +9,7 @@
<dependency> <dependency>
<groupId>com.mybatis-flex</groupId> <groupId>com.mybatis-flex</groupId>
<artifactId>mybatis-flex-core</artifactId> <artifactId>mybatis-flex-core</artifactId>
<version>1.0.7</version> <version>1.0.8</version>
</dependency> </dependency>
``` ```
@ -19,7 +19,7 @@
<dependency> <dependency>
<groupId>com.mybatis-flex</groupId> <groupId>com.mybatis-flex</groupId>
<artifactId>mybatis-flex-spring</artifactId> <artifactId>mybatis-flex-spring</artifactId>
<version>1.0.7</version> <version>1.0.8</version>
</dependency> </dependency>
`````` ``````
@ -29,6 +29,6 @@
<dependency> <dependency>
<groupId>com.mybatis-flex</groupId> <groupId>com.mybatis-flex</groupId>
<artifactId>mybatis-flex-spring-boot-starter</artifactId> <artifactId>mybatis-flex-spring-boot-starter</artifactId>
<version>1.0.7</version> <version>1.0.8</version>
</dependency> </dependency>
``` ```

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>parent</artifactId> <artifactId>parent</artifactId>
<groupId>com.mybatis-flex</groupId> <groupId>com.mybatis-flex</groupId>
<version>1.0.7</version> <version>1.0.8</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>parent</artifactId> <artifactId>parent</artifactId>
<groupId>com.mybatis-flex</groupId> <groupId>com.mybatis-flex</groupId>
<version>1.0.7</version> <version>1.0.8</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@ -27,7 +27,7 @@
<dependency> <dependency>
<groupId>com.mybatis-flex</groupId> <groupId>com.mybatis-flex</groupId>
<artifactId>mybatis-flex-core</artifactId> <artifactId>mybatis-flex-core</artifactId>
<version>1.0.7</version> <version>1.0.8</version>
</dependency> </dependency>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>parent</artifactId> <artifactId>parent</artifactId>
<groupId>com.mybatis-flex</groupId> <groupId>com.mybatis-flex</groupId>
<version>1.0.7</version> <version>1.0.8</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@ -21,7 +21,7 @@
<dependency> <dependency>
<groupId>com.mybatis-flex</groupId> <groupId>com.mybatis-flex</groupId>
<artifactId>mybatis-flex-annotation</artifactId> <artifactId>mybatis-flex-annotation</artifactId>
<version>1.0.7</version> <version>1.0.8</version>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -20,7 +20,7 @@ package com.mybatisflex.core;
*/ */
public class FlexConsts { public class FlexConsts {
public static final String NAME = "MyBatis-Flex"; public static final String NAME = "MyBatis-Flex";
public static final String VERSION = "1.0.7"; public static final String VERSION = "1.0.8";
public static final String DEFAULT_PRIMARY_FIELD = "id"; public static final String DEFAULT_PRIMARY_FIELD = "id";

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>parent</artifactId> <artifactId>parent</artifactId>
<groupId>com.mybatis-flex</groupId> <groupId>com.mybatis-flex</groupId>
<version>1.0.7</version> <version>1.0.8</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@ -21,7 +21,7 @@
<dependency> <dependency>
<groupId>com.mybatis-flex</groupId> <groupId>com.mybatis-flex</groupId>
<artifactId>mybatis-flex-spring</artifactId> <artifactId>mybatis-flex-spring</artifactId>
<version>1.0.7</version> <version>1.0.8</version>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>parent</artifactId> <artifactId>parent</artifactId>
<groupId>com.mybatis-flex</groupId> <groupId>com.mybatis-flex</groupId>
<version>1.0.7</version> <version>1.0.8</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@ -20,7 +20,7 @@
<dependency> <dependency>
<groupId>com.mybatis-flex</groupId> <groupId>com.mybatis-flex</groupId>
<artifactId>mybatis-flex-core</artifactId> <artifactId>mybatis-flex-core</artifactId>
<version>1.0.7</version> <version>1.0.8</version>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>mybatis-flex-test</artifactId> <artifactId>mybatis-flex-test</artifactId>
<groupId>com.mybatis-flex</groupId> <groupId>com.mybatis-flex</groupId>
<version>1.0.7</version> <version>1.0.8</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@ -20,7 +20,7 @@
<dependency> <dependency>
<groupId>com.mybatis-flex</groupId> <groupId>com.mybatis-flex</groupId>
<artifactId>mybatis-flex-core</artifactId> <artifactId>mybatis-flex-core</artifactId>
<version>1.0.7</version> <version>1.0.8</version>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -16,10 +16,11 @@
package com.mybatisflex.test; package com.mybatisflex.test;
import com.mybatisflex.core.MybatisFlexBootstrap; import com.mybatisflex.core.MybatisFlexBootstrap;
import com.mybatisflex.core.audit.AuditManager;
import com.mybatisflex.core.audit.ConsoleMessageCollector;
import com.mybatisflex.core.row.Row; import com.mybatisflex.core.row.Row;
import com.mybatisflex.core.row.RowKey; import com.mybatisflex.core.row.RowKey;
import com.mybatisflex.core.row.RowMapper; import com.mybatisflex.core.row.RowMapper;
import org.apache.ibatis.logging.stdout.StdOutImpl;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
@ -37,9 +38,12 @@ public class RowTestStarter {
MybatisFlexBootstrap bootstrap = MybatisFlexBootstrap.getInstance() MybatisFlexBootstrap bootstrap = MybatisFlexBootstrap.getInstance()
.setDataSource(dataSource) .setDataSource(dataSource)
.setLogImpl(StdOutImpl.class) // .setLogImpl(StdOutImpl.class)
.start(); .start();
AuditManager.setAuditEnable(true);
AuditManager.setMessageCollector(new ConsoleMessageCollector());
//查询 ID 1 的数据 //查询 ID 1 的数据
Row row = bootstrap.execute(RowMapper.class, rowMapper -> Row row = bootstrap.execute(RowMapper.class, rowMapper ->

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>mybatis-flex-test</artifactId> <artifactId>mybatis-flex-test</artifactId>
<groupId>com.mybatis-flex</groupId> <groupId>com.mybatis-flex</groupId>
<version>1.0.7</version> <version>1.0.8</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@ -21,12 +21,7 @@
<dependency> <dependency>
<groupId>com.mybatis-flex</groupId> <groupId>com.mybatis-flex</groupId>
<artifactId>mybatis-flex-spring-boot-starter</artifactId> <artifactId>mybatis-flex-spring-boot-starter</artifactId>
<version>1.0.7</version> <version>1.0.8</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency> </dependency>
<dependency> <dependency>
@ -34,38 +29,48 @@
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
</dependency> </dependency>
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-jdbc</artifactId>-->
<!-- <version>2.7.9</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.springframework</groupId>-->
<!-- <artifactId>spring-jdbc</artifactId>-->
<!-- </dependency>-->
<dependency> <dependency>
<groupId>org.springframework</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-jdbc</artifactId> <artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.h2database</groupId> <groupId>com.h2database</groupId>
<artifactId>h2</artifactId> <artifactId>h2</artifactId>
<version>1.4.199</version> <version>2.1.214</version>
</dependency> </dependency>
<!-- <dependency>-->
<!-- <groupId>org.yaml</groupId>-->
<!-- <artifactId>snakeyaml</artifactId>-->
<!-- <version>1.33</version>-->
<!-- </dependency>-->
<dependency> <dependency>
<groupId>org.yaml</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>snakeyaml</artifactId> <artifactId>spring-boot-starter-test</artifactId>
<version>1.33</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <!-- <dependency>-->
<groupId>junit</groupId> <!-- <groupId>junit</groupId>-->
<artifactId>junit</artifactId> <!-- <artifactId>junit</artifactId>-->
<scope>test</scope> <!-- <scope>test</scope>-->
</dependency> <!-- </dependency>-->
</dependencies> </dependencies>

View File

@ -15,25 +15,22 @@
*/ */
package com.mybatisflex.test; package com.mybatisflex.test;
import com.mybatisflex.test.mapper.AccountMapper;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner; import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication @SpringBootApplication
@MapperScan("com.mybatisflex.test.mapper") //@MapperScan("com.mybatisflex.test.mapper")
public class SampleApplication implements CommandLineRunner { public class SampleApplication implements CommandLineRunner {
@Autowired // @Resource
private AccountMapper accountMapper; // private AccountMapper accountMapper;
@Override @Override
public void run(String... args) throws Exception { public void run(String... args) throws Exception {
System.out.println(this.accountMapper.selectOneById(1)); // System.out.println(this.accountMapper.selectOneById(1));
} }

View File

@ -1,60 +1,60 @@
/** ///**
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). // * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p> // * <p>
* Licensed under the Apache License, Version 2.0 (the "License"); // * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. // * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at // * You may obtain a copy of the License at
* <p> // * <p>
* http://www.apache.org/licenses/LICENSE-2.0 // * http://www.apache.org/licenses/LICENSE-2.0
* <p> // * <p>
* Unless required by applicable law or agreed to in writing, software // * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, // * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and // * See the License for the specific language governing permissions and
* limitations under the License. // * limitations under the License.
*/ // */
package com.mybatisflex.test.controller; //package com.mybatisflex.test.controller;
//
import com.mybatisflex.core.paginate.Page; //import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper; //import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.test.mapper.AccountMapper; //import com.mybatisflex.test.mapper.AccountMapper;
import com.mybatisflex.test.model.Account; //import com.mybatisflex.test.model.Account;
import org.springframework.beans.factory.annotation.Autowired; //import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; //import org.springframework.web.bind.annotation.*;
//
import java.util.Arrays; //import java.util.Arrays;
import java.util.List; //import java.util.List;
import java.util.stream.Collectors; //import java.util.stream.Collectors;
//
@RestController //@RestController
public class AccountController { //public class AccountController {
//
@Autowired // @Autowired
AccountMapper accountMapper; // AccountMapper accountMapper;
//
//
@PostMapping("/account/add") // @PostMapping("/account/add")
String add(@RequestBody Account account){ // String add(@RequestBody Account account){
accountMapper.insert(account); // accountMapper.insert(account);
return "add ok!"; // return "add ok!";
} // }
//
//
@GetMapping("/account/{id}") // @GetMapping("/account/{id}")
Account selectOne(@PathVariable("id") Long id) { // Account selectOne(@PathVariable("id") Long id) {
return accountMapper.selectOneById(id); // return accountMapper.selectOneById(id);
} // }
//
//
@GetMapping("/selectListByIds/{id}") // @GetMapping("/selectListByIds/{id}")
List<Account> selectListByIds(@PathVariable("id") String id) { // List<Account> selectListByIds(@PathVariable("id") String id) {
List<Long> ids = Arrays.stream(id.split(",")).mapToLong(Long::parseLong).boxed().collect(Collectors.toList()); // List<Long> ids = Arrays.stream(id.split(",")).mapToLong(Long::parseLong).boxed().collect(Collectors.toList());
return accountMapper.selectListByIds(ids); // return accountMapper.selectListByIds(ids);
} // }
//
//
@GetMapping("/paginate") // @GetMapping("/paginate")
Page<Account> paginate(@RequestParam(defaultValue = "1") int pageNumber, @RequestParam(defaultValue = "10") int pageSize) { // Page<Account> paginate(@RequestParam(defaultValue = "1") int pageNumber, @RequestParam(defaultValue = "10") int pageSize) {
return accountMapper.paginate(pageNumber,pageSize, QueryWrapper.create()); // return accountMapper.paginate(pageNumber,pageSize, QueryWrapper.create());
} // }
} //}

View File

@ -21,7 +21,7 @@ import com.mybatisflex.annotation.KeyType;
import java.util.Date; import java.util.Date;
@Table("tb_account") @Table(value = "tb_account",onSet = AccountOnSetListener.class)
public class Account { public class Account {
@Id(keyType = KeyType.Auto) @Id(keyType = KeyType.Auto)
@ -30,6 +30,8 @@ public class Account {
private Integer age; private Integer age;
private Date birthday; private Date birthday;
public Long getId() { public Long getId() {
return id; return id;
} }

View File

@ -0,0 +1,11 @@
package com.mybatisflex.test.model;
import com.mybatisflex.annotation.SetListener;
public class AccountOnSetListener implements SetListener {
@Override
public Object onSet(Object entity, String property, Object value) {
System.out.println(">>>>>>> property: " + property +" value:" + value);
return value;
}
}

View File

@ -1,12 +1,14 @@
# DataSource Config # DataSource Config
spring: spring:
h2:
console:
enabled: true
datasource: datasource:
url: jdbc:h2:mem:testdb
driver-class-name: org.h2.Driver driver-class-name: org.h2.Driver
schema: classpath:schema.sql username: sa
username: root password:
password: test
sql: sql:
init: init:
schema-locations: classpath:schema.sql schema-locations: classpath:schema.sql
data-locations: classpath:data.sql data-locations: classpath:data.sql
mybatis-flex:

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>mybatis-flex-test</artifactId> <artifactId>mybatis-flex-test</artifactId>
<groupId>com.mybatis-flex</groupId> <groupId>com.mybatis-flex</groupId>
<version>1.0.7</version> <version>1.0.8</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@ -20,13 +20,13 @@
<dependency> <dependency>
<groupId>com.mybatis-flex</groupId> <groupId>com.mybatis-flex</groupId>
<artifactId>mybatis-flex-core</artifactId> <artifactId>mybatis-flex-core</artifactId>
<version>1.0.7</version> <version>1.0.8</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.mybatis-flex</groupId> <groupId>com.mybatis-flex</groupId>
<artifactId>mybatis-flex-spring</artifactId> <artifactId>mybatis-flex-spring</artifactId>
<version>1.0.7</version> <version>1.0.8</version>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -20,7 +20,7 @@ import com.mybatisflex.annotation.Table;
import java.util.Date; import java.util.Date;
@Table("tb_account") @Table(value = "tb_account", onSet = AccountOnSetListener.class)
public class Account { public class Account {
@Id @Id
@ -60,4 +60,14 @@ public class Account {
public void setBirthday(Date birthday) { public void setBirthday(Date birthday) {
this.birthday = birthday; this.birthday = birthday;
} }
@Override
public String toString() {
return "Account{" +
"id=" + id +
", userName='" + userName + '\'' +
", age=" + age +
", birthday=" + birthday +
'}';
}
} }

View File

@ -0,0 +1,11 @@
package com.mybatisflex.test.model;
import com.mybatisflex.annotation.SetListener;
public class AccountOnSetListener implements SetListener {
@Override
public Object onSet(Object entity, String property, Object value) {
System.out.println(">>>>>>> property: " + property +" value:" + value);
return value;
}
}

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>parent</artifactId> <artifactId>parent</artifactId>
<groupId>com.mybatis-flex</groupId> <groupId>com.mybatis-flex</groupId>
<version>1.0.7</version> <version>1.0.8</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

14
pom.xml
View File

@ -7,7 +7,7 @@
<groupId>com.mybatis-flex</groupId> <groupId>com.mybatis-flex</groupId>
<artifactId>parent</artifactId> <artifactId>parent</artifactId>
<packaging>pom</packaging> <packaging>pom</packaging>
<version>1.0.7</version> <version>1.0.8</version>
<name>mybatis-flex</name> <name>mybatis-flex</name>
<url>https://mybatis-flex.com</url> <url>https://mybatis-flex.com</url>
@ -137,6 +137,18 @@
<version>${spring-boot.version}</version> <version>${spring-boot.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<!--for test--> <!--for test-->
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>