Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
springboot-demo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Leona
W
web
backend
springboot-demo
Commits
da556397
Commit
da556397
authored
Jun 29, 2020
by
duanledexianxianxian
😁
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add:menu
parent
0508e072
Changes
24
Show whitespace changes
Inline
Side-by-side
Showing
24 changed files
with
6 additions
and
1577 deletions
+6
-1577
demo/pom.xml
demo/pom.xml
+5
-0
demo/src/main/java/com/duanledexianxianxian/demo/CodeGenerator.java
...ain/java/com/duanledexianxianxian/demo/CodeGenerator.java
+0
-130
demo/src/main/java/com/duanledexianxianxian/demo/common/util/BeanUtils.java
.../com/duanledexianxianxian/demo/common/util/BeanUtils.java
+0
-575
demo/src/main/java/com/duanledexianxianxian/demo/config/MybatisPlusConfig.java
...m/duanledexianxianxian/demo/config/MybatisPlusConfig.java
+0
-26
demo/src/main/java/com/duanledexianxianxian/demo/dao/MenuDao.java
.../main/java/com/duanledexianxianxian/demo/dao/MenuDao.java
+0
-16
demo/src/main/java/com/duanledexianxianxian/demo/dao/UserDao.java
.../main/java/com/duanledexianxianxian/demo/dao/UserDao.java
+0
-29
demo/src/main/java/com/duanledexianxianxian/demo/domain/dto/MenuDTO.java
...ava/com/duanledexianxianxian/demo/domain/dto/MenuDTO.java
+0
-48
demo/src/main/java/com/duanledexianxianxian/demo/domain/dto/UserDTO.java
...ava/com/duanledexianxianxian/demo/domain/dto/UserDTO.java
+0
-54
demo/src/main/java/com/duanledexianxianxian/demo/domain/entity/Menu.java
...ava/com/duanledexianxianxian/demo/domain/entity/Menu.java
+0
-57
demo/src/main/java/com/duanledexianxianxian/demo/domain/entity/User.java
...ava/com/duanledexianxianxian/demo/domain/entity/User.java
+0
-54
demo/src/main/java/com/duanledexianxianxian/demo/domain/model/query/MenuForm.java
...uanledexianxianxian/demo/domain/model/query/MenuForm.java
+0
-48
demo/src/main/java/com/duanledexianxianxian/demo/domain/model/query/MenuQuery.java
...anledexianxianxian/demo/domain/model/query/MenuQuery.java
+0
-23
demo/src/main/java/com/duanledexianxianxian/demo/domain/model/query/UserForm.java
...uanledexianxianxian/demo/domain/model/query/UserForm.java
+0
-47
demo/src/main/java/com/duanledexianxianxian/demo/domain/model/query/UserQuery.java
...anledexianxianxian/demo/domain/model/query/UserQuery.java
+0
-40
demo/src/main/java/com/duanledexianxianxian/demo/domain/model/vo/MenuVO.java
...com/duanledexianxianxian/demo/domain/model/vo/MenuVO.java
+0
-45
demo/src/main/java/com/duanledexianxianxian/demo/domain/model/vo/UserDetailVO.java
...anledexianxianxian/demo/domain/model/vo/UserDetailVO.java
+0
-52
demo/src/main/java/com/duanledexianxianxian/demo/domain/model/vo/UserVO.java
...com/duanledexianxianxian/demo/domain/model/vo/UserVO.java
+0
-47
demo/src/main/java/com/duanledexianxianxian/demo/service/IMenuService.java
...a/com/duanledexianxianxian/demo/service/IMenuService.java
+0
-54
demo/src/main/java/com/duanledexianxianxian/demo/service/IUserService.java
...a/com/duanledexianxianxian/demo/service/IUserService.java
+0
-62
demo/src/main/java/com/duanledexianxianxian/demo/service/impl/MenuServiceImpl.java
...anledexianxianxian/demo/service/impl/MenuServiceImpl.java
+0
-58
demo/src/main/java/com/duanledexianxianxian/demo/service/impl/UserServiceImpl.java
...anledexianxianxian/demo/service/impl/UserServiceImpl.java
+0
-74
demo/src/main/resources/mapper/test/MenuDao.xml
demo/src/main/resources/mapper/test/MenuDao.xml
+0
-5
demo/src/main/resources/mapper/test/UserDao.xml
demo/src/main/resources/mapper/test/UserDao.xml
+0
-33
pom.xml
pom.xml
+1
-0
No files found.
demo/pom.xml
View file @
da556397
...
@@ -33,5 +33,10 @@
...
@@ -33,5 +33,10 @@
<groupId>
org.freemarker
</groupId>
<groupId>
org.freemarker
</groupId>
<artifactId>
freemarker
</artifactId>
<artifactId>
freemarker
</artifactId>
</dependency>
</dependency>
<dependency>
<groupId>
com.github.fengyuchenglun
</groupId>
<artifactId>
kim-boot-util
</artifactId>
<version>
1.0.13
</version>
</dependency>
</dependencies>
</dependencies>
</project>
</project>
\ No newline at end of file
demo/src/main/java/com/duanledexianxianxian/demo/CodeGenerator.java
deleted
100644 → 0
View file @
0508e072
package
com.duanledexianxianxian.demo
;
import
com.baomidou.mybatisplus.core.exceptions.MybatisPlusException
;
import
com.baomidou.mybatisplus.core.toolkit.StringPool
;
import
com.baomidou.mybatisplus.core.toolkit.StringUtils
;
import
com.baomidou.mybatisplus.generator.AutoGenerator
;
import
com.baomidou.mybatisplus.generator.InjectionConfig
;
import
com.baomidou.mybatisplus.generator.config.*
;
import
com.baomidou.mybatisplus.generator.config.po.TableInfo
;
import
com.baomidou.mybatisplus.generator.config.rules.NamingStrategy
;
import
com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Scanner
;
/**
* 代码生成器
*/
public
class
CodeGenerator
{
/**
* 读取控制台内容
*
* @param tip the tip
* @return the string
*/
public
static
String
scanner
(
String
tip
)
{
Scanner
scanner
=
new
Scanner
(
System
.
in
);
StringBuilder
help
=
new
StringBuilder
();
help
.
append
(
"请输入"
+
tip
+
":"
);
System
.
out
.
println
(
help
.
toString
());
if
(
scanner
.
hasNext
())
{
String
ipt
=
scanner
.
next
();
if
(
StringUtils
.
isNotEmpty
(
ipt
))
{
return
ipt
;
}
}
throw
new
MybatisPlusException
(
"请输入正确的"
+
tip
+
"!"
);
}
/**
* The entry point of application.
*
* @param args the input arguments
*/
public
static
void
main
(
String
[]
args
)
{
// 代码生成器
AutoGenerator
mpg
=
new
AutoGenerator
();
// 全局配置
GlobalConfig
gc
=
new
GlobalConfig
();
// 项目路径
String
projectPath
=
"F:/@project@/@dianli@/springboot-demo/demo"
;
gc
.
setOutputDir
(
projectPath
+
"/src/main/java"
);
gc
.
setAuthor
(
"duanledexianxianxian"
);
gc
.
setOpen
(
false
);
gc
.
setFileOverride
(
true
);
gc
.
setBaseResultMap
(
true
);
gc
.
setBaseColumnList
(
true
);
// gc.setSwagger2(true); 实体属性 Swagger2 注解
mpg
.
setGlobalConfig
(
gc
);
// 数据源配置
DataSourceConfig
dsc
=
new
DataSourceConfig
();
dsc
.
setUrl
(
"jdbc:mysql://rm-bp1451sz2b7q8w95xvo.mysql.rds.aliyuncs.com:3306/convention?useUnicode=true&useSSL=false&characterEncoding=utf8"
);
// dsc.setSchemaName("public");
dsc
.
setDriverName
(
"com.mysql.cj.jdbc.Driver"
);
dsc
.
setUsername
(
"convention"
);
dsc
.
setPassword
(
"Convention123"
);
mpg
.
setDataSource
(
dsc
);
// 包配置
PackageConfig
pc
=
new
PackageConfig
();
pc
.
setModuleName
(
scanner
(
"模块名"
));
pc
.
setParent
(
"com.duanledexianxianxian.demo"
);
mpg
.
setPackageInfo
(
pc
);
// 自定义配置
InjectionConfig
cfg
=
new
InjectionConfig
()
{
@Override
public
void
initMap
()
{
// to do nothing
}
};
// 如果模板引擎是 freemarker
String
templatePath
=
"/templates/mapper.xml.ftl"
;
// 如果模板引擎是 velocity
// String templatePath = "/templates/mapper.xml.vm";
// 自定义输出配置
List
<
FileOutConfig
>
focList
=
new
ArrayList
<>();
// 自定义配置会被优先输出
focList
.
add
(
new
FileOutConfig
(
templatePath
)
{
@Override
public
String
outputFile
(
TableInfo
tableInfo
)
{
// 自定义输出文件名 , 如果你 Entity 设置了前后缀、此处注意 xml 的名称会跟着发生变化!!
return
projectPath
+
"/src/main/resources/mapper/"
+
pc
.
getModuleName
()
+
"/"
+
tableInfo
.
getEntityName
()
+
"Mapper"
+
StringPool
.
DOT_XML
;
}
});
cfg
.
setFileOutConfigList
(
focList
);
mpg
.
setCfg
(
cfg
);
// 配置模板
TemplateConfig
templateConfig
=
new
TemplateConfig
();
templateConfig
.
setXml
(
null
);
mpg
.
setTemplate
(
templateConfig
);
// 策略配置
StrategyConfig
strategy
=
new
StrategyConfig
();
strategy
.
setNaming
(
NamingStrategy
.
underline_to_camel
);
strategy
.
setColumnNaming
(
NamingStrategy
.
underline_to_camel
);
// strategy.setSuperEntityClass("你自己的父类实体,没有就不用设置!");
strategy
.
setEntityLombokModel
(
true
);
strategy
.
setRestControllerStyle
(
true
);
// 公共父类
// strategy.setSuperControllerClass("你自己的父类控制器,没有就不用设置!");
// 写于父类中的公共字段
// strategy.setSuperEntityColumns("id");
strategy
.
setInclude
(
scanner
(
"表名,多个英文逗号分割"
).
split
(
","
));
strategy
.
setControllerMappingHyphenStyle
(
true
);
strategy
.
setTablePrefix
(
pc
.
getModuleName
()
+
"_"
);
mpg
.
setStrategy
(
strategy
);
mpg
.
setTemplateEngine
(
new
FreemarkerTemplateEngine
());
mpg
.
execute
();
}
}
demo/src/main/java/com/duanledexianxianxian/demo/common/util/BeanUtils.java
deleted
100644 → 0
View file @
0508e072
package
com.duanledexianxianxian.demo.common.util
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.BeansException
;
import
org.springframework.beans.FatalBeanException
;
import
org.springframework.util.Assert
;
import
org.springframework.util.ClassUtils
;
import
java.beans.PropertyDescriptor
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Modifier
;
import
java.util.*
;
/**
* BeanUtil提供一系列与bean相关的操作.
*
* @author duanledexianxianxian
* @date 2019-02-14 23:35:22
*/
public
class
BeanUtils
extends
org
.
springframework
.
beans
.
BeanUtils
{
/**
* The constant logger.
*/
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
BeanUtils
.
class
);
/**
* The constant SERIAL_VERSION_UID.
*/
private
static
final
String
SERIAL_VERSION_UID
=
"serialVersionUID"
;
/**
* The constant COMPARE_TYPE_INTEGER.
*/
private
static
final
String
COMPARE_TYPE_INTEGER
=
"java.lang.Integer"
;
/**
* The constant COMPARE_TYPE_STRING.
*/
private
static
final
String
COMPARE_TYPE_STRING
=
"java.lang.String"
;
/**
* Copy properties.
*
* @param source the source
* @param target the target
* @throws BeansException the beans exception
*/
public
static
void
copyProperties
(
Object
source
,
Object
target
)
throws
BeansException
{
copyProperties
(
source
,
target
,
null
,
(
String
[])
null
);
}
/**
* Copy properties.
*
* @param source the source
* @param target the target
* @param editable the editable
* @param ignoreProperties the ignore properties
* @throws BeansException the beans exception
*/
private
static
void
copyProperties
(
Object
source
,
Object
target
,
Class
<?>
editable
,
String
...
ignoreProperties
)
throws
BeansException
{
Assert
.
notNull
(
source
,
"Source must not be null"
);
Assert
.
notNull
(
target
,
"Target must not be null"
);
Class
<?>
actualEditable
=
target
.
getClass
();
if
(
editable
!=
null
)
{
if
(!
editable
.
isInstance
(
target
))
{
throw
new
IllegalArgumentException
(
"Target class ["
+
target
.
getClass
().
getName
()
+
"] not assignable to Editable class ["
+
editable
.
getName
()
+
"]"
);
}
actualEditable
=
editable
;
}
PropertyDescriptor
[]
targetPds
=
getPropertyDescriptors
(
actualEditable
);
List
<
String
>
ignoreList
=
(
ignoreProperties
!=
null
?
Arrays
.
asList
(
ignoreProperties
)
:
null
);
for
(
PropertyDescriptor
targetPd
:
targetPds
)
{
Method
writeMethod
=
targetPd
.
getWriteMethod
();
boolean
ignoreCondition
=
ignoreList
==
null
||
!
ignoreList
.
contains
(
targetPd
.
getName
());
if
(
writeMethod
!=
null
&&
ignoreCondition
)
{
PropertyDescriptor
sourcePd
=
getPropertyDescriptor
(
source
.
getClass
(),
targetPd
.
getName
());
if
(
sourcePd
!=
null
)
{
Method
readMethod
=
sourcePd
.
getReadMethod
();
boolean
isAssignable
=
ClassUtils
.
isAssignable
(
writeMethod
.
getParameterTypes
()[
0
],
readMethod
.
getReturnType
());
if
(
readMethod
!=
null
&&
isAssignable
)
{
try
{
setReadMethod
(
readMethod
);
Object
value
=
readMethod
.
invoke
(
source
);
// 这里判断以下value是否为空 当然这里也能进行一些特殊要求的处理 例如绑定时格式转换等等
setWriteMethodMethod
(
value
,
writeMethod
,
target
);
}
catch
(
Throwable
ex
)
{
throw
new
FatalBeanException
(
"Could not copy property '"
+
targetPd
.
getName
()
+
"' from source to target"
,
ex
);
}
}
}
}
}
}
/**
* Sets read method.
*
* @param readMethod the read method
*/
private
static
void
setReadMethod
(
Method
readMethod
)
{
if
(!
Modifier
.
isPublic
(
readMethod
.
getDeclaringClass
().
getModifiers
()))
{
readMethod
.
setAccessible
(
true
);
}
}
/**
* Sets write method method.
*
* @param value the value
* @param writeMethod the write method
* @param target the target
* @throws Exception the exception
*/
private
static
void
setWriteMethodMethod
(
Object
value
,
Method
writeMethod
,
Object
target
)
throws
Exception
{
if
(
value
!=
null
)
{
if
(!
Modifier
.
isPublic
(
writeMethod
.
getDeclaringClass
().
getModifiers
()))
{
writeMethod
.
setAccessible
(
true
);
}
writeMethod
.
invoke
(
target
,
value
);
}
}
/**
* 复制对象.
*
* @param <T> the type parameter
* @param entity the entity
* @param targetCls the target cls
* @return the t
*/
public
static
<
T
>
T
copyObject
(
Object
entity
,
Class
<?
extends
T
>
targetCls
)
{
// 如果entity,直接返回null
if
(
entity
==
null
)
{
return
null
;
}
Object
target
=
null
;
try
{
target
=
targetCls
.
newInstance
();
copyProperties
(
entity
,
target
);
}
catch
(
InstantiationException
|
IllegalAccessException
e
)
{
logger
.
error
(
"error:{}"
,
e
);
}
return
(
T
)
target
;
}
/**
* 复制对象
*
* @param list the list
* @param targetCls the target cls
* @return list list
*/
public
static
List
copyList
(
List
list
,
Class
<?>
targetCls
)
{
List
resultList
=
new
ArrayList
();
if
(
list
!=
null
&&
list
.
size
()
>
0
)
{
for
(
Object
entity
:
list
)
{
resultList
.
add
(
copyObject
(
entity
,
targetCls
));
}
}
return
resultList
;
}
/**
* java反射bean的get方法
*
* @param objectClass the object class
* @param fieldName the field name
* @return get method
*/
@SuppressWarnings
(
"unchecked"
)
public
static
Method
getGetMethod
(
Class
objectClass
,
String
fieldName
)
{
StringBuffer
sb
=
new
StringBuffer
();
sb
.
append
(
"get"
);
sb
.
append
(
fieldName
.
substring
(
0
,
1
).
toUpperCase
());
sb
.
append
(
fieldName
.
substring
(
1
));
try
{
return
objectClass
.
getMethod
(
sb
.
toString
());
}
catch
(
NoSuchMethodException
e
)
{
e
.
printStackTrace
();
logger
.
error
(
"error:{}"
,
e
);
}
return
null
;
}
/**
* java反射bean的set方法
*
* @param objectClass the object class
* @param fieldName the field name
* @return set method
*/
@SuppressWarnings
(
"unchecked"
)
public
static
Method
getSetMethod
(
Class
objectClass
,
String
fieldName
)
{
try
{
Class
[]
parameterTypes
=
new
Class
[
1
];
Field
field
=
objectClass
.
getDeclaredField
(
fieldName
);
parameterTypes
[
0
]
=
field
.
getType
();
StringBuffer
sb
=
new
StringBuffer
();
sb
.
append
(
"set"
);
sb
.
append
(
fieldName
.
substring
(
0
,
1
).
toUpperCase
());
sb
.
append
(
fieldName
.
substring
(
1
));
Method
method
=
objectClass
.
getMethod
(
sb
.
toString
(),
parameterTypes
);
return
method
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
logger
.
error
(
"error:{}"
,
e
);
}
return
null
;
}
/**
* 执行set方法
*
* @param o 执行对象
* @param fieldName 属性
* @param value 值
*/
public
static
void
invokeSet
(
Object
o
,
String
fieldName
,
Object
value
)
{
Method
method
=
getSetMethod
(
o
.
getClass
(),
fieldName
);
try
{
method
.
invoke
(
o
,
new
Object
[]{
value
});
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
logger
.
error
(
"error:{}"
,
e
);
}
}
/**
* 这个函数主要用于将字符串和数字型分开 前台都是字符串 根据model类型转换 现在仅支持String int 不是这两个类型不做set函数<br>.
*
* @param o the o
* @param fieldName the field name
* @param value the value
*/
public
static
void
invokeSetStringInt
(
Object
o
,
String
fieldName
,
String
value
)
{
Method
method
=
getGetMethod
(
o
.
getClass
(),
fieldName
);
String
type
=
method
.
getReturnType
().
getName
();
if
(
COMPARE_TYPE_INTEGER
.
equals
(
type
))
{
invokeSet
(
o
,
fieldName
,
(
value
==
null
)
?
null
:
Integer
.
parseInt
(
value
));
}
else
if
(
COMPARE_TYPE_STRING
.
equals
(
type
))
{
invokeSet
(
o
,
fieldName
,
value
);
}
else
{
logger
.
error
(
"set 函数不能设置Sting和int以外的函数,设置类型:"
+
type
+
",方法:"
+
method
.
getName
());
}
}
/**
* 执行get方法
*
* @param o 执行对象
* @param fieldName 属性
* @return the object
*/
public
static
Object
invokeGet
(
Object
o
,
String
fieldName
)
{
Method
method
=
getGetMethod
(
o
.
getClass
(),
fieldName
);
try
{
return
method
.
invoke
(
o
,
new
Object
[
0
]);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
logger
.
error
(
"error:{}"
,
e
);
}
return
null
;
}
/**
* 将返回值包装成String 如果是空则仍然保持空.
*
* @param o the o
* @param fieldName the field name
* @return the string
*/
public
static
String
invokeGetString
(
Object
o
,
String
fieldName
)
{
Object
obj
=
invokeGet
(
o
,
fieldName
);
return
(
obj
==
null
)
?
null
:
String
.
valueOf
(
obj
);
}
/**
* Merger obj object.
*
* @param <T> 项目域对象如果为空,则直接返回产品域对象项目域对象字段属性为空,则使用产品域覆盖项目域字段
* @param parent 产品域对象
* @param son 项目域对象
* @param refClass class对象
* @return the object
*/
public
static
<
T
>
Object
mergerObj
(
T
parent
,
T
son
,
Class
<?>
refClass
)
{
Object
obj
=
null
;
try
{
obj
=
refClass
.
newInstance
();
if
(
parent
==
null
)
{
obj
=
son
;
}
else
if
(
son
==
null
)
{
obj
=
parent
;
}
else
{
for
(
Field
field
:
refClass
.
getDeclaredFields
())
{
String
fieldName
=
field
.
getName
();
if
(
SERIAL_VERSION_UID
.
equalsIgnoreCase
(
fieldName
))
{
continue
;
}
Object
value
=
invokeGet
(
son
,
fieldName
);
if
(
value
==
null
)
{
value
=
invokeGet
(
parent
,
fieldName
);
}
invokeSet
(
obj
,
fieldName
,
value
);
}
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
logger
.
error
(
"error:{}"
,
e
);
}
logger
.
debug
(
"Page object:"
+
obj
);
return
obj
;
}
/**
* Merger obj object.
*
* @param <T> the type parameter
* @param parent the parent
* @param son the son
* @param refClassParent the ref class parent
* @param refClassSon the ref class son
* @return the object
*/
public
static
<
T
>
Object
mergerObj
(
T
parent
,
T
son
,
Class
<?>
refClassParent
,
Class
<?>
refClassSon
)
{
return
mergerObj
(
parent
,
son
,
refClassParent
,
refClassSon
,
null
);
}
/**
* Merger obj object.
*
* @param <T> 父对象为空,则直接返回子对象<br>
* 子对象为空,则将子对象域父对象相同的字段拷贝给obj<br>
* 父对象与子对象都不为空,现将子对象的值拷贝给obj,在将子对象与父对象相同的字段拷贝给obj<br>
* 例如:比如指标与业务视图字段合并,则指标为父对象、业务视图字段为子对象变量命名有问题<br>
* @param parent 父对象
* @param son 子对象
* @param refClassParent 父class对象
* @param refClassSon 子class对象
* @param prefix 前缀
* @return the object
*/
public
static
<
T
>
Object
mergerObj
(
T
parent
,
T
son
,
Class
<?>
refClassParent
,
Class
<?>
refClassSon
,
String
prefix
)
{
Map
<
String
,
String
>
publicFieldMap
=
new
HashMap
<>(
100
);
Object
obj
=
null
;
try
{
//比较父class对象与子class对象,找出字段相同的字段
for
(
Field
pField
:
refClassParent
.
getDeclaredFields
())
{
for
(
Field
sField
:
refClassSon
.
getDeclaredFields
())
{
if
(
sField
.
getName
().
equals
(
pField
.
getName
()))
{
publicFieldMap
.
put
(
pField
.
getName
(),
sField
.
getName
());
break
;
}
else
if
(
prefix
!=
null
&&
sField
.
getName
().
equals
(
prefix
+
pField
.
getName
()))
{
publicFieldMap
.
put
(
pField
.
getName
(),
sField
.
getName
());
break
;
}
}
}
obj
=
refClassSon
.
newInstance
();
//父对象为空,直接返回父对象给obj
if
(
parent
==
null
)
{
obj
=
son
;
}
else
//子对象为空,将父对象中与子对象中相同字段的值复制给obj
if
(
son
==
null
)
{
for
(
Map
.
Entry
<
String
,
String
>
entry
:
publicFieldMap
.
entrySet
())
{
if
(
SERIAL_VERSION_UID
.
equalsIgnoreCase
(
entry
.
getValue
()))
{
continue
;
}
Object
value
=
invokeGet
(
parent
,
entry
.
getValue
());
invokeSet
(
obj
,
entry
.
getValue
(),
value
);
}
}
else
{
//先将子对象拷贝给obj
for
(
Field
field
:
refClassSon
.
getDeclaredFields
())
{
if
(
SERIAL_VERSION_UID
.
equalsIgnoreCase
(
field
.
getName
()))
{
continue
;
}
Object
value
=
invokeGet
(
son
,
field
.
getName
());
invokeSet
(
obj
,
field
.
getName
(),
value
);
}
//将相同字段的值拷贝给obj
for
(
Map
.
Entry
<
String
,
String
>
entry
:
publicFieldMap
.
entrySet
())
{
String
pFieldName
=
entry
.
getKey
();
if
(
SERIAL_VERSION_UID
.
equalsIgnoreCase
(
entry
.
getValue
()))
{
continue
;
}
Object
value
=
invokeGet
(
son
,
entry
.
getValue
());
if
(
null
==
value
||
""
.
equals
(
value
))
{
value
=
invokeGet
(
parent
,
pFieldName
);
}
invokeSet
(
obj
,
entry
.
getValue
(),
value
);
}
}
}
catch
(
Exception
e
)
{
logger
.
error
(
"error:{}"
,
e
);
}
return
obj
;
}
/**
* Division obj t.
*
* @param <T> the type parameter
* @param parent 父对象
* @param son 子对象
* @param newSon 新的子对象
* @param refClass class对象
* @return T t
*/
public
static
<
T
>
T
divisionObj
(
T
parent
,
T
son
,
T
newSon
,
Class
<?>
refClass
)
{
return
divisionObj
(
parent
,
son
,
newSon
,
refClass
,
""
);
}
/**
* 比较产品域对象、项目域对象、页面对象,返回最后需要插入数据库中的对象
*
* @param <T> the type parameter
* @param parent 父对象
* @param son 子对象
* @param newSon 新的子对象
* @param refClass class对象
* @param excludeFields 不需要比较字段的列表
* @return T t
*/
public
static
<
T
>
T
divisionObj
(
T
parent
,
T
son
,
T
newSon
,
Class
<?>
refClass
,
String
...
excludeFields
)
{
for
(
Field
field
:
refClass
.
getDeclaredFields
())
{
if
(
SERIAL_VERSION_UID
.
equalsIgnoreCase
(
field
.
getName
()))
{
continue
;
}
//排除不需要比较的字段
if
(!
""
.
equals
(
excludeFields
)
&&
Arrays
.
asList
(
excludeFields
).
contains
(
field
.
getName
()))
{
continue
;
}
/*项目域不存在,则说明该元素只是项目化没有修改,表里面不存在*/
Object
valueSon
=
(
son
==
null
)
?
null
:
invokeGet
(
son
,
field
.
getName
());
/*子对象的对应的属性为空,则继承与产品域的属性,如果没有修改则继续继承*/
if
(
valueSon
==
null
)
{
Object
valueNewSon
=
invokeGet
(
newSon
,
field
.
getName
());
Object
valueParent
=
invokeGet
(
parent
,
field
.
getName
());
if
(
valueParent
!=
null
&&
valueParent
.
equals
(
valueNewSon
))
{
invokeSet
(
newSon
,
field
.
getName
(),
null
);
}
}
}
return
newSon
;
}
/**
* 应用场景,产品域字段列表跟项目域字段列表合并,以keyName作为主键,相同的keyName,则使用项目域的覆盖产品域的
*
* @param <T> the type parameter
* @param parentList 父域列表
* @param sonList 子域列表
* @param keyName 主键
* @return list list
*/
public
static
<
T
>
List
<
T
>
mergerList
(
List
<
T
>
parentList
,
List
<
T
>
sonList
,
String
keyName
)
{
List
<
T
>
resultList
=
new
ArrayList
<
T
>();
Map
<
Object
,
T
>
map
=
new
HashMap
<>(
100
);
if
(
parentList
==
null
)
{
resultList
.
addAll
(
sonList
);
return
resultList
;
}
if
(
sonList
==
null
)
{
resultList
.
addAll
(
parentList
);
return
resultList
;
}
resultList
.
addAll
(
parentList
);
for
(
T
obj
:
parentList
)
{
Object
keyFieldName
=
invokeGet
(
obj
,
keyName
);
map
.
put
(
keyFieldName
,
obj
);
}
int
size
=
sonList
.
size
();
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
Object
keyFieldName
=
invokeGet
(
sonList
.
get
(
i
),
keyName
);
if
(
map
.
containsKey
(
keyFieldName
))
{
resultList
.
remove
(
map
.
get
(
keyFieldName
));
resultList
.
add
(
i
,
sonList
.
get
(
i
));
}
else
{
resultList
.
add
(
sonList
.
get
(
i
));
}
}
return
resultList
;
}
/**
* 返回dto的所有属性字段名称 返回其中所有字段(除serialVersionUID之外) 可以用于设置值.
*
* @param <T> the type parameter
* @param refClass the ref class
* @return the string [ ]
*/
public
static
<
T
>
String
[]
getAllFieldName
(
Class
<?>
refClass
)
{
Field
[]
allField
=
refClass
.
getDeclaredFields
();
List
<
String
>
allFieldList
=
new
ArrayList
<
String
>();
for
(
int
i
=
0
,
j
=
0
;
i
<
allField
.
length
;
i
++)
{
String
filedName
=
allField
[
i
].
getName
();
if
(!
SERIAL_VERSION_UID
.
equalsIgnoreCase
(
filedName
))
{
allFieldList
.
add
(
filedName
);
}
}
return
allFieldList
.
toArray
(
new
String
[
allFieldList
.
size
()]);
}
/**
* 返回dto的所有Field字段 返回其中所有字段(除serialVersionUID之外) 可以用于设置值.
*
* @param <T> the type parameter
* @param refClass the ref class
* @return the field [ ]
*/
public
static
<
T
>
Field
[]
getAllField
(
Class
<?>
refClass
)
{
Field
[]
allField
=
refClass
.
getDeclaredFields
();
List
<
Field
>
allFieldList
=
new
ArrayList
<
Field
>();
for
(
int
i
=
0
,
j
=
0
;
i
<
allField
.
length
;
i
++)
{
if
(!
SERIAL_VERSION_UID
.
equalsIgnoreCase
(
allField
[
i
].
getName
()))
{
allFieldList
.
add
(
allField
[
i
]);
}
}
return
allFieldList
.
toArray
(
new
Field
[
allFieldList
.
size
()]);
}
/**
* 获取指定字段名称查找在class中的对应的Field对象(包括查找父类)
*
* @param clazz 指定的class
* @param fieldName 字段名称
* @return Field对象 class field
*/
public
static
Field
getClassField
(
Class
clazz
,
String
fieldName
)
{
if
(!
Object
.
class
.
getName
().
equals
(
clazz
.
getName
()))
{
Field
[]
declaredFields
=
clazz
.
getDeclaredFields
();
for
(
Field
field
:
declaredFields
)
{
if
(
field
.
getName
().
equals
(
fieldName
))
{
return
field
;
}
}
Class
superClass
=
clazz
.
getSuperclass
();
if
(
superClass
!=
null
)
{
// 简单的递归一下
return
getClassField
(
superClass
,
fieldName
);
}
}
return
null
;
}
}
demo/src/main/java/com/duanledexianxianxian/demo/config/MybatisPlusConfig.java
deleted
100644 → 0
View file @
0508e072
package
com.duanledexianxianxian.demo.config
;
import
com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.optimize.JsqlParserCountOptimize
;
import
org.mybatis.spring.annotation.MapperScan
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.transaction.annotation.EnableTransactionManagement
;
@EnableTransactionManagement
@Configuration
@MapperScan
(
basePackages
=
"com.duanledexianxianxian.demo.dao"
)
public
class
MybatisPlusConfig
{
@Bean
public
PaginationInterceptor
paginationInterceptor
()
{
PaginationInterceptor
paginationInterceptor
=
new
PaginationInterceptor
();
// 设置请求的页面大于最大页后操作, true调回到首页,false 继续请求 默认false
// paginationInterceptor.setOverflow(false);
// 设置最大单页限制数量,默认 500 条,-1 不受限制
// paginationInterceptor.setLimit(500);
// 开启 count 的 join 优化,只针对部分 left join
paginationInterceptor
.
setCountSqlParser
(
new
JsqlParserCountOptimize
(
true
));
return
paginationInterceptor
;
}
}
\ No newline at end of file
demo/src/main/java/com/duanledexianxianxian/demo/dao/MenuDao.java
deleted
100644 → 0
View file @
0508e072
package
com.duanledexianxianxian.demo.dao
;
import
com.duanledexianxianxian.demo.domain.entity.Menu
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
/**
* <p>
* 菜单表 Mapper 接口
* </p>
*
* @author duanledexianxianxian
* @since 2020-03-19
*/
public
interface
MenuDao
extends
BaseMapper
<
Menu
>
{
}
demo/src/main/java/com/duanledexianxianxian/demo/dao/UserDao.java
deleted
100644 → 0
View file @
0508e072
package
com.duanledexianxianxian.demo.dao
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.duanledexianxianxian.demo.domain.entity.User
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.duanledexianxianxian.demo.domain.model.query.UserQuery
;
import
org.apache.ibatis.annotations.Param
;
import
java.util.List
;
/**
* <p>
* 用户表 Mapper 接口
* </p>
*
* @author duanledexianxianxian
* @since 2020 -03-19
*/
public
interface
UserDao
extends
BaseMapper
<
User
>
{
/**
* Gets list.
*
* @param page the page
* @param query the query
* @return the list
*/
List
<
User
>
getList
(
IPage
<
User
>
page
,
@Param
(
"query"
)
UserQuery
query
);
}
demo/src/main/java/com/duanledexianxianxian/demo/domain/dto/MenuDTO.java
deleted
100644 → 0
View file @
0508e072
package
com.duanledexianxianxian.demo.domain.dto
;
import
lombok.Data
;
import
java.io.Serializable
;
import
java.time.LocalDateTime
;
/**
* 菜单传输对象
*
* @author duanledexianxianxian
* @since 2020 -03-19
*/
@Data
public
class
MenuDTO
implements
Serializable
{
/**
* The constant serialVersionUID.
*/
private
static
final
long
serialVersionUID
=
1L
;
/**
* 菜单编号
*/
private
Long
menuId
;
/**
* 菜单url
*/
private
String
menuUrl
;
/**
* 菜单名称
*/
private
String
menuName
;
/**
* 菜单编码
*/
private
String
menuCode
;
/**
* 创建时间
*/
private
LocalDateTime
createTime
;
}
demo/src/main/java/com/duanledexianxianxian/demo/domain/dto/UserDTO.java
deleted
100644 → 0
View file @
0508e072
package
com.duanledexianxianxian.demo.domain.dto
;
import
com.duanledexianxianxian.demo.domain.entity.Menu
;
import
lombok.Data
;
import
java.io.Serializable
;
import
java.time.LocalDate
;
import
java.util.List
;
/**
* 用户传输对象
*
* @author duanledexianxianxian
* @since 2020 -03-19
*/
@Data
public
class
UserDTO
implements
Serializable
{
/**
* The constant serialVersionUID.
*/
private
static
final
long
serialVersionUID
=
1L
;
/**
* 用户编号
*/
private
Long
userId
;
/**
* 用户名称
*/
private
String
userName
;
/**
* 用户昵称
*/
private
String
nickName
;
/**
* 年龄
*/
private
Integer
age
;
/**
* 生日
*/
private
LocalDate
birthday
;
/**
* 菜单列表
*/
List
<
MenuDTO
>
menuList
;
}
demo/src/main/java/com/duanledexianxianxian/demo/domain/entity/Menu.java
deleted
100644 → 0
View file @
0508e072
package
com.duanledexianxianxian.demo.domain.entity
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
java.time.LocalDateTime
;
import
java.io.Serializable
;
import
lombok.Data
;
import
lombok.EqualsAndHashCode
;
import
lombok.experimental.Accessors
;
/**
* <p>
* 菜单表
* </p>
*
* @author duanledexianxianxian
* @since 2020-03-19
*/
@Data
@EqualsAndHashCode
(
callSuper
=
false
)
@Accessors
(
chain
=
true
)
@TableName
(
"test_menu"
)
public
class
Menu
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
/**
* 用户编号
*/
private
Long
userId
;
/**
* 菜单编号
*/
@TableId
private
Long
menuId
;
/**
* 菜单url
*/
private
String
menuUrl
;
/**
* 菜单名称
*/
private
String
menuName
;
/**
* 菜单编码
*/
private
String
menuCode
;
/**
* 创建时间
*/
private
LocalDateTime
createTime
;
}
demo/src/main/java/com/duanledexianxianxian/demo/domain/entity/User.java
deleted
100644 → 0
View file @
0508e072
package
com.duanledexianxianxian.demo.domain.entity
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
java.time.LocalDate
;
import
java.io.Serializable
;
import
lombok.Data
;
import
lombok.EqualsAndHashCode
;
import
lombok.experimental.Accessors
;
/**
* <p>
* 用户表
* </p>
*
* @author duanledexianxianxian
* @since 2020-03-19
*/
@Data
@EqualsAndHashCode
(
callSuper
=
false
)
@Accessors
(
chain
=
true
)
@TableName
(
"test_user"
)
public
class
User
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
/**
* 用户编号
*/
@TableId
private
Long
userId
;
/**
* 用户名称
*/
private
String
userName
;
/**
* 用户昵称
*/
private
String
nickName
;
/**
* 年龄
*/
private
Integer
age
;
/**
* 生日
*/
private
LocalDate
birthday
;
}
demo/src/main/java/com/duanledexianxianxian/demo/domain/model/query/MenuForm.java
deleted
100644 → 0
View file @
0508e072
package
com.duanledexianxianxian.demo.domain.model.query
;
import
lombok.Data
;
import
java.io.Serializable
;
import
java.time.LocalDateTime
;
/**
* 菜单表单对象
*
* @author duanledexianxianxian
* @since 2020-03-19
*/
@Data
public
class
MenuForm
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
/**
* 用户编号
*/
private
Long
userId
;
/**
* 菜单编号
*/
private
Long
menuId
;
/**
* 菜单url
*/
private
String
menuUrl
;
/**
* 菜单名称
*/
private
String
menuName
;
/**
* 菜单编码
*/
private
String
menuCode
;
/**
* 创建时间
*/
private
LocalDateTime
createTime
;
}
demo/src/main/java/com/duanledexianxianxian/demo/domain/model/query/MenuQuery.java
deleted
100644 → 0
View file @
0508e072
package
com.duanledexianxianxian.demo.domain.model.query
;
import
lombok.Data
;
import
java.io.Serializable
;
/**
* 菜单查询对象
*
* @author duanledexianxianxian
* @since 2020 -03-19
*/
@Data
public
class
MenuQuery
implements
Serializable
{
/**
* 菜单名称
*/
private
String
menuName
;
}
demo/src/main/java/com/duanledexianxianxian/demo/domain/model/query/UserForm.java
deleted
100644 → 0
View file @
0508e072
package
com.duanledexianxianxian.demo.domain.model.query
;
import
lombok.Data
;
import
java.io.Serializable
;
import
java.time.LocalDate
;
/**
* 用户表单对象
*
* @author duanledexianxianxian
* @since 2020 -03-19
*/
@Data
public
class
UserForm
implements
Serializable
{
/**
* The constant serialVersionUID.
*/
private
static
final
long
serialVersionUID
=
1L
;
/**
* 用户编号
*/
private
Long
userId
;
/**
* 用户名称
*/
private
String
userName
;
/**
* 用户昵称
*/
private
String
nickName
;
/**
* 年龄
*/
private
Integer
age
;
/**
* 生日
*/
private
LocalDate
birthday
;
}
demo/src/main/java/com/duanledexianxianxian/demo/domain/model/query/UserQuery.java
deleted
100644 → 0
View file @
0508e072
package
com.duanledexianxianxian.demo.domain.model.query
;
import
lombok.Data
;
import
java.io.Serializable
;
import
java.time.LocalDate
;
/**
* 用户查询对象
*
* @author duanledexianxianxian
* @since 2020 -03-19
*/
@Data
public
class
UserQuery
implements
Serializable
{
/**
* The constant serialVersionUID.
*/
private
static
final
long
serialVersionUID
=
1L
;
/**
* The Page num.
*/
Long
pageNum
=
1L
;
/**
* The Page size.
*/
Long
pageSize
=
10L
;
/**
* 用户名称
*/
private
String
userName
;
/**
* 用户昵称
*/
private
String
nickName
;
}
demo/src/main/java/com/duanledexianxianxian/demo/domain/model/vo/MenuVO.java
deleted
100644 → 0
View file @
0508e072
package
com.duanledexianxianxian.demo.domain.model.vo
;
import
lombok.Data
;
import
java.io.Serializable
;
import
java.time.LocalDateTime
;
/**
* 菜单vo对象
*
* @author duanledexianxianxian
* @since 2020-03-19
*/
@Data
public
class
MenuVO
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
/**
* 菜单编号
*/
private
Long
menuId
;
/**
* 菜单url
*/
private
String
menuUrl
;
/**
* 菜单名称
*/
private
String
menuName
;
/**
* 菜单编码
*/
private
String
menuCode
;
/**
* 创建时间
*/
private
LocalDateTime
createTime
;
}
demo/src/main/java/com/duanledexianxianxian/demo/domain/model/vo/UserDetailVO.java
deleted
100644 → 0
View file @
0508e072
package
com.duanledexianxianxian.demo.domain.model.vo
;
import
lombok.Data
;
import
java.io.Serializable
;
import
java.time.LocalDate
;
import
java.util.List
;
/**
* 用户vo对象
*
* @author duanledexianxianxian
* @since 2020 -03-19
*/
@Data
public
class
UserDetailVO
implements
Serializable
{
/**
* The constant serialVersionUID.
*/
private
static
final
long
serialVersionUID
=
1L
;
/**
* 用户编号
*/
private
Long
userId
;
/**
* 用户名称
*/
private
String
userName
;
/**
* 用户昵称
*/
private
String
nickName
;
/**
* 年龄
*/
private
Integer
age
;
/**
* 生日
*/
private
LocalDate
birthday
;
/**
* The Menu list.
*/
private
List
<
MenuVO
>
menuList
;
}
demo/src/main/java/com/duanledexianxianxian/demo/domain/model/vo/UserVO.java
deleted
100644 → 0
View file @
0508e072
package
com.duanledexianxianxian.demo.domain.model.vo
;
import
lombok.Data
;
import
java.io.Serializable
;
import
java.time.LocalDate
;
/**
* 用户vo对象
*
* @author duanledexianxianxian
* @since 2020 -03-19
*/
@Data
public
class
UserVO
implements
Serializable
{
/**
* The constant serialVersionUID.
*/
private
static
final
long
serialVersionUID
=
1L
;
/**
* 用户编号
*/
private
Long
userId
;
/**
* 用户名称
*/
private
String
userName
;
/**
* 用户昵称
*/
private
String
nickName
;
/**
* 年龄
*/
private
Integer
age
;
/**
* 生日
*/
private
LocalDate
birthday
;
}
demo/src/main/java/com/duanledexianxianxian/demo/service/IMenuService.java
deleted
100644 → 0
View file @
0508e072
package
com.duanledexianxianxian.demo.service
;
import
com.duanledexianxianxian.demo.domain.dto.MenuDTO
;
import
com.duanledexianxianxian.demo.domain.entity.Menu
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.duanledexianxianxian.demo.domain.model.query.MenuForm
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.List
;
/**
* <p>
* 菜单表 服务类
* </p>
*
* @author duanledexianxianxian
* @since 2020 -03-19
*/
public
interface
IMenuService
extends
IService
<
Menu
>
{
/**
* Add menu long.
*
* @param form the form
* @return the long
*/
Long
addMenu
(
MenuForm
form
);
/**
* Edit menu boolean.
*
* @param form the form
* @return the boolean
*/
Boolean
editMenu
(
MenuForm
form
);
/**
* Delete menu boolean.
*
* @param menuId the menu id
* @return the boolean
*/
Boolean
deleteMenu
(
Long
menuId
);
/**
* Gets user menu list.
*
* @param userId the user id
* @return the user menu list
*/
List
<
MenuDTO
>
getUserMenuList
(
Long
userId
);
}
demo/src/main/java/com/duanledexianxianxian/demo/service/IUserService.java
deleted
100644 → 0
View file @
0508e072
package
com.duanledexianxianxian.demo.service
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.duanledexianxianxian.demo.dao.UserDao
;
import
com.duanledexianxianxian.demo.domain.dto.MenuDTO
;
import
com.duanledexianxianxian.demo.domain.dto.UserDTO
;
import
com.duanledexianxianxian.demo.domain.entity.User
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.duanledexianxianxian.demo.domain.model.query.MenuForm
;
import
com.duanledexianxianxian.demo.domain.model.query.UserForm
;
import
com.duanledexianxianxian.demo.domain.model.query.UserQuery
;
import
java.util.List
;
/**
* 用户接口
*
* @author duanledexianxianxian
* @since 2020 -03-19
*/
public
interface
IUserService
extends
IService
<
User
>
{
/**
* Add menu long.
*
* @param query the query
* @return the long
*/
IPage
getUserListPage
(
UserQuery
query
);
/**
* Gets user menu list.
*
* @param userId the user id
* @return the user menu list
*/
UserDTO
getUserDetail
(
Long
userId
);
/**
* Add menu long.
*
* @param form the form
* @return the long
*/
Long
addUser
(
UserForm
form
);
/**
* Edit menu boolean.
*
* @param form the form
* @return the boolean
*/
Boolean
editUser
(
UserForm
form
);
/**
* Delete menu boolean.
*
* @param userId the user id
* @return the boolean
*/
Boolean
deleteUser
(
Long
userId
);
}
demo/src/main/java/com/duanledexianxianxian/demo/service/impl/MenuServiceImpl.java
deleted
100644 → 0
View file @
0508e072
package
com.duanledexianxianxian.demo.service.impl
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.extension.toolkit.SqlHelper
;
import
com.duanledexianxianxian.demo.common.util.BeanUtils
;
import
com.duanledexianxianxian.demo.domain.dto.MenuDTO
;
import
com.duanledexianxianxian.demo.domain.entity.Menu
;
import
com.duanledexianxianxian.demo.dao.MenuDao
;
import
com.duanledexianxianxian.demo.domain.model.query.MenuForm
;
import
com.duanledexianxianxian.demo.service.IMenuService
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.List
;
/**
* 菜单服务实现类
*
* @author duanledexianxianxian
* @since 2020 -03-19
*/
@Service
public
class
MenuServiceImpl
extends
ServiceImpl
<
MenuDao
,
Menu
>
implements
IMenuService
{
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Override
public
Long
addMenu
(
MenuForm
form
)
{
// 做插入前检查
Menu
menu
=
BeanUtils
.
copyObject
(
form
,
Menu
.
class
);
this
.
baseMapper
.
insert
(
menu
);
return
menu
.
getMenuId
();
}
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Override
public
Boolean
editMenu
(
MenuForm
form
)
{
// 做编辑前检查
Menu
menu
=
BeanUtils
.
copyObject
(
form
,
Menu
.
class
);
int
cnt
=
this
.
baseMapper
.
updateById
(
menu
);
return
SqlHelper
.
retBool
(
cnt
);
}
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Override
public
Boolean
deleteMenu
(
Long
menuId
)
{
// 做删除前检查
return
SqlHelper
.
retBool
(
this
.
baseMapper
.
deleteById
(
menuId
));
}
@Override
public
List
<
MenuDTO
>
getUserMenuList
(
Long
userId
)
{
return
BeanUtils
.
copyList
(
this
.
baseMapper
.
selectList
(
new
LambdaQueryWrapper
<
Menu
>()
.
eq
(
Menu:
:
getUserId
,
userId
)),
MenuDTO
.
class
);
}
}
demo/src/main/java/com/duanledexianxianxian/demo/service/impl/UserServiceImpl.java
deleted
100644 → 0
View file @
0508e072
package
com.duanledexianxianxian.demo.service.impl
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.baomidou.mybatisplus.extension.toolkit.SqlHelper
;
import
com.duanledexianxianxian.demo.common.util.BeanUtils
;
import
com.duanledexianxianxian.demo.dao.MenuDao
;
import
com.duanledexianxianxian.demo.domain.dto.MenuDTO
;
import
com.duanledexianxianxian.demo.domain.dto.UserDTO
;
import
com.duanledexianxianxian.demo.domain.entity.Menu
;
import
com.duanledexianxianxian.demo.domain.entity.User
;
import
com.duanledexianxianxian.demo.dao.UserDao
;
import
com.duanledexianxianxian.demo.domain.model.query.UserForm
;
import
com.duanledexianxianxian.demo.domain.model.query.UserQuery
;
import
com.duanledexianxianxian.demo.service.IMenuService
;
import
com.duanledexianxianxian.demo.service.IUserService
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.CollectionUtils
;
import
java.util.List
;
/**
* 用户服务接口实现类
*
* @author duanledexianxianxian
* @since 2020 -03-19
*/
@Service
public
class
UserServiceImpl
extends
ServiceImpl
<
UserDao
,
User
>
implements
IUserService
{
@Autowired
IMenuService
menuService
;
@Override
public
IPage
getUserListPage
(
UserQuery
query
)
{
IPage
page
=
new
Page
(
query
.
getPageNum
(),
query
.
getPageSize
());
List
<
User
>
userList
=
this
.
baseMapper
.
getList
(
page
,
query
);
page
.
setRecords
(
BeanUtils
.
copyList
(
userList
,
UserDTO
.
class
));
return
page
;
}
@Override
public
UserDTO
getUserDetail
(
Long
userId
)
{
User
user
=
this
.
baseMapper
.
selectById
(
userId
);
// 需要检查用户是否存在
UserDTO
userDTO
=
BeanUtils
.
copyObject
(
user
,
UserDTO
.
class
);
List
<
MenuDTO
>
menuDTOList
=
menuService
.
getUserMenuList
(
userId
);
userDTO
.
setMenuList
(
menuDTOList
);
return
userDTO
;
}
@Override
public
Long
addUser
(
UserForm
form
)
{
// 做插入前检查
User
user
=
BeanUtils
.
copyObject
(
form
,
User
.
class
);
this
.
baseMapper
.
insert
(
user
);
return
user
.
getUserId
();
}
@Override
public
Boolean
editUser
(
UserForm
form
)
{
// 做编辑前检查
User
user
=
BeanUtils
.
copyObject
(
form
,
User
.
class
);
return
SqlHelper
.
retBool
(
this
.
baseMapper
.
updateById
(
user
));
}
@Override
public
Boolean
deleteUser
(
Long
userId
)
{
// 做删除前检查
return
SqlHelper
.
retBool
(
this
.
baseMapper
.
deleteById
(
userId
));
}
}
demo/src/main/resources/mapper/test/MenuDao.xml
deleted
100644 → 0
View file @
0508e072
<?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=
"com.duanledexianxianxian.demo.dao.MenuDao"
>
</mapper>
demo/src/main/resources/mapper/test/UserDao.xml
deleted
100644 → 0
View file @
0508e072
<?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=
"com.duanledexianxianxian.demo.dao.UserDao"
>
<!-- 通用查询映射结果 -->
<resultMap
id=
"BaseResultMap"
type=
"com.duanledexianxianxian.demo.domain.entity.User"
>
<id
column=
"user_id"
property=
"userId"
/>
<result
column=
"user_name"
property=
"userName"
/>
<result
column=
"nick_name"
property=
"nickName"
/>
<result
column=
"age"
property=
"age"
/>
<result
column=
"birthday"
property=
"birthday"
/>
</resultMap>
<!-- 通用查询结果列 -->
<sql
id=
"Base_Column_List"
>
user_id, user_name, nick_name, age, birthday
</sql>
<select
id=
"getList"
resultMap=
"BaseResultMap"
>
select
<include
refid=
"Base_Column_List"
/>
from test_user
<where>
<if
test=
"query.userName!=null and query.userName!=''"
>
and user_name like concat('%',#{query.userName})
</if>
<if
test=
"query.nickName!=null and query.nickName!=''"
>
and nick_name like concat('%',#{query.nickName})
</if>
</where>
</select>
</mapper>
pom.xml
View file @
da556397
...
@@ -10,6 +10,7 @@
...
@@ -10,6 +10,7 @@
<version>
1.0-SNAPSHOT
</version>
<version>
1.0-SNAPSHOT
</version>
<modules>
<modules>
<module>
demo
</module>
<module>
demo
</module>
<module>
demo1
</module>
</modules>
</modules>
<parent>
<parent>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment