Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
bigsys
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
bigsys
Commits
2856ce65
Commit
2856ce65
authored
Sep 08, 2017
by
fangzhipeng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
构建通用dao层
parent
3b329be9
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
203 additions
and
27 deletions
+203
-27
bigsys-auth/bigsys-auth-project/src/main/java/com/bigsys/auth/project/config/ShiroConfig.java
...main/java/com/bigsys/auth/project/config/ShiroConfig.java
+14
-13
bigsys-auth/bigsys-auth-project/src/main/java/com/bigsys/auth/project/controller/UserController.java
...va/com/bigsys/auth/project/controller/UserController.java
+7
-2
bigsys-auth/bigsys-auth-project/src/main/java/com/bigsys/auth/project/service/UserService.java
...ain/java/com/bigsys/auth/project/service/UserService.java
+3
-2
bigsys-auth/bigsys-auth-project/src/main/java/com/bigsys/auth/project/service/impl/UserServiceImpl.java
...com/bigsys/auth/project/service/impl/UserServiceImpl.java
+1
-3
bigsys-auth/bigsys-auth-project/src/main/java/com/bigsys/auth/project/util/response/BSResponse.java
...ava/com/bigsys/auth/project/util/response/BSResponse.java
+1
-1
bigsys-auth/bigsys-auth-project/src/main/java/com/bigsys/auth/project/util/service/BaseService.java
...ava/com/bigsys/auth/project/util/service/BaseService.java
+34
-0
bigsys-auth/bigsys-auth-project/src/main/java/com/bigsys/auth/project/util/service/BaseServiceImpl.java
...com/bigsys/auth/project/util/service/BaseServiceImpl.java
+140
-0
bigsys-auth/bigsys-auth-project/src/test/java/com/bigsys/auth/project/BigsysAuthSpringbootApplicationTests.java
...ys/auth/project/BigsysAuthSpringbootApplicationTests.java
+2
-5
bigsys-auth/bigsys-auth-project/src/test/resources/generatorConfig.xml
...igsys-auth-project/src/test/resources/generatorConfig.xml
+1
-1
No files found.
bigsys-auth/bigsys-auth-project/src/main/java/com/bigsys/auth/project/ShiroConfig.java
→
bigsys-auth/bigsys-auth-project/src/main/java/com/bigsys/auth/project/
config/
ShiroConfig.java
View file @
2856ce65
package
com
.
bigsys
.
auth
.
project
;
package
com
.
bigsys
.
auth
.
project
.
config
;
import
org.apache.shiro.mgt.SecurityManager
;
import
org.apache.shiro.spring.web.ShiroFilterFactoryBean
;
...
...
@@ -39,18 +39,19 @@ public class ShiroConfig {
// 拦截器.
Map
<
String
,
String
>
filterChainDefinitionMap
=
new
LinkedHashMap
<
String
,
String
>();
// 配置不会被拦截的链接 顺序判断
filterChainDefinitionMap
.
put
(
"/static/**"
,
"anon"
);
filterChainDefinitionMap
.
put
(
"/ajaxLogin"
,
"anon"
);
// 配置退出过滤器,其中的具体的退出代码Shiro已经替我们实现了
filterChainDefinitionMap
.
put
(
"/logout"
,
"logout"
);
filterChainDefinitionMap
.
put
(
"/add"
,
"perms[权限添加]"
);
// <!-- 过滤链定义,从上向下顺序执行,一般将 /**放在最为下边 -->:这是一个坑呢,一不小心代码就不好使了;
// <!-- authc:所有url都必须认证通过才可以访问; anon:所有url都都可以匿名访问-->
filterChainDefinitionMap
.
put
(
"/**"
,
"authc"
);
filterChainDefinitionMap
.
put
(
"/**"
,
"anon"
);
// // 配置不会被拦截的链接 顺序判断
// filterChainDefinitionMap.put("/static/**", "anon");
// filterChainDefinitionMap.put("/ajaxLogin", "anon");
//
// // 配置退出过滤器,其中的具体的退出代码Shiro已经替我们实现了
// filterChainDefinitionMap.put("/logout", "logout");
//
// filterChainDefinitionMap.put("/add", "perms[权限添加]");
//
// // <!-- 过滤链定义,从上向下顺序执行,一般将 /**放在最为下边 -->:这是一个坑呢,一不小心代码就不好使了;
// // <!-- authc:所有url都必须认证通过才可以访问; anon:所有url都都可以匿名访问-->
// filterChainDefinitionMap.put("/**", "authc");
shiroFilterFactoryBean
.
setFilterChainDefinitionMap
(
filterChainDefinitionMap
);
System
.
out
.
println
(
"Shiro拦截器工厂类注入成功"
);
...
...
bigsys-auth/bigsys-auth-project/src/main/java/com/bigsys/auth/project/controller/UserController.java
View file @
2856ce65
...
...
@@ -2,10 +2,9 @@ package com.bigsys.auth.project.controller;
import
com.bigsys.auth.project.db.model.User
;
import
com.bigsys.auth.project.service.UserService
;
import
com.bigsys.auth.project.util.BSResponse
;
import
com.bigsys.auth.project.util.
response.
BSResponse
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.thymeleaf.util.StringUtils
;
import
javax.annotation.Resource
;
...
...
@@ -22,4 +21,10 @@ public class UserController {
return
BSResponse
.
ok
();
}
@RequestMapping
(
value
=
"/getById"
)
public
BSResponse
getById
(
String
id
)
{
User
user
=
userService
.
selectByPrimaryKey
(
id
);
return
BSResponse
.
ok
(
user
);
}
}
bigsys-auth/bigsys-auth-project/src/main/java/com/bigsys/auth/project/service/UserService.java
View file @
2856ce65
package
com
.
bigsys
.
auth
.
project
.
service
;
import
com.bigsys.auth.project.db.model.User
;
import
com.github.pagehelper.Page
;
import
com.bigsys.auth.project.db.model.UserExample
;
import
com.bigsys.auth.project.util.service.BaseService
;
import
com.github.pagehelper.PageInfo
;
public
interface
UserService
{
public
interface
UserService
extends
BaseService
<
String
,
User
,
UserExample
,
UserExample
.
Criteria
>
{
void
addOrUpdate
(
User
model
);
...
...
bigsys-auth/bigsys-auth-project/src/main/java/com/bigsys/auth/project/service/impl/UserServiceImpl.java
View file @
2856ce65
...
...
@@ -4,10 +4,8 @@ import com.bigsys.auth.project.db.dao.UserMapper;
import
com.bigsys.auth.project.db.model.User
;
import
com.bigsys.auth.project.db.model.UserExample
;
import
com.bigsys.auth.project.service.UserService
;
import
com.bigsys.auth.project.util.CreateExample
;
import
com.bigsys.auth.project.util.UUIDGenarator
;
import
com.bigsys.auth.project.util.dao.BaseServiceImpl
;
import
com.github.pagehelper.PageHelper
;
import
com.bigsys.auth.project.util.service.BaseServiceImpl
;
import
com.github.pagehelper.PageInfo
;
import
org.springframework.stereotype.Service
;
import
org.thymeleaf.util.StringUtils
;
...
...
bigsys-auth/bigsys-auth-project/src/main/java/com/bigsys/auth/project/util/BSResponse.java
→
bigsys-auth/bigsys-auth-project/src/main/java/com/bigsys/auth/project/util/
response/
BSResponse.java
View file @
2856ce65
package
com
.
bigsys
.
auth
.
project
.
util
;
package
com
.
bigsys
.
auth
.
project
.
util
.
response
;
import
java.util.HashMap
;
...
...
bigsys-auth/bigsys-auth-project/src/main/java/com/bigsys/auth/project/util/service/BaseService.java
0 → 100644
View file @
2856ce65
package
com
.
bigsys
.
auth
.
project
.
util
.
service
;
import
com.bigsys.auth.project.util.CreateExample
;
import
com.github.pagehelper.PageInfo
;
import
java.util.List
;
public
interface
BaseService
<
key
,
model
,
example
,
criteria
>
{
long
countByExample
(
CreateExample
<
example
,
criteria
>
createExample
);
int
deleteByExample
(
CreateExample
<
example
,
criteria
>
createExample
);
int
deleteByPrimaryKey
(
key
id
);
int
insert
(
model
record
);
int
insertSelective
(
model
record
);
List
<
model
>
selectByExample
(
CreateExample
<
example
,
criteria
>
createExample
);
model
selectByPrimaryKey
(
key
id
);
int
updateByExampleSelective
(
model
record
,
CreateExample
<
example
,
criteria
>
createExample
);
int
updateByExample
(
model
record
,
CreateExample
<
example
,
criteria
>
createExample
);
int
updateByPrimaryKeySelective
(
model
record
);
int
updateByPrimaryKey
(
model
record
);
PageInfo
<
model
>
selectByExampleAndPage
(
PageInfo
<
model
>
page
,
CreateExample
<
example
,
criteria
>
createExample
);
}
bigsys-auth/bigsys-auth-project/src/main/java/com/bigsys/auth/project/util/
dao
/BaseServiceImpl.java
→
bigsys-auth/bigsys-auth-project/src/main/java/com/bigsys/auth/project/util/
service
/BaseServiceImpl.java
View file @
2856ce65
package
com
.
bigsys
.
auth
.
project
.
util
.
dao
;
package
com
.
bigsys
.
auth
.
project
.
util
.
service
;
import
com.bigsys.auth.project.util.CreateExample
;
import
com.github.pagehelper.PageHelper
;
import
com.github.pagehelper.PageInfo
;
import
com.sun.org.apache.xml.internal.security.Init
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Method
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
public
abstract
class
BaseServiceImpl
<
key
,
model
,
example
,
criteria
>
{
public
abstract
class
BaseServiceImpl
<
key
,
model
,
example
,
criteria
>
implements
BaseService
<
key
,
model
,
example
,
criteria
>
{
private
Map
<
String
,
Method
>
methodMap
=
new
HashMap
<>();
private
final
String
MYBATIS_COUNTBYEXAMPLE
=
"countByExample"
;
private
final
String
MYBATIS_DELETEBYEXAMPLE
=
"deleteByExample"
;
private
final
String
MYBATIS_DELETEBYPRIMARYKEY
=
"deleteByPrimaryKey"
;
private
final
String
MYBATIS_INSERT
=
"insert"
;
private
final
String
MYBATIS_INSERTSELECTIVE
=
"insertSelective"
;
private
final
String
MYBATIS_SELECTBYEXAMPLE
=
"selectByExample"
;
private
final
String
MYBATIS_SELECTBYPRIMARYKEY
=
"selectByPrimaryKey"
;
private
final
String
MYBATIS_UPDATEBYEXAMPLESELECTIVE
=
"updateByExampleSelective"
;
private
final
String
MYBATIS_UPDATEBYEXAMPLE
=
"updateByExample"
;
private
final
String
MYBATIS_UPDATEBYPRIMARYKEYSELECTIVE
=
"updateByPrimaryKeySelective"
;
private
final
String
MYBATIS_UPDATEBYPRIMARYKEY
=
"updateByPrimaryKey"
;
private
final
String
MYBATIS_CREATECRITERIA
=
"createCriteria"
;
public
abstract
Object
getDao
();
public
abstract
Class
getExample
();
public
void
init
()
{
@Override
public
long
countByExample
(
CreateExample
<
example
,
criteria
>
createExample
)
{
return
(
long
)
invokeMethod
(
getDao
(),
MYBATIS_COUNTBYEXAMPLE
,
produceExample
(
createExample
));
}
@Override
public
int
deleteByExample
(
CreateExample
<
example
,
criteria
>
createExample
)
{
return
(
int
)
invokeMethod
(
getDao
(),
MYBATIS_DELETEBYEXAMPLE
,
produceExample
(
createExample
));
}
@Override
public
int
deleteByPrimaryKey
(
key
id
)
{
return
(
int
)
invokeMethod
(
getDao
(),
MYBATIS_DELETEBYPRIMARYKEY
,
id
);
}
@Override
public
int
insert
(
model
record
)
{
return
(
int
)
invokeMethod
(
getDao
(),
MYBATIS_INSERT
,
record
);
}
@Override
public
int
insertSelective
(
model
record
)
{
return
(
int
)
invokeMethod
(
getDao
(),
MYBATIS_INSERTSELECTIVE
,
record
);
}
@Override
public
List
<
model
>
selectByExample
(
CreateExample
<
example
,
criteria
>
createExample
)
{
return
(
List
<
model
>)
invokeMethod
(
getDao
(),
MYBATIS_SELECTBYEXAMPLE
,
produceExample
(
createExample
));
}
@Override
public
model
selectByPrimaryKey
(
key
id
)
{
return
(
model
)
invokeMethod
(
getDao
(),
MYBATIS_SELECTBYPRIMARYKEY
,
id
);
}
@Override
public
int
updateByExampleSelective
(
model
record
,
CreateExample
<
example
,
criteria
>
createExample
)
{
return
(
int
)
invokeMethod
(
getDao
(),
MYBATIS_UPDATEBYEXAMPLESELECTIVE
,
record
,
produceExample
(
createExample
));
}
@Override
public
int
updateByExample
(
model
record
,
CreateExample
<
example
,
criteria
>
createExample
)
{
return
(
int
)
invokeMethod
(
getDao
(),
MYBATIS_UPDATEBYEXAMPLE
,
record
,
produceExample
(
createExample
));
}
@Override
public
int
updateByPrimaryKeySelective
(
model
record
)
{
return
(
int
)
invokeMethod
(
getDao
(),
MYBATIS_UPDATEBYPRIMARYKEYSELECTIVE
,
record
);
}
@Override
public
int
updateByPrimaryKey
(
model
record
)
{
return
(
int
)
invokeMethod
(
getDao
(),
MYBATIS_UPDATEBYPRIMARYKEY
,
record
);
}
@Override
public
PageInfo
<
model
>
selectByExampleAndPage
(
PageInfo
<
model
>
page
,
CreateExample
<
example
,
criteria
>
createExample
)
{
page
=
PageHelper
.
startPage
(
page
).
doSelectPageInfo
(()
->
{
invokeMethod
(
getDao
(),
MYBATIS_SELECTBYEXAMPLE
,
produceExample
(
createExample
));
});
return
page
;
}
private
void
init
()
{
Object
dao
=
getDao
();
Class
clazz
=
dao
.
getClass
();
Method
[]
methods
=
clazz
.
getMethods
();
...
...
@@ -30,16 +102,14 @@ public abstract class BaseServiceImpl<key, model, example, criteria> {
}
}
public
PageInfo
<
model
>
selectByExampleAndPage
(
PageInfo
<
model
>
page
,
CreateExample
<
example
,
criteria
>
createExample
)
{
private
example
produceExample
(
CreateExample
<
example
,
criteria
>
createExample
)
{
example
example
=
null
;
try
{
example
example
=
(
example
)
getExample
().
newInstance
();
example
=
(
example
)
getExample
().
newInstance
();
Class
clazz
=
example
.
getClass
();
criteria
criteria
=
(
criteria
)
clazz
.
getMethod
(
MYBATIS_CREATECRITERIA
).
invoke
(
example
);
createExample
.
createExample
(
example
,
criteria
);
page
=
PageHelper
.
startPage
(
page
).
doSelectPageInfo
(()
->
{
invokeMethod
(
getDao
(),
MYBATIS_SELECTBYEXAMPLE
,
example
);
});
return
page
;
return
example
;
}
catch
(
InstantiationException
e
)
{
e
.
printStackTrace
();
}
catch
(
IllegalAccessException
e
)
{
...
...
@@ -52,7 +122,7 @@ public abstract class BaseServiceImpl<key, model, example, criteria> {
return
null
;
}
Object
invokeMethod
(
Object
obj
,
String
method
,
Object
...
args
)
{
private
Object
invokeMethod
(
Object
obj
,
String
method
,
Object
...
args
)
{
if
(
methodMap
.
size
()
==
0
)
{
init
();
}
...
...
bigsys-auth/bigsys-auth-project/src/test/java/com/bigsys/auth/project/BigsysAuthSpringbootApplicationTests.java
View file @
2856ce65
...
...
@@ -20,10 +20,7 @@ public class BigsysAuthSpringbootApplicationTests {
@Test
public
void
contextLoads
()
{
PageInfo
<
User
>
page
=
new
PageInfo
<
User
>();
page
.
setPageNum
(
11
);
page
.
setPageSize
(
10
);
userService
.
page
(
null
,
page
);
}
System
.
out
.
println
(
userService
.
countByExample
((
example
,
criteria
)
->
{}));
}
}
bigsys-auth/bigsys-auth-project/src/test/resources/generatorConfig.xml
View file @
2856ce65
...
...
@@ -4,7 +4,7 @@
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<!-- 配置Run As Maven build : Goals 参数 : mybatis-generator:generate -Dmybatis.generator.overwrite=true -->
<!-- 配置 tableName,使用 Run As Maven build 生成
dao
model 层 -->
<!-- 配置 tableName,使用 Run As Maven build 生成
service
model 层 -->
<generatorConfiguration>
<!-- 配置文件路径 -->
<properties
url=
"${mybatis.generator.generatorConfig.properties}"
/>
...
...
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