From aedecc44d18da29a4f245b0a569224d2589e33ca Mon Sep 17 00:00:00 2001
From: YunaiV <>
Date: Fri, 22 Feb 2019 00:01:06 +0800
Subject: [PATCH] =?UTF-8?q?=E6=8A=8A=20mybatis=20=E6=95=B4=E5=90=88?=
=?UTF-8?q?=E5=88=B0=E5=85=B6=E4=B8=AD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
product/product-application/pom.xml | 13 +++++++++++++
.../mall/product/ProductRestApplication.java | 9 ++++++++-
.../{ => user}/ProductCategoryController.java | 4 ++--
.../{ => user}/ProductSpuController.java | 4 ++--
.../mall/product/dao/ProductSpuDAO.java | 15 ---------------
.../mall/product/dao/ProductSpuMapper.java | 11 +++++++++++
.../product/service/ProductSpuService.java | 4 ++--
.../src/main/resources/application.yaml | 13 +++++++++++++
.../mybatis/mapper/ProductCategoryMapper.xml | 12 ++++++++++++
.../main/resources/mybatis/mybatis-config.xml | 19 +++++++++++++++++++
10 files changed, 82 insertions(+), 22 deletions(-)
rename product/product-application/src/main/java/cn/iocoder/mall/product/controller/{ => user}/ProductCategoryController.java (87%)
rename product/product-application/src/main/java/cn/iocoder/mall/product/controller/{ => user}/ProductSpuController.java (91%)
delete mode 100644 product/product-application/src/main/java/cn/iocoder/mall/product/dao/ProductSpuDAO.java
create mode 100644 product/product-application/src/main/java/cn/iocoder/mall/product/dao/ProductSpuMapper.java
create mode 100644 product/product-application/src/main/resources/application.yaml
create mode 100644 product/product-application/src/main/resources/mybatis/mapper/ProductCategoryMapper.xml
create mode 100644 product/product-application/src/main/resources/mybatis/mybatis-config.xml
diff --git a/product/product-application/pom.xml b/product/product-application/pom.xml
index 01a6224d5..ce024bf19 100644
--- a/product/product-application/pom.xml
+++ b/product/product-application/pom.xml
@@ -22,6 +22,19 @@
org.springframework.boot
spring-boot-starter-web
+
+ mysql
+ mysql-connector-java
+
+
+ org.springframework.boot
+ spring-boot-starter-jdbc
+
+
+ org.mybatis.spring.boot
+ mybatis-spring-boot-starter
+ 2.0.0
+
org.springframework.boot
diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/ProductRestApplication.java b/product/product-application/src/main/java/cn/iocoder/mall/product/ProductRestApplication.java
index 0af823ca0..c192eb487 100644
--- a/product/product-application/src/main/java/cn/iocoder/mall/product/ProductRestApplication.java
+++ b/product/product-application/src/main/java/cn/iocoder/mall/product/ProductRestApplication.java
@@ -1,13 +1,20 @@
package cn.iocoder.mall.product;
+import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.ConfigurableApplicationContext;
+
+import javax.sql.DataSource;
@SpringBootApplication
+@MapperScan("cn.iocoder.mall.product.dao") // 扫描对应的 Mapper 接口
public class ProductRestApplication {
public static void main(String[] args) {
- SpringApplication.run(ProductRestApplication.class, args);
+ ConfigurableApplicationContext ctx = SpringApplication.run(ProductRestApplication.class, args);
+ DataSource ds = ctx.getBean(DataSource.class);
+ System.out.println(ds);
}
}
\ No newline at end of file
diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/controller/ProductCategoryController.java b/product/product-application/src/main/java/cn/iocoder/mall/product/controller/user/ProductCategoryController.java
similarity index 87%
rename from product/product-application/src/main/java/cn/iocoder/mall/product/controller/ProductCategoryController.java
rename to product/product-application/src/main/java/cn/iocoder/mall/product/controller/user/ProductCategoryController.java
index fbe5d1b62..d9c087e15 100644
--- a/product/product-application/src/main/java/cn/iocoder/mall/product/controller/ProductCategoryController.java
+++ b/product/product-application/src/main/java/cn/iocoder/mall/product/controller/user/ProductCategoryController.java
@@ -1,4 +1,4 @@
-package cn.iocoder.mall.product.controller;
+package cn.iocoder.mall.product.controller.user;
import cn.iocoder.mall.product.vo.ProductCategoryVO;
import org.springframework.web.bind.annotation.GetMapping;
@@ -10,7 +10,7 @@ import java.util.ArrayList;
import java.util.List;
@RestController
-@RequestMapping("/product/category")
+@RequestMapping("user/product/category")
public class ProductCategoryController {
// TODO 获得父编号为 id 的分类们 后面,使用 swagger 注释
diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/controller/ProductSpuController.java b/product/product-application/src/main/java/cn/iocoder/mall/product/controller/user/ProductSpuController.java
similarity index 91%
rename from product/product-application/src/main/java/cn/iocoder/mall/product/controller/ProductSpuController.java
rename to product/product-application/src/main/java/cn/iocoder/mall/product/controller/user/ProductSpuController.java
index a11b616b3..6c9fd73c7 100644
--- a/product/product-application/src/main/java/cn/iocoder/mall/product/controller/ProductSpuController.java
+++ b/product/product-application/src/main/java/cn/iocoder/mall/product/controller/user/ProductSpuController.java
@@ -1,4 +1,4 @@
-package cn.iocoder.mall.product.controller;
+package cn.iocoder.mall.product.controller.user;
import cn.iocoder.mall.product.bo.ProductSpuBO;
import cn.iocoder.mall.product.service.ProductSpuService;
@@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
-@RequestMapping("/product/spu")
+@RequestMapping("user/product/spu")
public class ProductSpuController {
@Autowired
diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/dao/ProductSpuDAO.java b/product/product-application/src/main/java/cn/iocoder/mall/product/dao/ProductSpuDAO.java
deleted file mode 100644
index 84ff091ae..000000000
--- a/product/product-application/src/main/java/cn/iocoder/mall/product/dao/ProductSpuDAO.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package cn.iocoder.mall.product.dao;
-
-import cn.iocoder.mall.product.dataobject.ProductSpuDO;
-import org.springframework.stereotype.Repository;
-
-@Repository
-public class ProductSpuDAO {
-
- public ProductSpuDO selectById(Integer id) {
- ProductSpuDO spu = new ProductSpuDO();
- spu.setId(id);
- return spu;
- }
-
-}
\ No newline at end of file
diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/dao/ProductSpuMapper.java b/product/product-application/src/main/java/cn/iocoder/mall/product/dao/ProductSpuMapper.java
new file mode 100644
index 000000000..a7a814868
--- /dev/null
+++ b/product/product-application/src/main/java/cn/iocoder/mall/product/dao/ProductSpuMapper.java
@@ -0,0 +1,11 @@
+package cn.iocoder.mall.product.dao;
+
+import cn.iocoder.mall.product.dataobject.ProductSpuDO;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface ProductSpuMapper {
+
+ ProductSpuDO selectById(Integer id);
+
+}
\ No newline at end of file
diff --git a/product/product-application/src/main/java/cn/iocoder/mall/product/service/ProductSpuService.java b/product/product-application/src/main/java/cn/iocoder/mall/product/service/ProductSpuService.java
index b74d83122..387ce4082 100644
--- a/product/product-application/src/main/java/cn/iocoder/mall/product/service/ProductSpuService.java
+++ b/product/product-application/src/main/java/cn/iocoder/mall/product/service/ProductSpuService.java
@@ -1,7 +1,7 @@
package cn.iocoder.mall.product.service;
import cn.iocoder.mall.product.bo.ProductSpuBO;
-import cn.iocoder.mall.product.dao.ProductSpuDAO;
+import cn.iocoder.mall.product.dao.ProductSpuMapper;
import cn.iocoder.mall.product.dataobject.ProductSpuDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -11,7 +11,7 @@ import org.springframework.stereotype.Service;
public class ProductSpuService implements cn.iocoder.mall.product.service.api.ProductSpuService {
@Autowired
- private ProductSpuDAO productSpuDAO;
+ private ProductSpuMapper productSpuDAO;
public ProductSpuBO getProductSpu(Integer id) {
ProductSpuDO productSpuDO = productSpuDAO.selectById(id);
diff --git a/product/product-application/src/main/resources/application.yaml b/product/product-application/src/main/resources/application.yaml
new file mode 100644
index 000000000..4f0aaa78f
--- /dev/null
+++ b/product/product-application/src/main/resources/application.yaml
@@ -0,0 +1,13 @@
+spring:
+ # datasource
+ datasource:
+ url: jdbc:mysql://127.0.0.1:33061/mall_product?useSSL=false
+ driver-class-name: com.mysql.jdbc.Driver
+ username: root
+ password: 123456
+
+# mybatis
+mybatis:
+ config-location: classpath:mybatis/mybatis-config.xml
+ mapper-locations: classpath:mybatis/mapper/*.xml
+ type-aliases-package: cn.iocoder.mall.product.dataobject
\ No newline at end of file
diff --git a/product/product-application/src/main/resources/mybatis/mapper/ProductCategoryMapper.xml b/product/product-application/src/main/resources/mybatis/mapper/ProductCategoryMapper.xml
new file mode 100644
index 000000000..f3c090623
--- /dev/null
+++ b/product/product-application/src/main/resources/mybatis/mapper/ProductCategoryMapper.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/product/product-application/src/main/resources/mybatis/mybatis-config.xml b/product/product-application/src/main/resources/mybatis/mybatis-config.xml
new file mode 100644
index 000000000..7f604cc7e
--- /dev/null
+++ b/product/product-application/src/main/resources/mybatis/mybatis-config.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file