Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
fenghuo12
zheng
提交
ba634133
Z
zheng
项目概览
fenghuo12
/
zheng
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Z
zheng
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ba634133
编写于
11月 14, 2016
作者:
shuzheng5201314
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
完成基本controller
上级
b3b60571
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
589 addition
and
1 deletion
+589
-1
cms/cms-web/src/main/java/com/zheng/cms/controller/CmsArticleController.java
...n/java/com/zheng/cms/controller/CmsArticleController.java
+144
-0
cms/cms-web/src/main/java/com/zheng/cms/controller/CmsCategoryController.java
.../java/com/zheng/cms/controller/CmsCategoryController.java
+144
-0
cms/cms-web/src/main/java/com/zheng/cms/controller/CmsCommentController.java
...n/java/com/zheng/cms/controller/CmsCommentController.java
+146
-0
cms/cms-web/src/main/java/com/zheng/cms/controller/CmsTagController.java
.../main/java/com/zheng/cms/controller/CmsTagController.java
+144
-0
common/src/main/java/com/zheng/common/util/Paginator.java
common/src/main/java/com/zheng/common/util/Paginator.java
+11
-1
未找到文件。
cms/cms-web/src/main/java/com/zheng/cms/controller/CmsArticleController.java
0 → 100644
浏览文件 @
ba634133
package
com.zheng.cms.controller
;
import
com.zheng.cms.dao.model.CmsArticle
;
import
com.zheng.cms.dao.model.CmsArticleExample
;
import
com.zheng.cms.service.CmsArticleService
;
import
com.zheng.common.util.Paginator
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.validation.BindingResult
;
import
org.springframework.validation.ObjectError
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.validation.Valid
;
import
java.util.List
;
/**
* 文章控制器
* Created by shuzheng on 2016/11/14.
*/
@Controller
@RequestMapping
(
"/article"
)
public
class
CmsArticleController
extends
BaseController
{
private
final
static
Logger
_log
=
LoggerFactory
.
getLogger
(
CmsArticleController
.
class
);
@Autowired
private
CmsArticleService
cmsArticleService
;
/**
* 首页
* @return
*/
@RequestMapping
(
""
)
public
String
index
()
{
return
"redirect:/article/list"
;
}
/**
* 列表
* @param page
* @param rows
* @param request
* @return
*/
@RequestMapping
(
"/list"
)
public
String
list
(
@RequestParam
(
required
=
false
,
defaultValue
=
"1"
,
value
=
"page"
)
int
page
,
@RequestParam
(
required
=
false
,
defaultValue
=
"20"
,
value
=
"rows"
)
int
rows
,
HttpServletRequest
request
,
Model
model
)
{
// 数据列表
CmsArticleExample
cmsArticleExample
=
new
CmsArticleExample
();
cmsArticleExample
.
setOffset
((
page
-
1
)
*
rows
);
cmsArticleExample
.
setLimit
(
rows
);
cmsArticleExample
.
setOrderByClause
(
"articleId desc"
);
List
<
CmsArticle
>
articles
=
cmsArticleService
.
getMapper
().
selectByExample
(
cmsArticleExample
);
// 分页对象
long
total
=
cmsArticleService
.
getMapper
().
countByExample
(
cmsArticleExample
);
Paginator
paginator
=
new
Paginator
(
total
,
page
,
rows
,
request
);
model
.
addAttribute
(
"articles"
,
articles
);
model
.
addAttribute
(
"paginator"
,
paginator
);
return
"/article/list"
;
}
/**
* 新增get
* @return
*/
@RequestMapping
(
value
=
"/add"
,
method
=
RequestMethod
.
GET
)
public
String
add
()
{
return
"/article/add"
;
}
/**
* 新增post
* @param cmsArticle
* @param binding
* @return
*/
@RequestMapping
(
value
=
"/add"
,
method
=
RequestMethod
.
POST
)
public
String
add
(
@Valid
CmsArticle
cmsArticle
,
BindingResult
binding
)
{
if
(
binding
.
hasErrors
())
{
for
(
ObjectError
error
:
binding
.
getAllErrors
())
{
_log
.
error
(
error
.
getDefaultMessage
());
}
return
"/article/add"
;
}
cmsArticle
.
setCtime
(
System
.
currentTimeMillis
());
cmsArticleService
.
getMapper
().
insertSelective
(
cmsArticle
);
_log
.
info
(
"新增记录id为:{}"
,
cmsArticle
.
getArticleId
());
return
"redirect:/article/list"
;
}
/**
* 删除
* @param id
* @return
*/
@RequestMapping
(
value
=
"/delete/{id}"
,
method
=
RequestMethod
.
GET
)
public
String
delete
(
@PathVariable
(
"id"
)
int
id
)
{
cmsArticleService
.
getMapper
().
deleteByPrimaryKey
(
id
);
return
"redirect:/article/list"
;
}
/**
* 修改get
* @param id
* @param model
* @return
*/
@RequestMapping
(
value
=
"/update/{id}"
,
method
=
RequestMethod
.
GET
)
public
String
update
(
@PathVariable
(
"id"
)
int
id
,
Model
model
)
{
model
.
addAttribute
(
"article"
,
cmsArticleService
.
getMapper
().
selectByPrimaryKey
(
id
));
return
"/article/update"
;
}
/**
* 修改post
* @param id
* @param cmsArticle
* @param binding
* @param model
* @return
*/
@RequestMapping
(
value
=
"/update/{id}"
,
method
=
RequestMethod
.
POST
)
public
String
update
(
@PathVariable
(
"id"
)
int
id
,
@Valid
CmsArticle
cmsArticle
,
BindingResult
binding
,
Model
model
)
{
if
(
binding
.
hasErrors
())
{
model
.
addAttribute
(
"errors"
,
binding
.
getAllErrors
());
return
"/article/update/"
+
id
;
}
cmsArticleService
.
getMapper
().
updateByPrimaryKeySelective
(
cmsArticle
);
return
"redirect:/article/list"
;
}
}
\ No newline at end of file
cms/cms-web/src/main/java/com/zheng/cms/controller/CmsCategoryController.java
0 → 100644
浏览文件 @
ba634133
package
com.zheng.cms.controller
;
import
com.zheng.cms.dao.model.CmsCategory
;
import
com.zheng.cms.dao.model.CmsCategoryExample
;
import
com.zheng.cms.service.CmsCategoryService
;
import
com.zheng.common.util.Paginator
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.validation.BindingResult
;
import
org.springframework.validation.ObjectError
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.validation.Valid
;
import
java.util.List
;
/**
* 类目控制器
* Created by shuzheng on 2016/11/14.
*/
@Controller
@RequestMapping
(
"/category"
)
public
class
CmsCategoryController
extends
BaseController
{
private
final
static
Logger
_log
=
LoggerFactory
.
getLogger
(
CmsCategoryController
.
class
);
@Autowired
private
CmsCategoryService
cmsCategoryService
;
/**
* 首页
* @return
*/
@RequestMapping
(
""
)
public
String
index
()
{
return
"redirect:/category/list"
;
}
/**
* 列表
* @param page
* @param rows
* @param request
* @return
*/
@RequestMapping
(
"/list"
)
public
String
list
(
@RequestParam
(
required
=
false
,
defaultValue
=
"1"
,
value
=
"page"
)
int
page
,
@RequestParam
(
required
=
false
,
defaultValue
=
"20"
,
value
=
"rows"
)
int
rows
,
HttpServletRequest
request
,
Model
model
)
{
// 数据列表
CmsCategoryExample
cmsCategoryExample
=
new
CmsCategoryExample
();
cmsCategoryExample
.
setOffset
((
page
-
1
)
*
rows
);
cmsCategoryExample
.
setLimit
(
rows
);
cmsCategoryExample
.
setOrderByClause
(
"categoryId desc"
);
List
<
CmsCategory
>
categorys
=
cmsCategoryService
.
getMapper
().
selectByExample
(
cmsCategoryExample
);
// 分页对象
long
total
=
cmsCategoryService
.
getMapper
().
countByExample
(
cmsCategoryExample
);
Paginator
paginator
=
new
Paginator
(
total
,
page
,
rows
,
request
);
model
.
addAttribute
(
"categorys"
,
categorys
);
model
.
addAttribute
(
"paginator"
,
paginator
);
return
"/category/list"
;
}
/**
* 新增get
* @return
*/
@RequestMapping
(
value
=
"/add"
,
method
=
RequestMethod
.
GET
)
public
String
add
()
{
return
"/category/add"
;
}
/**
* 新增post
* @param cmsCategory
* @param binding
* @return
*/
@RequestMapping
(
value
=
"/add"
,
method
=
RequestMethod
.
POST
)
public
String
add
(
@Valid
CmsCategory
cmsCategory
,
BindingResult
binding
)
{
if
(
binding
.
hasErrors
())
{
for
(
ObjectError
error
:
binding
.
getAllErrors
())
{
_log
.
error
(
error
.
getDefaultMessage
());
}
return
"/category/add"
;
}
cmsCategory
.
setCtime
(
System
.
currentTimeMillis
());
cmsCategoryService
.
getMapper
().
insertSelective
(
cmsCategory
);
_log
.
info
(
"新增记录id为:{}"
,
cmsCategory
.
getCategoryId
());
return
"redirect:/category/list"
;
}
/**
* 删除
* @param id
* @return
*/
@RequestMapping
(
value
=
"/delete/{id}"
,
method
=
RequestMethod
.
GET
)
public
String
delete
(
@PathVariable
(
"id"
)
int
id
)
{
cmsCategoryService
.
getMapper
().
deleteByPrimaryKey
(
id
);
return
"redirect:/category/list"
;
}
/**
* 修改get
* @param id
* @param model
* @return
*/
@RequestMapping
(
value
=
"/update/{id}"
,
method
=
RequestMethod
.
GET
)
public
String
update
(
@PathVariable
(
"id"
)
int
id
,
Model
model
)
{
model
.
addAttribute
(
"category"
,
cmsCategoryService
.
getMapper
().
selectByPrimaryKey
(
id
));
return
"/category/update"
;
}
/**
* 修改post
* @param id
* @param cmsCategory
* @param binding
* @param model
* @return
*/
@RequestMapping
(
value
=
"/update/{id}"
,
method
=
RequestMethod
.
POST
)
public
String
update
(
@PathVariable
(
"id"
)
int
id
,
@Valid
CmsCategory
cmsCategory
,
BindingResult
binding
,
Model
model
)
{
if
(
binding
.
hasErrors
())
{
model
.
addAttribute
(
"errors"
,
binding
.
getAllErrors
());
return
"/category/update/"
+
id
;
}
cmsCategoryService
.
getMapper
().
updateByPrimaryKeySelective
(
cmsCategory
);
return
"redirect:/category/list"
;
}
}
\ No newline at end of file
cms/cms-web/src/main/java/com/zheng/cms/controller/CmsCommentController.java
0 → 100644
浏览文件 @
ba634133
package
com.zheng.cms.controller
;
import
com.zheng.cms.dao.model.CmsComment
;
import
com.zheng.cms.dao.model.CmsCommentExample
;
import
com.zheng.cms.dao.model.CmsTag
;
import
com.zheng.cms.dao.model.CmsTagExample
;
import
com.zheng.cms.service.CmsCommentService
;
import
com.zheng.common.util.Paginator
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.validation.BindingResult
;
import
org.springframework.validation.ObjectError
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.validation.Valid
;
import
java.util.List
;
/**
* 评论控制器
* Created by shuzheng on 2016/11/14.
*/
@Controller
@RequestMapping
(
"/comment"
)
public
class
CmsCommentController
extends
BaseController
{
private
final
static
Logger
_log
=
LoggerFactory
.
getLogger
(
CmsCommentController
.
class
);
@Autowired
private
CmsCommentService
cmsCommentService
;
/**
* 首页
* @return
*/
@RequestMapping
(
""
)
public
String
index
()
{
return
"redirect:/comment/list"
;
}
/**
* 列表
* @param page
* @param rows
* @param request
* @return
*/
@RequestMapping
(
"/list"
)
public
String
list
(
@RequestParam
(
required
=
false
,
defaultValue
=
"1"
,
value
=
"page"
)
int
page
,
@RequestParam
(
required
=
false
,
defaultValue
=
"20"
,
value
=
"rows"
)
int
rows
,
HttpServletRequest
request
,
Model
model
)
{
// 数据列表
CmsCommentExample
cmsCommentExample
=
new
CmsCommentExample
();
cmsCommentExample
.
setOffset
((
page
-
1
)
*
rows
);
cmsCommentExample
.
setLimit
(
rows
);
cmsCommentExample
.
setOrderByClause
(
"commentId desc"
);
List
<
CmsComment
>
tags
=
cmsCommentService
.
getMapper
().
selectByExample
(
cmsCommentExample
);
// 分页对象
long
total
=
cmsCommentService
.
getMapper
().
countByExample
(
cmsCommentExample
);
Paginator
paginator
=
new
Paginator
(
total
,
page
,
rows
,
request
);
model
.
addAttribute
(
"tags"
,
tags
);
model
.
addAttribute
(
"paginator"
,
paginator
);
return
"/comment/list"
;
}
/**
* 新增get
* @return
*/
@RequestMapping
(
value
=
"/add"
,
method
=
RequestMethod
.
GET
)
public
String
add
()
{
return
"/comment/add"
;
}
/**
* 新增post
* @param cmsComment
* @param binding
* @return
*/
@RequestMapping
(
value
=
"/add"
,
method
=
RequestMethod
.
POST
)
public
String
add
(
@Valid
CmsComment
cmsComment
,
BindingResult
binding
)
{
if
(
binding
.
hasErrors
())
{
for
(
ObjectError
error
:
binding
.
getAllErrors
())
{
_log
.
error
(
error
.
getDefaultMessage
());
}
return
"/comment/add"
;
}
cmsComment
.
setCtime
(
System
.
currentTimeMillis
());
cmsCommentService
.
getMapper
().
insertSelective
(
cmsComment
);
_log
.
info
(
"新增记录id为:{}"
,
cmsComment
.
getArticleId
());
return
"redirect:/comment/list"
;
}
/**
* 删除
* @param id
* @return
*/
@RequestMapping
(
value
=
"/delete/{id}"
,
method
=
RequestMethod
.
GET
)
public
String
delete
(
@PathVariable
(
"id"
)
int
id
)
{
cmsCommentService
.
getMapper
().
deleteByPrimaryKey
(
id
);
return
"redirect:/comment/list"
;
}
/**
* 修改get
* @param id
* @param model
* @return
*/
@RequestMapping
(
value
=
"/update/{id}"
,
method
=
RequestMethod
.
GET
)
public
String
update
(
@PathVariable
(
"id"
)
int
id
,
Model
model
)
{
model
.
addAttribute
(
"comment"
,
cmsCommentService
.
getMapper
().
selectByPrimaryKey
(
id
));
return
"/comment/update"
;
}
/**
* 修改post
* @param id
* @param cmsComment
* @param binding
* @param model
* @return
*/
@RequestMapping
(
value
=
"/update/{id}"
,
method
=
RequestMethod
.
POST
)
public
String
update
(
@PathVariable
(
"id"
)
int
id
,
@Valid
CmsComment
cmsComment
,
BindingResult
binding
,
Model
model
)
{
if
(
binding
.
hasErrors
())
{
model
.
addAttribute
(
"errors"
,
binding
.
getAllErrors
());
return
"/comment/update/"
+
id
;
}
cmsCommentService
.
getMapper
().
updateByPrimaryKeySelective
(
cmsComment
);
return
"redirect:/comment/list"
;
}
}
\ No newline at end of file
cms/cms-web/src/main/java/com/zheng/cms/controller/CmsTagController.java
0 → 100644
浏览文件 @
ba634133
package
com.zheng.cms.controller
;
import
com.zheng.cms.dao.model.CmsTag
;
import
com.zheng.cms.dao.model.CmsTagExample
;
import
com.zheng.cms.service.CmsTagService
;
import
com.zheng.common.util.Paginator
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.validation.BindingResult
;
import
org.springframework.validation.ObjectError
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.validation.Valid
;
import
java.util.List
;
/**
* 标签控制器
* Created by shuzheng on 2016/11/14.
*/
@Controller
@RequestMapping
(
"/tag"
)
public
class
CmsTagController
extends
BaseController
{
private
final
static
Logger
_log
=
LoggerFactory
.
getLogger
(
CmsTagController
.
class
);
@Autowired
private
CmsTagService
cmsTagService
;
/**
* 首页
* @return
*/
@RequestMapping
(
""
)
public
String
index
()
{
return
"redirect:/tag/list"
;
}
/**
* 列表
* @param page
* @param rows
* @param request
* @return
*/
@RequestMapping
(
"/list"
)
public
String
list
(
@RequestParam
(
required
=
false
,
defaultValue
=
"1"
,
value
=
"page"
)
int
page
,
@RequestParam
(
required
=
false
,
defaultValue
=
"20"
,
value
=
"rows"
)
int
rows
,
HttpServletRequest
request
,
Model
model
)
{
// 数据列表
CmsTagExample
cmsTagExample
=
new
CmsTagExample
();
cmsTagExample
.
setOffset
((
page
-
1
)
*
rows
);
cmsTagExample
.
setLimit
(
rows
);
cmsTagExample
.
setOrderByClause
(
"tagId desc"
);
List
<
CmsTag
>
tags
=
cmsTagService
.
getMapper
().
selectByExample
(
cmsTagExample
);
// 分页对象
long
total
=
cmsTagService
.
getMapper
().
countByExample
(
cmsTagExample
);
Paginator
paginator
=
new
Paginator
(
total
,
page
,
rows
,
request
);
model
.
addAttribute
(
"tags"
,
tags
);
model
.
addAttribute
(
"paginator"
,
paginator
);
return
"/tag/list"
;
}
/**
* 新增get
* @return
*/
@RequestMapping
(
value
=
"/add"
,
method
=
RequestMethod
.
GET
)
public
String
add
()
{
return
"/tag/add"
;
}
/**
* 新增post
* @param cmsTag
* @param binding
* @return
*/
@RequestMapping
(
value
=
"/add"
,
method
=
RequestMethod
.
POST
)
public
String
add
(
@Valid
CmsTag
cmsTag
,
BindingResult
binding
)
{
if
(
binding
.
hasErrors
())
{
for
(
ObjectError
error
:
binding
.
getAllErrors
())
{
_log
.
error
(
error
.
getDefaultMessage
());
}
return
"/tag/add"
;
}
cmsTag
.
setCtime
(
System
.
currentTimeMillis
());
cmsTagService
.
getMapper
().
insertSelective
(
cmsTag
);
_log
.
info
(
"新增记录id为:{}"
,
cmsTag
.
getTagId
());
return
"redirect:/tag/list"
;
}
/**
* 删除
* @param id
* @return
*/
@RequestMapping
(
value
=
"/delete/{id}"
,
method
=
RequestMethod
.
GET
)
public
String
delete
(
@PathVariable
(
"id"
)
int
id
)
{
cmsTagService
.
getMapper
().
deleteByPrimaryKey
(
id
);
return
"redirect:/tag/list"
;
}
/**
* 修改get
* @param id
* @param model
* @return
*/
@RequestMapping
(
value
=
"/update/{id}"
,
method
=
RequestMethod
.
GET
)
public
String
update
(
@PathVariable
(
"id"
)
int
id
,
Model
model
)
{
model
.
addAttribute
(
"tag"
,
cmsTagService
.
getMapper
().
selectByPrimaryKey
(
id
));
return
"/tag/update"
;
}
/**
* 修改post
* @param id
* @param cmsTag
* @param binding
* @param model
* @return
*/
@RequestMapping
(
value
=
"/update/{id}"
,
method
=
RequestMethod
.
POST
)
public
String
update
(
@PathVariable
(
"id"
)
int
id
,
@Valid
CmsTag
cmsTag
,
BindingResult
binding
,
Model
model
)
{
if
(
binding
.
hasErrors
())
{
model
.
addAttribute
(
"errors"
,
binding
.
getAllErrors
());
return
"/tag/update/"
+
id
;
}
cmsTagService
.
getMapper
().
updateByPrimaryKeySelective
(
cmsTag
);
return
"redirect:/tag/list"
;
}
}
\ No newline at end of file
common/src/main/java/com/zheng/common/util/Paginator.java
浏览文件 @
ba634133
package
com.zheng.common.util
;
package
com.zheng.common.util
;
import
javax.servlet.http.HttpServletRequest
;
/**
/**
* 分页实体类
* 分页实体类
* @author shuzheng
* @author shuzheng
...
@@ -17,6 +19,14 @@ public class Paginator {
...
@@ -17,6 +19,14 @@ public class Paginator {
private
String
url
=
""
;
// 项目路径
private
String
url
=
""
;
// 项目路径
private
String
query
=
""
;
// 当前页所有参数
private
String
query
=
""
;
// 当前页所有参数
public
Paginator
(
long
total
,
int
page
,
int
rows
,
HttpServletRequest
request
)
{
setTotal
(
total
);
setPage
(
page
);
setRows
(
rows
);
setUrl
(
request
.
getRequestURI
());
setQuery
(
request
.
getQueryString
());
}
public
long
getTotal
()
{
public
long
getTotal
()
{
return
total
;
return
total
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录