From f821cfe687756d14fe4bb591f312306b52fe4578 Mon Sep 17 00:00:00 2001
From: shuzheng <469741414@qq.com>
Date: Mon, 17 Oct 2016 15:16:16 +0800
Subject: [PATCH] =?UTF-8?q?mybatis=20generator=E7=94=9F=E6=88=90=E7=9A=84?=
=?UTF-8?q?=E6=8F=92=E5=85=A5=E6=96=B9=E6=B3=95=E6=89=A7=E8=A1=8C=E5=90=8E?=
=?UTF-8?q?=EF=BC=8C=E8=BF=94=E5=9B=9E=E8=87=AA=E5=A2=9E=E4=B8=BB=E9=94=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../java/com/zheng/cms/mapper/BookMapper.xml | 18 ++++----
.../com/zheng/cms/mapper/CmsArticleMapper.xml | 36 +++++++--------
.../zheng/cms/mapper/CmsCategoryMapper.xml | 26 +++++------
.../com/zheng/cms/mapper/CmsTagMapper.xml | 24 +++++-----
.../java/com/zheng/cms/mapper/UserMapper.xml | 24 +++++-----
.../src/main/resources/generatorConfig.xml | 25 ++++++++---
.../com/zheng/cms/mapper/UserVOMapper.java | 4 --
.../com/zheng/cms/mapper/UserVOMapper.xml | 44 -------------------
.../com/zheng/cms/service/UserService.java | 17 -------
.../cms/service/impl/UserServiceImpl.java | 32 ++------------
.../zheng/cms/controller/UserController.java | 41 ++++++-----------
11 files changed, 97 insertions(+), 194 deletions(-)
diff --git a/cms/cms-dao/src/main/java/com/zheng/cms/mapper/BookMapper.xml b/cms/cms-dao/src/main/java/com/zheng/cms/mapper/BookMapper.xml
index ceab9fc3..c6652baa 100644
--- a/cms/cms-dao/src/main/java/com/zheng/cms/mapper/BookMapper.xml
+++ b/cms/cms-dao/src/main/java/com/zheng/cms/mapper/BookMapper.xml
@@ -106,17 +106,18 @@
- insert into book (id, userid, name
- )
- values (#{id,jdbcType=INTEGER}, #{userid,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}
- )
+
+ SELECT LAST_INSERT_ID()
+
+ insert into book (userid, name)
+ values (#{userid,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR})
+
+ SELECT LAST_INSERT_ID()
+
insert into book
-
- id,
-
userid,
@@ -125,9 +126,6 @@
-
- #{id,jdbcType=INTEGER},
-
#{userid,jdbcType=INTEGER},
diff --git a/cms/cms-dao/src/main/java/com/zheng/cms/mapper/CmsArticleMapper.xml b/cms/cms-dao/src/main/java/com/zheng/cms/mapper/CmsArticleMapper.xml
index 1d4f9168..1430497d 100644
--- a/cms/cms-dao/src/main/java/com/zheng/cms/mapper/CmsArticleMapper.xml
+++ b/cms/cms-dao/src/main/java/com/zheng/cms/mapper/CmsArticleMapper.xml
@@ -144,25 +144,28 @@
- insert into cms_article (article_id, title, author,
- fromurl, image, keywords,
- description, type, allowcomments,
- status, user_id, up,
- down, readnumber, ctime,
- orders, content)
- values (#{articleId,jdbcType=INTEGER}, #{title,jdbcType=VARCHAR}, #{author,jdbcType=VARCHAR},
- #{fromurl,jdbcType=VARCHAR}, #{image,jdbcType=VARCHAR}, #{keywords,jdbcType=VARCHAR},
- #{description,jdbcType=VARCHAR}, #{type,jdbcType=TINYINT}, #{allowcomments,jdbcType=TINYINT},
- #{status,jdbcType=TINYINT}, #{userId,jdbcType=INTEGER}, #{up,jdbcType=INTEGER},
- #{down,jdbcType=INTEGER}, #{readnumber,jdbcType=INTEGER}, #{ctime,jdbcType=BIGINT},
- #{orders,jdbcType=BIGINT}, #{content,jdbcType=LONGVARCHAR})
+
+ SELECT LAST_INSERT_ID()
+
+ insert into cms_article (title, author, fromurl,
+ image, keywords, description,
+ type, allowcomments, status,
+ user_id, up, down, readnumber,
+ ctime, orders, content
+ )
+ values (#{title,jdbcType=VARCHAR}, #{author,jdbcType=VARCHAR}, #{fromurl,jdbcType=VARCHAR},
+ #{image,jdbcType=VARCHAR}, #{keywords,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR},
+ #{type,jdbcType=TINYINT}, #{allowcomments,jdbcType=TINYINT}, #{status,jdbcType=TINYINT},
+ #{userId,jdbcType=INTEGER}, #{up,jdbcType=INTEGER}, #{down,jdbcType=INTEGER}, #{readnumber,jdbcType=INTEGER},
+ #{ctime,jdbcType=BIGINT}, #{orders,jdbcType=BIGINT}, #{content,jdbcType=LONGVARCHAR}
+ )
+
+ SELECT LAST_INSERT_ID()
+
insert into cms_article
-
- article_id,
-
title,
@@ -213,9 +216,6 @@
-
- #{articleId,jdbcType=INTEGER},
-
#{title,jdbcType=VARCHAR},
diff --git a/cms/cms-dao/src/main/java/com/zheng/cms/mapper/CmsCategoryMapper.xml b/cms/cms-dao/src/main/java/com/zheng/cms/mapper/CmsCategoryMapper.xml
index ef65ccbe..147ed48a 100644
--- a/cms/cms-dao/src/main/java/com/zheng/cms/mapper/CmsCategoryMapper.xml
+++ b/cms/cms-dao/src/main/java/com/zheng/cms/mapper/CmsCategoryMapper.xml
@@ -113,21 +113,22 @@
- insert into cms_category (category_id, pid, level,
- name, description, icon,
- type, alias, ctime,
- orders)
- values (#{categoryId,jdbcType=INTEGER}, #{pid,jdbcType=INTEGER}, #{level,jdbcType=TINYINT},
- #{name,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR}, #{icon,jdbcType=VARCHAR},
- #{type,jdbcType=TINYINT}, #{alias,jdbcType=VARCHAR}, #{ctime,jdbcType=BIGINT},
- #{orders,jdbcType=BIGINT})
+
+ SELECT LAST_INSERT_ID()
+
+ insert into cms_category (pid, level, name,
+ description, icon, type,
+ alias, ctime, orders)
+ values (#{pid,jdbcType=INTEGER}, #{level,jdbcType=TINYINT}, #{name,jdbcType=VARCHAR},
+ #{description,jdbcType=VARCHAR}, #{icon,jdbcType=VARCHAR}, #{type,jdbcType=TINYINT},
+ #{alias,jdbcType=VARCHAR}, #{ctime,jdbcType=BIGINT}, #{orders,jdbcType=BIGINT})
+
+ SELECT LAST_INSERT_ID()
+
insert into cms_category
-
- category_id,
-
pid,
@@ -157,9 +158,6 @@
-
- #{categoryId,jdbcType=INTEGER},
-
#{pid,jdbcType=INTEGER},
diff --git a/cms/cms-dao/src/main/java/com/zheng/cms/mapper/CmsTagMapper.xml b/cms/cms-dao/src/main/java/com/zheng/cms/mapper/CmsTagMapper.xml
index 8952f644..f8025461 100644
--- a/cms/cms-dao/src/main/java/com/zheng/cms/mapper/CmsTagMapper.xml
+++ b/cms/cms-dao/src/main/java/com/zheng/cms/mapper/CmsTagMapper.xml
@@ -111,19 +111,22 @@
- insert into cms_tag (tag_id, name, description,
- icon, type, alias,
- ctime, orders)
- values (#{tagId,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR},
- #{icon,jdbcType=VARCHAR}, #{type,jdbcType=TINYINT}, #{alias,jdbcType=VARCHAR},
- #{ctime,jdbcType=BIGINT}, #{orders,jdbcType=BIGINT})
+
+ SELECT LAST_INSERT_ID()
+
+ insert into cms_tag (name, description, icon,
+ type, alias, ctime,
+ orders)
+ values (#{name,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR}, #{icon,jdbcType=VARCHAR},
+ #{type,jdbcType=TINYINT}, #{alias,jdbcType=VARCHAR}, #{ctime,jdbcType=BIGINT},
+ #{orders,jdbcType=BIGINT})
+
+ SELECT LAST_INSERT_ID()
+
insert into cms_tag
-
- tag_id,
-
name,
@@ -147,9 +150,6 @@
-
- #{tagId,jdbcType=INTEGER},
-
#{name,jdbcType=VARCHAR},
diff --git a/cms/cms-dao/src/main/java/com/zheng/cms/mapper/UserMapper.xml b/cms/cms-dao/src/main/java/com/zheng/cms/mapper/UserMapper.xml
index 5aa14cb6..3ac1b005 100644
--- a/cms/cms-dao/src/main/java/com/zheng/cms/mapper/UserMapper.xml
+++ b/cms/cms-dao/src/main/java/com/zheng/cms/mapper/UserMapper.xml
@@ -133,19 +133,22 @@
- insert into user (id, username, password,
- nickname, sex, ctime,
- content)
- values (#{id,jdbcType=INTEGER}, #{username,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR},
- #{nickname,jdbcType=VARCHAR}, #{sex,jdbcType=INTEGER}, #{ctime,jdbcType=BIGINT},
- #{content,jdbcType=LONGVARCHAR})
+
+ SELECT LAST_INSERT_ID()
+
+ insert into user (username, password, nickname,
+ sex, ctime, content
+ )
+ values (#{username,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR}, #{nickname,jdbcType=VARCHAR},
+ #{sex,jdbcType=INTEGER}, #{ctime,jdbcType=BIGINT}, #{content,jdbcType=LONGVARCHAR}
+ )
+
+ SELECT LAST_INSERT_ID()
+
insert into user
-
- id,
-
username,
@@ -166,9 +169,6 @@
-
- #{id,jdbcType=INTEGER},
-
#{username,jdbcType=VARCHAR},
diff --git a/cms/cms-dao/src/main/resources/generatorConfig.xml b/cms/cms-dao/src/main/resources/generatorConfig.xml
index 5bf0a052..85fd34d9 100644
--- a/cms/cms-dao/src/main/resources/generatorConfig.xml
+++ b/cms/cms-dao/src/main/resources/generatorConfig.xml
@@ -48,15 +48,26 @@
-
-
-
-
-
-
+
+
+
+
+
-
+
\ No newline at end of file
diff --git a/cms/cms-service/src/main/java/com/zheng/cms/mapper/UserVOMapper.java b/cms/cms-service/src/main/java/com/zheng/cms/mapper/UserVOMapper.java
index 1064a147..25562e27 100644
--- a/cms/cms-service/src/main/java/com/zheng/cms/mapper/UserVOMapper.java
+++ b/cms/cms-service/src/main/java/com/zheng/cms/mapper/UserVOMapper.java
@@ -18,8 +18,4 @@ public interface UserVOMapper extends UserMapper {
UserVO selectUserWithBook(int id);
- List selectAll(Map map);
-
- void insertAutoKey(User user);
-
}
\ No newline at end of file
diff --git a/cms/cms-service/src/main/java/com/zheng/cms/mapper/UserVOMapper.xml b/cms/cms-service/src/main/java/com/zheng/cms/mapper/UserVOMapper.xml
index e4504c5f..d66cbf26 100644
--- a/cms/cms-service/src/main/java/com/zheng/cms/mapper/UserVOMapper.xml
+++ b/cms/cms-service/src/main/java/com/zheng/cms/mapper/UserVOMapper.xml
@@ -35,49 +35,5 @@
where
u.id=#{id,jdbcType=INTEGER}
-
-
-
-
-
-
- insert into
- user
-
- id,
- username,
- password,
- nickname,
- sex,
- ctime,
-
-
- #{id,jdbcType=INTEGER},
- #{username,jdbcType=VARCHAR},
- #{password,jdbcType=VARCHAR},
- #{nickname,jdbcType=VARCHAR},
- #{sex,jdbcType=INTEGER},
- #{ctime,jdbcType=BIGINT},
-
-
-
\ No newline at end of file
diff --git a/cms/cms-service/src/main/java/com/zheng/cms/service/UserService.java b/cms/cms-service/src/main/java/com/zheng/cms/service/UserService.java
index 1f4bd3fd..bddcc02a 100644
--- a/cms/cms-service/src/main/java/com/zheng/cms/service/UserService.java
+++ b/cms/cms-service/src/main/java/com/zheng/cms/service/UserService.java
@@ -1,10 +1,6 @@
package com.zheng.cms.service;
-import java.util.List;
-import java.util.Map;
-
import com.zheng.cms.mapper.UserMapper;
-import com.zheng.cms.model.User;
import com.zheng.cms.model.UserVO;
/**
@@ -20,18 +16,5 @@ public interface UserService extends BaseService {
* @return
*/
UserVO selectUserWithBook(int id);
-
- /**
- * 根据条件获取用户列表
- * @param map
- * @return
- */
- List selectAll(Map map);
-
- /**
- * 插入用户并返回主键
- * @param user
- */
- void insertAutoKey(User user);
}
\ No newline at end of file
diff --git a/cms/cms-service/src/main/java/com/zheng/cms/service/impl/UserServiceImpl.java b/cms/cms-service/src/main/java/com/zheng/cms/service/impl/UserServiceImpl.java
index 8b6cf917..3301804c 100644
--- a/cms/cms-service/src/main/java/com/zheng/cms/service/impl/UserServiceImpl.java
+++ b/cms/cms-service/src/main/java/com/zheng/cms/service/impl/UserServiceImpl.java
@@ -1,18 +1,12 @@
package com.zheng.cms.service.impl;
-import java.util.List;
-import java.util.Map;
-
import com.zheng.cms.mapper.UserMapper;
-import com.zheng.cms.model.User;
-import com.zheng.cms.model.UserExample;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-
import com.zheng.cms.mapper.UserVOMapper;
import com.zheng.cms.model.UserVO;
import com.zheng.cms.service.UserService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
/**
* 用户service实现
@@ -48,24 +42,4 @@ public class UserServiceImpl implements UserService {
return userVOMapper.selectUserWithBook(id);
}
- /**
- * 根据条件获取用户列表
- * @param map
- * @return
- */
- @Override
- public List selectAll(Map map) {
- return userVOMapper.selectAll(map);
- }
-
- /**
- * 插入用户并返回主键
- * @param user
- */
- @Override
- public void insertAutoKey(User user) {
- userVOMapper.insertAutoKey(user);
- }
-
-
}
\ No newline at end of file
diff --git a/cms/cms-web/src/main/java/com/zheng/cms/controller/UserController.java b/cms/cms-web/src/main/java/com/zheng/cms/controller/UserController.java
index 5338c835..8cddee44 100644
--- a/cms/cms-web/src/main/java/com/zheng/cms/controller/UserController.java
+++ b/cms/cms-web/src/main/java/com/zheng/cms/controller/UserController.java
@@ -30,8 +30,8 @@ import java.util.Map;
@Controller
@RequestMapping("/user")
public class UserController extends BaseController {
-
- private static Logger logger = LoggerFactory.getLogger(UserController.class);
+
+ private static Logger _log = LoggerFactory.getLogger(UserController.class);
@Autowired
private UserService userService;
@@ -59,8 +59,8 @@ public class UserController extends BaseController {
*/
@RequestMapping("/list")
public String list(
- @RequestParam(required = false, defaultValue = "1") int page,
- @RequestParam(required = false, defaultValue = "20") int rows,
+ @RequestParam(required = false, defaultValue = "1", value = "page") int page,
+ @RequestParam(required = false, defaultValue = "20", value = "rows") int rows,
HttpServletRequest request, Model model) {
UserExample userExample = new UserExample();
@@ -69,7 +69,7 @@ public class UserController extends BaseController {
userExample.setOffset((page -1) * rows);
userExample.setLimit(rows);
userExample.setDistinct(false);
- userExample.setOrderByClause(" id desc ");
+ userExample.setOrderByClause(" id asc ");
List users = userService.getMapper().selectByExample(userExample);
model.addAttribute("users", users);
@@ -106,39 +106,26 @@ public class UserController extends BaseController {
public String add(@Valid User user, BindingResult binding) {
if (binding.hasErrors()) {
for (ObjectError error : binding.getAllErrors()) {
- logger.error(error.getDefaultMessage());
+ _log.error(error.getDefaultMessage());
}
return "/user/add";
}
user.setCtime(System.currentTimeMillis());
+
userService.getMapper().insertSelective(user);
+
+ _log.info("新增记录id为:{}", user.getId());
+
return "redirect:/user/list";
}
-
- /**
- * 新增post2,返回自增主键值
- * @param user
- * @param binding
- * @return
- */
- @RequestMapping(value = "/add2", method = RequestMethod.POST)
- public String add2(@Valid User user, BindingResult binding) {
- if (binding.hasErrors()) {
- return "user/add";
- }
- user.setCtime(System.currentTimeMillis());
- userService.insertAutoKey(user);
- System.out.println(user.getId());
- return "redirect:/user/list";
- }
-
+
/**
* 删除
* @param id
* @return
*/
@RequestMapping(value = "/delete/{id}",method = RequestMethod.GET)
- public String delete(@PathVariable int id) {
+ public String delete(@PathVariable("id") int id) {
userService.getMapper().deleteByPrimaryKey(id);
return "redirect:/user/list";
}
@@ -150,7 +137,7 @@ public class UserController extends BaseController {
* @return
*/
@RequestMapping(value = "/update/{id}", method = RequestMethod.GET)
- public String update(@PathVariable int id, Model model) {
+ public String update(@PathVariable("id") int id, Model model) {
model.addAttribute("user", userService.getMapper().selectByPrimaryKey(id));
return "/user/update";
}
@@ -164,7 +151,7 @@ public class UserController extends BaseController {
* @return
*/
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
- public String update(@PathVariable int id, @Valid User user, BindingResult binding, Model model) {
+ public String update(@PathVariable("id") int id, @Valid User user, BindingResult binding, Model model) {
if (binding.hasErrors()) {
model.addAttribute("errors", binding.getAllErrors());
return "user/update/" + id;