Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yudao-cloud
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
hblj
yudao-cloud
Commits
398d23cc
提交
398d23cc
authored
2月 22, 2019
作者:
YunaiV
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
增加 swagger 提供 API 文档功能
增加 mapstruct 提供 Bean 之间的复制
上级
aedecc44
隐藏空白字符变更
内嵌
并排
正在显示
22 个修改的文件
包含
640 行增加
和
28 行删除
+640
-28
pom.xml
product/pom.xml
+0
-1
pom.xml
product/product-application/pom.xml
+45
-0
ProductApplication.java
...main/java/cn/iocoder/mall/product/ProductApplication.java
+3
-9
ProductCategoryBO.java
...in/java/cn/iocoder/mall/product/bo/ProductCategoryBO.java
+70
-0
DatabaseConfiguration.java
...cn/iocoder/mall/product/config/DatabaseConfiguration.java
+15
-0
GlobalExceptionHandler.java
...n/iocoder/mall/product/config/GlobalExceptionHandler.java
+37
-0
GlobalResponseBodyAdvice.java
...iocoder/mall/product/config/GlobalResponseBodyAdvice.java
+27
-0
MVCConfiguration.java
...java/cn/iocoder/mall/product/config/MVCConfiguration.java
+24
-0
SwaggerConfiguration.java
.../cn/iocoder/mall/product/config/SwaggerConfiguration.java
+37
-0
ErrorCodeEnum.java
...java/cn/iocoder/mall/product/constants/ErrorCodeEnum.java
+32
-0
ProductCategoryController.java
...ll/product/controller/user/ProductCategoryController.java
+17
-4
ProductCategoryConvert.java
.../iocoder/mall/product/convert/ProductCategoryConvert.java
+28
-0
ProductSpuConvert.java
...va/cn/iocoder/mall/product/convert/ProductSpuConvert.java
+18
-0
ProductCategoryMapper.java
...va/cn/iocoder/mall/product/dao/ProductCategoryMapper.java
+16
-0
ProductCategoryDO.java
...cn/iocoder/mall/product/dataobject/ProductCategoryDO.java
+77
-2
ServiceException.java
...a/cn/iocoder/mall/product/exception/ServiceException.java
+47
-0
ProductCategoryService.java
.../iocoder/mall/product/service/ProductCategoryService.java
+25
-0
ProductSpuService.java
...va/cn/iocoder/mall/product/service/ProductSpuService.java
+4
-3
ProductCategoryVO.java
...in/java/cn/iocoder/mall/product/vo/ProductCategoryVO.java
+37
-0
RestResult.java
.../src/main/java/cn/iocoder/mall/product/vo/RestResult.java
+57
-0
ProductCategoryMapper.xml
...c/main/resources/mybatis/mapper/ProductCategoryMapper.xml
+11
-9
ProductSkuMapper.xml
...on/src/main/resources/mybatis/mapper/ProductSkuMapper.xml
+13
-0
没有找到文件。
product/pom.xml
浏览文件 @
398d23cc
...
...
@@ -13,7 +13,6 @@
<packaging>
pom
</packaging>
<modules>
<module>
product-application
</module>
<module>
product-service
</module>
<module>
product-service-api
</module>
</modules>
...
...
product/product-application/pom.xml
浏览文件 @
398d23cc
...
...
@@ -11,6 +11,10 @@
<artifactId>
product-rest
</artifactId>
<properties>
<org.mapstruct.version>
1.3.0.Final
</org.mapstruct.version>
</properties>
<dependencies>
<dependency>
<groupId>
cn.iocoder.mall
</groupId>
...
...
@@ -60,6 +64,46 @@
<version>
2.12.0
</version>
</dependency>
<dependency>
<groupId>
org.mapstruct
</groupId>
<artifactId>
mapstruct
</artifactId>
<!-- use mapstruct-jdk8 for Java 8 or higher -->
<version>
${org.mapstruct.version}
</version>
</dependency>
<dependency>
<groupId>
io.springfox
</groupId>
<artifactId>
springfox-swagger2
</artifactId>
<version>
2.9.2
</version>
</dependency>
<dependency>
<groupId>
io.springfox
</groupId>
<artifactId>
springfox-swagger-ui
</artifactId>
<version>
2.9.2
</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- 提供给 mapstruct 使用 -->
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-compiler-plugin
</artifactId>
<version>
3.5.1
</version>
<configuration>
<source>
1.8
</source>
<!-- or higher, depending on your project -->
<target>
1.8
</target>
<!-- or higher, depending on your project -->
<annotationProcessorPaths>
<path>
<groupId>
org.mapstruct
</groupId>
<artifactId>
mapstruct-processor
</artifactId>
<version>
${org.mapstruct.version}
</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
product/product-application/src/main/java/cn/iocoder/mall/product/Product
Rest
Application.java
→
product/product-application/src/main/java/cn/iocoder/mall/product/ProductApplication.java
浏览文件 @
398d23cc
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
class
ProductApplication
{
public
static
void
main
(
String
[]
args
)
{
ConfigurableApplicationContext
ctx
=
SpringApplication
.
run
(
ProductRestApplication
.
class
,
args
);
DataSource
ds
=
ctx
.
getBean
(
DataSource
.
class
);
System
.
out
.
println
(
ds
);
SpringApplication
.
run
(
ProductApplication
.
class
,
args
);
}
}
\ No newline at end of file
product/product-application/src/main/java/cn/iocoder/mall/product/bo/ProductCategoryBO.java
0 → 100644
浏览文件 @
398d23cc
package
cn
.
iocoder
.
mall
.
product
.
bo
;
/**
* 商品分类 BO
*/
public
class
ProductCategoryBO
{
/**
* 分类编号
*/
private
Integer
id
;
/**
* 父分类编号
*
* 如果不存在父级,则 pid = 0 。
*/
private
Integer
pid
;
/**
* 名称
*/
private
String
name
;
/**
* 分类图片
*/
private
String
picUrl
;
/**
* 排序值
*/
private
Integer
sort
;
public
Integer
getId
()
{
return
id
;
}
public
void
setId
(
Integer
id
)
{
this
.
id
=
id
;
}
public
Integer
getPid
()
{
return
pid
;
}
public
void
setPid
(
Integer
pid
)
{
this
.
pid
=
pid
;
}
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
String
getPicUrl
()
{
return
picUrl
;
}
public
void
setPicUrl
(
String
picUrl
)
{
this
.
picUrl
=
picUrl
;
}
public
Integer
getSort
()
{
return
sort
;
}
public
void
setSort
(
Integer
sort
)
{
this
.
sort
=
sort
;
}
}
product/product-application/src/main/java/cn/iocoder/mall/product/config/DatabaseConfiguration.java
0 → 100644
浏览文件 @
398d23cc
package
cn
.
iocoder
.
mall
.
product
.
config
;
import
org.mybatis.spring.annotation.MapperScan
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.transaction.annotation.EnableTransactionManagement
;
@Configuration
@MapperScan
(
"cn.iocoder.mall.product.dao"
)
// 扫描对应的 Mapper 接口
@EnableTransactionManagement
(
proxyTargetClass
=
true
)
// 启动事务管理。为什么使用 proxyTargetClass 参数,参见 https://blog.csdn.net/huang_550/article/details/76492600
public
class
DatabaseConfiguration
{
// 数据源,使用 HikariCP
}
\ No newline at end of file
product/product-application/src/main/java/cn/iocoder/mall/product/config/GlobalExceptionHandler.java
0 → 100644
浏览文件 @
398d23cc
package
cn
.
iocoder
.
mall
.
product
.
config
;
import
cn.iocoder.mall.product.constants.ErrorCodeEnum
;
import
cn.iocoder.mall.product.exception.ServiceException
;
import
cn.iocoder.mall.product.vo.RestResult
;
import
org.springframework.web.bind.MissingServletRequestParameterException
;
import
org.springframework.web.bind.annotation.ControllerAdvice
;
import
org.springframework.web.bind.annotation.ExceptionHandler
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
javax.servlet.http.HttpServletRequest
;
@ControllerAdvice
public
class
GlobalExceptionHandler
{
@ResponseBody
@ExceptionHandler
(
value
=
ServiceException
.
class
)
public
RestResult
serviceExceptionHandler
(
HttpServletRequest
req
,
Exception
e
)
{
ServiceException
ex
=
(
ServiceException
)
e
;
return
RestResult
.
error
(
ex
.
getCode
(),
ex
.
getMessage
());
}
@ResponseBody
@ExceptionHandler
(
value
=
Exception
.
class
)
public
RestResult
resultExceptionHandler
(
HttpServletRequest
req
,
Exception
e
)
{
// TODO 异常日志
e
.
printStackTrace
();
// TODO 翻译不同的异常
if
(
e
instanceof
MissingServletRequestParameterException
)
{
return
RestResult
.
error
(
ErrorCodeEnum
.
MISSING_REQUEST_PARAM_ERROR
.
getCode
(),
ErrorCodeEnum
.
MISSING_REQUEST_PARAM_ERROR
.
getMessage
());
}
// 返回
return
RestResult
.
error
(
ErrorCodeEnum
.
SYS_ERROR
.
getCode
(),
ErrorCodeEnum
.
SYS_ERROR
.
getMessage
());
}
}
\ No newline at end of file
product/product-application/src/main/java/cn/iocoder/mall/product/config/GlobalResponseBodyAdvice.java
0 → 100644
浏览文件 @
398d23cc
package
cn
.
iocoder
.
mall
.
product
.
config
;
import
cn.iocoder.mall.product.vo.RestResult
;
import
org.springframework.core.MethodParameter
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.server.ServerHttpRequest
;
import
org.springframework.http.server.ServerHttpResponse
;
import
org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice
;
//@ControllerAdvice
public
class
GlobalResponseBodyAdvice
implements
ResponseBodyAdvice
{
@Override
public
boolean
supports
(
MethodParameter
returnType
,
Class
converterType
)
{
return
true
;
// TODO 芋艿,未来,这里可以剔除掉一些,需要特殊返回的接口
}
@Override
public
Object
beforeBodyWrite
(
Object
body
,
MethodParameter
returnType
,
MediaType
selectedContentType
,
Class
selectedConverterType
,
ServerHttpRequest
request
,
ServerHttpResponse
response
)
{
if
(
body
instanceof
RestResult
)
{
return
body
;
}
return
RestResult
.
ok
(
body
);
}
}
\ No newline at end of file
product/product-application/src/main/java/cn/iocoder/mall/product/config/MVCConfiguration.java
0 → 100644
浏览文件 @
398d23cc
package
cn
.
iocoder
.
mall
.
product
.
config
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.web.servlet.config.annotation.EnableWebMvc
;
import
org.springframework.web.servlet.config.annotation.InterceptorRegistry
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurer
;
@EnableWebMvc
@Configuration
public
class
MVCConfiguration
implements
WebMvcConfigurer
{
// @Autowired
// private SecurityInterceptor securityInterceptor;
// @Reference
// private OAuth2Service oauth2Service;
@Override
public
void
addInterceptors
(
InterceptorRegistry
registry
)
{
// registry.addInterceptor(securityInterceptor);
}
}
\ No newline at end of file
product/product-application/src/main/java/cn/iocoder/mall/product/config/SwaggerConfiguration.java
0 → 100644
浏览文件 @
398d23cc
package
cn
.
iocoder
.
mall
.
product
.
config
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
springfox.documentation.builders.ApiInfoBuilder
;
import
springfox.documentation.builders.PathSelectors
;
import
springfox.documentation.builders.RequestHandlerSelectors
;
import
springfox.documentation.service.ApiInfo
;
import
springfox.documentation.spi.DocumentationType
;
import
springfox.documentation.spring.web.plugins.Docket
;
import
springfox.documentation.swagger2.annotations.EnableSwagger2
;
@Configuration
@EnableSwagger2
public
class
SwaggerConfiguration
{
@Bean
public
Docket
createRestApi
()
{
return
new
Docket
(
DocumentationType
.
SWAGGER_2
)
.
apiInfo
(
apiInfo
())
.
select
()
.
apis
(
RequestHandlerSelectors
.
basePackage
(
"cn.iocoder.mall.product.controller"
))
.
paths
(
PathSelectors
.
any
())
.
build
();
}
private
ApiInfo
apiInfo
()
{
return
new
ApiInfoBuilder
()
.
title
(
"商品子系统"
)
.
description
(
"商品子系统"
)
.
termsOfServiceUrl
(
"http://www.iocoder.cn"
)
.
version
(
"1.0.0"
)
.
build
();
}
}
\ No newline at end of file
product/product-application/src/main/java/cn/iocoder/mall/product/constants/ErrorCodeEnum.java
0 → 100644
浏览文件 @
398d23cc
package
cn
.
iocoder
.
mall
.
product
.
constants
;
/**
* 错误码枚举类
*
* 系统级异常,使用 2-001-000-000 段
*/
public
enum
ErrorCodeEnum
{
SYS_ERROR
(
2001001000
,
"服务端发生异常"
),
MISSING_REQUEST_PARAM_ERROR
(
2001001001
,
"参数缺失"
),
;
private
final
int
code
;
private
final
String
message
;
ErrorCodeEnum
(
int
code
,
String
message
)
{
this
.
code
=
code
;
this
.
message
=
message
;
}
public
int
getCode
()
{
return
code
;
}
public
String
getMessage
()
{
return
message
;
}
;
}
product/product-application/src/main/java/cn/iocoder/mall/product/controller/user/ProductCategoryController.java
浏览文件 @
398d23cc
package
cn
.
iocoder
.
mall
.
product
.
controller
.
user
;
import
cn.iocoder.mall.product.convert.ProductCategoryConvert
;
import
cn.iocoder.mall.product.service.ProductCategoryService
;
import
cn.iocoder.mall.product.vo.ProductCategoryVO
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.ArrayList
;
import
java.util.List
;
@RestController
@RequestMapping
(
"user/product/category"
)
@Api
(
"商品分类"
)
public
class
ProductCategoryController
{
// TODO 获得父编号为 id 的分类们 后面,使用 swagger 注释
@Autowired
private
ProductCategoryService
productCategoryService
;
@GetMapping
public
List
<
ProductCategoryVO
>
list
(
@RequestParam
(
"id"
)
Integer
id
)
{
return
new
ArrayList
<>();
@ApiOperation
(
"获得指定编号下的子分类的数组"
)
@ApiImplicitParam
(
name
=
"pid"
,
value
=
"指定分类编号"
,
required
=
true
)
public
List
<
ProductCategoryVO
>
list
(
@RequestParam
(
"pid"
)
Integer
pid
)
{
return
ProductCategoryConvert
.
INSTANCE
.
convertToVO
(
productCategoryService
.
getListByPid
(
pid
)
);
}
}
\ No newline at end of file
product/product-application/src/main/java/cn/iocoder/mall/product/convert/ProductCategoryConvert.java
0 → 100644
浏览文件 @
398d23cc
package
cn
.
iocoder
.
mall
.
product
.
convert
;
import
cn.iocoder.mall.product.bo.ProductCategoryBO
;
import
cn.iocoder.mall.product.dataobject.ProductCategoryDO
;
import
cn.iocoder.mall.product.vo.ProductCategoryVO
;
import
org.mapstruct.Mapper
;
import
org.mapstruct.Mappings
;
import
org.mapstruct.factory.Mappers
;
import
java.util.List
;
@Mapper
public
interface
ProductCategoryConvert
{
ProductCategoryConvert
INSTANCE
=
Mappers
.
getMapper
(
ProductCategoryConvert
.
class
);
@Mappings
({})
ProductCategoryBO
convertToBO
(
ProductCategoryDO
category
);
List
<
ProductCategoryBO
>
convertToBO
(
List
<
ProductCategoryDO
>
categoryList
);
@Mappings
({})
ProductCategoryVO
convertToVO
(
ProductCategoryBO
category
);
List
<
ProductCategoryVO
>
convertToVO
(
List
<
ProductCategoryBO
>
categoryList
);
}
\ No newline at end of file
product/product-application/src/main/java/cn/iocoder/mall/product/convert/ProductSpuConvert.java
0 → 100644
浏览文件 @
398d23cc
package
cn
.
iocoder
.
mall
.
product
.
convert
;
import
cn.iocoder.mall.product.bo.ProductSpuBO
;
import
cn.iocoder.mall.product.dataobject.ProductSpuDO
;
import
org.mapstruct.Mapper
;
import
org.mapstruct.Mappings
;
import
org.mapstruct.factory.Mappers
;
@Mapper
public
interface
ProductSpuConvert
{
ProductSpuConvert
INSTANCE
=
Mappers
.
getMapper
(
ProductSpuConvert
.
class
);
@Mappings
({})
ProductSpuBO
convert
(
ProductSpuDO
spu
);
}
\ No newline at end of file
product/product-application/src/main/java/cn/iocoder/mall/product/dao/ProductCategoryMapper.java
0 → 100644
浏览文件 @
398d23cc
package
cn
.
iocoder
.
mall
.
product
.
dao
;
import
cn.iocoder.mall.product.dataobject.ProductCategoryDO
;
import
org.apache.ibatis.annotations.Param
;
import
org.springframework.stereotype.Repository
;
import
java.util.List
;
@Repository
public
interface
ProductCategoryMapper
{
List
<
ProductCategoryDO
>
selectListByPidAndStatusOrderBySort
(
@Param
(
"pid"
)
Integer
pid
,
@Param
(
"status"
)
Integer
status
);
}
\ No newline at end of file
product/product-application/src/main/java/cn/iocoder/mall/product/dataobject/ProductCategoryDO.java
浏览文件 @
398d23cc
...
...
@@ -7,6 +7,8 @@ import java.util.Date;
*/
public
class
ProductCategoryDO
{
public
static
final
Integer
STATUS_ENABLE
=
1
;
/**
* 分类编号
*/
...
...
@@ -28,7 +30,7 @@ public class ProductCategoryDO {
/**
* 分类图片
*/
private
String
picU
RL
;
private
String
picU
rl
;
/**
* 排序值
*/
...
...
@@ -49,4 +51,76 @@ public class ProductCategoryDO {
*/
private
Integer
status
;
}
public
Integer
getId
()
{
return
id
;
}
public
void
setId
(
Integer
id
)
{
this
.
id
=
id
;
}
public
Integer
getPid
()
{
return
pid
;
}
public
void
setPid
(
Integer
pid
)
{
this
.
pid
=
pid
;
}
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
String
getDescription
()
{
return
description
;
}
public
void
setDescription
(
String
description
)
{
this
.
description
=
description
;
}
public
String
getPicUrl
()
{
return
picUrl
;
}
public
void
setPicUrl
(
String
picUrl
)
{
this
.
picUrl
=
picUrl
;
}
public
Integer
getSort
()
{
return
sort
;
}
public
void
setSort
(
Integer
sort
)
{
this
.
sort
=
sort
;
}
public
Date
getCreateTime
()
{
return
createTime
;
}
public
void
setCreateTime
(
Date
createTime
)
{
this
.
createTime
=
createTime
;
}
public
Date
getUpdateTime
()
{
return
updateTime
;
}
public
void
setUpdateTime
(
Date
updateTime
)
{
this
.
updateTime
=
updateTime
;
}
public
Integer
getStatus
()
{
return
status
;
}
public
void
setStatus
(
Integer
status
)
{
this
.
status
=
status
;
}
}
\ No newline at end of file
product/product-application/src/main/java/cn/iocoder/mall/product/exception/ServiceException.java
0 → 100644
浏览文件 @
398d23cc
package
cn
.
iocoder
.
mall
.
product
.
exception
;
/**
* 服务异常
*
* 参考 https://www.kancloud.cn/onebase/ob/484204 文章
*
* 一共 10 位,分成四段
*
* 第一段,1 位,类型
* 1 - 业务级别异常
* 2 - 系统级别异常
* 第二段,3 位,系统类型
* 001 - 用户系统
* 002 - 商品系统
* 003 - 订单系统
* 004 - 支付系统
* 005 - 优惠劵系统
* ... - ...
* 第三段,3 位,模块
* 不限制规则。
* 一般建议,每个系统里面,可能有多个模块,可以再去做分段。以用户系统为例子:
* 001 - OAuth2 模块
* 002 - User 模块
* 003 - MobileCode 模块
* 第四段,3 位,错误码
* 不限制规则。
* 一般建议,每个模块自增。
*/
public
class
ServiceException
extends
RuntimeException
{
/**
* 错误码
*/
private
final
Integer
code
;
public
ServiceException
(
Integer
code
,
String
message
)
{
super
(
message
);
this
.
code
=
code
;
}
public
Integer
getCode
()
{
return
code
;
}
}
\ No newline at end of file
product/product-application/src/main/java/cn/iocoder/mall/product/service/ProductCategoryService.java
0 → 100644
浏览文件 @
398d23cc
package
cn
.
iocoder
.
mall
.
product
.
service
;
import
cn.iocoder.mall.product.bo.ProductCategoryBO
;
import
cn.iocoder.mall.product.convert.ProductCategoryConvert
;
import
cn.iocoder.mall.product.dao.ProductCategoryMapper
;
import
cn.iocoder.mall.product.dataobject.ProductCategoryDO
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
@Service
// 实际上不用添加。添加的原因是,必须 Spring 报错提示
//@com.alibaba.dubbo.config.annotation.Service
public
class
ProductCategoryService
{
@Autowired
private
ProductCategoryMapper
productCategoryMapper
;
public
List
<
ProductCategoryBO
>
getListByPid
(
Integer
pid
)
{
List
<
ProductCategoryDO
>
categoryList
=
productCategoryMapper
.
selectListByPidAndStatusOrderBySort
(
pid
,
ProductCategoryDO
.
STATUS_ENABLE
);
return
ProductCategoryConvert
.
INSTANCE
.
convertToBO
(
categoryList
);
}
}
\ No newline at end of file
product/product-application/src/main/java/cn/iocoder/mall/product/service/ProductSpuService.java
浏览文件 @
398d23cc
package
cn
.
iocoder
.
mall
.
product
.
service
;
import
cn.iocoder.mall.product.bo.ProductSpuBO
;
import
cn.iocoder.mall.product.convert.ProductSpuConvert
;
import
cn.iocoder.mall.product.dao.ProductSpuMapper
;
import
cn.iocoder.mall.product.dataobject.ProductSpuDO
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -15,9 +16,8 @@ public class ProductSpuService implements cn.iocoder.mall.product.service.api.Pr
public
ProductSpuBO
getProductSpu
(
Integer
id
)
{
ProductSpuDO
productSpuDO
=
productSpuDAO
.
selectById
(
id
);
ProductSpuBO
productSpuBO
=
new
ProductSpuBO
();
// TODO 芋艿,后面改下
productSpuBO
.
setId
(
productSpuDO
.
getId
());
return
productSpuBO
;
// 转换成 BO
return
ProductSpuConvert
.
INSTANCE
.
convert
(
productSpuDO
);
}
}
\ No newline at end of file
product/product-application/src/main/java/cn/iocoder/mall/product/vo/ProductCategoryVO.java
浏览文件 @
398d23cc
package
cn
.
iocoder
.
mall
.
product
.
vo
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
@ApiModel
(
"商品分类"
)
public
class
ProductCategoryVO
{
@ApiModelProperty
(
value
=
"分类编号"
,
required
=
true
,
example
=
"1"
)
private
Integer
id
;
@ApiModelProperty
(
value
=
"分类名"
,
required
=
true
,
example
=
"手机"
)
private
String
name
;
@ApiModelProperty
(
value
=
"分类图片"
,
notes
=
"一般情况下,只有根分类才有图片"
,
example
=
"http://www.iocoder.cn/images/common/wechat_mp_2017_07_31_bak.jpg"
)
private
String
picUrl
;
public
Integer
getId
()
{
return
id
;
}
public
void
setId
(
Integer
id
)
{
this
.
id
=
id
;
}
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
String
getPicUrl
()
{
return
picUrl
;
}
public
void
setPicUrl
(
String
picUrl
)
{
this
.
picUrl
=
picUrl
;
}
}
\ No newline at end of file
product/product-application/src/main/java/cn/iocoder/mall/product/vo/RestResult.java
0 → 100644
浏览文件 @
398d23cc
package
cn
.
iocoder
.
mall
.
product
.
vo
;
public
class
RestResult
{
/**
* 错误码
*/
private
Integer
code
;
/**
* 错误提示
*/
private
String
message
;
/**
* 返回数据
*/
private
Object
data
;
public
static
RestResult
error
(
Integer
code
,
String
message
)
{
RestResult
result
=
new
RestResult
();
result
.
code
=
code
;
result
.
message
=
message
;
return
result
;
}
public
static
RestResult
ok
(
Object
data
)
{
RestResult
result
=
new
RestResult
();
result
.
code
=
0
;
result
.
data
=
data
;
result
.
message
=
""
;
return
result
;
}
public
Integer
getCode
()
{
return
code
;
}
public
void
setCode
(
Integer
code
)
{
this
.
code
=
code
;
}
public
String
getMessage
()
{
return
message
;
}
public
void
setMessage
(
String
message
)
{
this
.
message
=
message
;
}
public
Object
getData
()
{
return
data
;
}
public
void
setData
(
Object
data
)
{
this
.
data
=
data
;
}
}
\ No newline at end of file
product/product-application/src/main/resources/mybatis/mapper/ProductCategoryMapper.xml
浏览文件 @
398d23cc
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"cn.iocoder.mall.product.dao.Product
Spu
Mapper"
>
<?xml version="1.0" encoding="UTF-8"
?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"
>
<mapper
namespace=
"cn.iocoder.mall.product.dao.Product
Category
Mapper"
>
<select
id=
"select
ById"
parameterType=
"Integer"
resultType=
"ProductSpu
DO"
>
<select
id=
"select
ListByPidAndStatusOrderBySort"
resultType=
"ProductCategory
DO"
>
SELECT
id
FROM product_spu
WHERE id = #{id}
id, name, pic_url, sort
FROM product_category
WHERE pid = #{pid}
AND status = #{status}
ORDER BY sort ASC
</select>
</mapper>
\ No newline at end of file
</mapper>
product/product-application/src/main/resources/mybatis/mapper/ProductSkuMapper.xml
0 → 100644
浏览文件 @
398d23cc
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"cn.iocoder.mall.product.dao.ProductSpuMapper"
>
<select
id=
"selectById"
parameterType=
"Integer"
resultType=
"ProductSpuDO"
>
SELECT
id
FROM product_spu
WHERE id = #{id}
</select>
</mapper>
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论