From dab9ee4b2fc93c8f2dfdc7b96c1e558ad91fdf48 Mon Sep 17 00:00:00 2001
From: "Yangkai.Shen" <237497819@qq.com>
Date: Wed, 14 Nov 2018 21:41:00 +0800
Subject: [PATCH] =?UTF-8?q?:sparkles:=20spring-boot-demo-orm-beetlsql=20?=
=?UTF-8?q?=E5=AE=8C=E6=88=90?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
spring-boot-demo-orm-beetlsql/README.md | 387 +++++++++++++++++-
spring-boot-demo-orm-beetlsql/pom.xml | 5 +
.../orm/beetlsql/config/BeetlConfig.java | 3 +
.../xkcoding/orm/beetlsql/entity/User.java | 2 +
.../orm/beetlsql/service/UserService.java | 14 +-
.../service/impl/UserServiceImpl.java | 29 +-
.../src/main/resources/application.yml | 41 +-
.../service/impl/UserServiceImplTest.java | 45 +-
8 files changed, 499 insertions(+), 27 deletions(-)
diff --git a/spring-boot-demo-orm-beetlsql/README.md b/spring-boot-demo-orm-beetlsql/README.md
index 06fd0e2..4de6300 100644
--- a/spring-boot-demo-orm-beetlsql/README.md
+++ b/spring-boot-demo-orm-beetlsql/README.md
@@ -1,3 +1,388 @@
# spring-boot-demo-orm-beetlsql
-> 此 demo 仍然存在问题
\ No newline at end of file
+> 此 demo 主要演示了 Spring Boot 如何整合 beetl sql 快捷操作数据库,使用的是beetl官方提供的beetl-framework-starter集成。集成过程不是十分顺利,没有其他的orm框架集成的便捷。
+
+## pom.xml
+
+```xml
+
+
+ * Beetl数据源配置 + *
+ * + * @package: com.xkcoding.orm.beetlsql.config + * @description: Beetl数据源配置 + * @author: yangkai.shen + * @date: Created in 2018/11/14 17:15 + * @copyright: Copyright (c) 2018 + * @version: V1.0 + * @modified: yangkai.shen + */ +@Configuration +public class BeetlConfig { + + /** + * Beetl需要显示的配置数据源,方可启动项目,大坑,切记! + */ + @Bean(name = "datasource") + public DataSource getDataSource(Environment env){ + HikariDataSource dataSource = new HikariDataSource(); + dataSource.setDriverClassName(env.getProperty("spring.datasource.driver-class-name")); + dataSource.setJdbcUrl(env.getProperty("spring.datasource.url")); + dataSource.setUsername(env.getProperty("spring.datasource.username")); + dataSource.setPassword(env.getProperty("spring.datasource.password")); + return dataSource; + } +} +``` + +## UserDao.java + +```java +/** + *+ * UserDao + *
+ * + * @package: com.xkcoding.orm.beetlsql.dao + * @description: UserDao + * @author: yangkai.shen + * @date: Created in 2018/11/14 16:18 + * @copyright: Copyright (c) 2018 + * @version: V1.0 + * @modified: yangkai.shen + */ +@Component +public interface UserDao extends BaseMapper+ * User Service + *
+ * + * @package: com.xkcoding.orm.beetlsql.service.impl + * @description: User Service + * @author: yangkai.shen + * @date: Created in 2018/11/14 16:28 + * @copyright: Copyright (c) 2018 + * @version: V1.0 + * @modified: yangkai.shen + */ +@Service +@Slf4j +public class UserServiceImpl implements UserService { + + private final UserDao userDao; + + @Autowired + public UserServiceImpl(UserDao userDao) { + this.userDao = userDao; + } + + /** + * 新增用户 + * + * @param user 用户 + */ + @Override + public User saveUser(User user) { + userDao.insert(user, true); + return user; + } + + /** + * 批量插入用户 + * + * @param users 用户列表 + */ + @Override + public void saveUserList(List+ * User Service测试 + *
+ * + * @package: com.xkcoding.orm.beetlsql.service.impl + * @description: User Service测试 + * @author: yangkai.shen + * @date: Created in 2018/11/14 16:30 + * @copyright: Copyright (c) 2018 + * @version: V1.0 + * @modified: yangkai.shen + */ +@Slf4j +public class UserServiceImplTest extends SpringBootDemoOrmBeetlsqlApplicationTests { + @Autowired + private UserService userService; + + @Test + public void saveUser() { + String salt = IdUtil.fastSimpleUUID(); + User user = User.builder().name("testSave3").password(SecureUtil.md5("123456" + salt)).salt(salt).email("testSave3@xkcoding.com").phoneNumber("17300000003").status(1).lastLoginTime(new DateTime()).createTime(new DateTime()).lastUpdateTime(new DateTime()).build(); + + user = userService.saveUser(user); + Assert.assertTrue(ObjectUtil.isNotNull(user.getId())); + log.debug("【user】= {}", user); + } + + @Test + public void saveUserList() { + List
* User Service测试
@@ -29,14 +38,40 @@ public class UserServiceImplTest extends SpringBootDemoOrmBeetlsqlApplicationTes
@Test
public void saveUser() {
+ String salt = IdUtil.fastSimpleUUID();
+ User user = User.builder().name("testSave3").password(SecureUtil.md5("123456" + salt)).salt(salt).email("testSave3@xkcoding.com").phoneNumber("17300000003").status(1).lastLoginTime(new DateTime()).createTime(new DateTime()).lastUpdateTime(new DateTime()).build();
+
+ user = userService.saveUser(user);
+ Assert.assertTrue(ObjectUtil.isNotNull(user.getId()));
+ log.debug("【user】= {}", user);
+ }
+
+ @Test
+ public void saveUserList() {
+ List