From 9713ec74e091772a9d4f4711a02c5964b730d90f Mon Sep 17 00:00:00 2001 From: westxixia Date: Thu, 31 Dec 2015 17:49:32 +0800 Subject: [PATCH] abstract service --- .settings/org.eclipse.jdt.core.prefs | 30 +- .../java/com/ssmssm/core/dao/BaseDao.java | 91 ++++++ .../com/ssmssm/core/entity/BaseCriteria.java | 27 ++ .../ssmssm/{ => core}/entity/BaseEntity.java | 2 +- .../com/ssmssm/{ => core}/entity/Page.java | 2 +- .../com/ssmssm/core/service/BaseService.java | 270 ++++++++++++++++++ .../java/com/ssmssm/core/utils/ComConst.java | 18 ++ .../com/ssmssm/dao/system/BolbFileMapper.java | 11 +- .../ssmssm/dao/system/BusinessLogsMapper.java | 3 +- .../ssmssm/dao/system/CommonCodeMapper.java | 3 +- .../com/ssmssm/dao/system/ResourceMapper.java | 3 +- .../com/ssmssm/dao/system/RoleMapper.java | 3 +- .../ssmssm/dao/system/RoleResourceMapper.java | 3 +- .../com/ssmssm/dao/system/UserMapper.java | 3 +- .../com/ssmssm/dao/system/UserRoleMapper.java | 3 +- .../entity/system/BolbFileCriteria.java | 5 +- .../com/ssmssm/entity/system/BolbFileKey.java | 2 +- .../entity/system/BusinessLogsCriteria.java | 5 +- .../ssmssm/entity/system/BusinessLogsKey.java | 2 +- .../entity/system/CommonCodeCriteria.java | 5 +- .../ssmssm/entity/system/CommonCodeKey.java | 2 +- .../entity/system/ResourceCriteria.java | 5 +- .../com/ssmssm/entity/system/ResourceKey.java | 2 +- .../ssmssm/entity/system/RoleCriteria.java | 5 +- .../com/ssmssm/entity/system/RoleKey.java | 2 +- .../entity/system/RoleResourceCriteria.java | 5 +- .../ssmssm/entity/system/RoleResourceKey.java | 2 +- .../ssmssm/entity/system/UserCriteria.java | 5 +- .../com/ssmssm/entity/system/UserKey.java | 2 +- .../entity/system/UserRoleCriteria.java | 5 +- .../com/ssmssm/entity/system/UserRoleKey.java | 2 +- .../ssmssm/service/system/UserService.java | 102 ++++--- .../ssmssm/view/system/UserController.java | 28 +- .../plugins/PostgreSQLPaginationPlugin.java | 2 +- .../resources/mybatis/generatorConfig.xml | 2 +- .../webapp/WEB-INF/res/js/common/comconst.js | 20 +- .../WEB-INF/res/js/common/datatablesInit.js | 2 +- .../WEB-INF/res/js/system/user_index.js | 63 +++- src/main/webapp/WEB-INF/views/user/index.jsp | 4 +- 39 files changed, 631 insertions(+), 120 deletions(-) create mode 100644 src/main/java/com/ssmssm/core/dao/BaseDao.java create mode 100644 src/main/java/com/ssmssm/core/entity/BaseCriteria.java rename src/main/java/com/ssmssm/{ => core}/entity/BaseEntity.java (96%) rename src/main/java/com/ssmssm/{ => core}/entity/Page.java (94%) create mode 100644 src/main/java/com/ssmssm/core/service/BaseService.java diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index 63747e0..01d0f02 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -21,14 +21,14 @@ org.eclipse.jdt.core.formatter.alignment_for_enum_constants=0 org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16 org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0 org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16 -org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=0 org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_resources_in_try=80 org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=80 org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16 -org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=37 +org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=5 org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=37 org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch=16 org.eclipse.jdt.core.formatter.blank_lines_after_imports=1 @@ -64,7 +64,7 @@ org.eclipse.jdt.core.formatter.comment.format_line_comments=true org.eclipse.jdt.core.formatter.comment.format_source_code=true org.eclipse.jdt.core.formatter.comment.indent_parameter_description=true org.eclipse.jdt.core.formatter.comment.indent_root_tags=true -org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert +org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=do not insert org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=do not insert org.eclipse.jdt.core.formatter.comment.line_length=120 org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries=true @@ -94,22 +94,22 @@ org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method=insert org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package=insert org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=insert org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type=insert -org.eclipse.jdt.core.formatter.insert_new_line_after_label=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_after_label=insert org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert org.eclipse.jdt.core.formatter.insert_new_line_after_type_annotation=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=insert +org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=insert +org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement=insert -org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement=insert +org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement=do not insert org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration=insert org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert diff --git a/src/main/java/com/ssmssm/core/dao/BaseDao.java b/src/main/java/com/ssmssm/core/dao/BaseDao.java new file mode 100644 index 0000000..0ee92ad --- /dev/null +++ b/src/main/java/com/ssmssm/core/dao/BaseDao.java @@ -0,0 +1,91 @@ +package com.ssmssm.core.dao; + +import java.util.List; + +import org.apache.ibatis.annotations.Param; + +import com.ssmssm.core.entity.BaseCriteria; +import com.ssmssm.core.entity.BaseEntity; + +public interface BaseDao { + + /** + * 根据条件检索数据件数 + * @param example + * @return + */ + int countByExample(BaseCriteria example); + + /** + * 根据主键检索数据 + * @param key + * @return + */ + BaseEntity selectByPrimaryKey(BaseEntity key); + + /** + * 根据条件检索数据 + * @param example + * @return + */ + List selectByExample(BaseCriteria example); + + /** + * 新增数据 + * @param record + * @return + */ + int insert(BaseEntity record); + + /** + * 根据条件新增数据(null不处理) + * @param record + * @return + */ + int insertSelective(BaseEntity record); + + /** + * 根据主键更新数据 + * @param record + * @return + */ + int updateByPrimaryKey(BaseEntity record); + + /** + * 根据主键更新数据(null不处理) + * @param record + * @return + */ + int updateByPrimaryKeySelective(BaseEntity record); + + /** + * 根据条件更新数据 + * @param record + * @param example + * @return + */ + int updateByExample(@Param("record") BaseEntity record, @Param("example") BaseCriteria example); + + /** + * 根据条件更新数据(null不处理) + * @param record + * @param example + * @return + */ + int updateByExampleSelective(@Param("record") BaseEntity record, @Param("example") BaseCriteria example); + + /** + * 根据主键删除数据 + * @param key + * @return + */ + int deleteByPrimaryKey(BaseEntity key); + + /** + * 根据条件删除数据 + * @param example + * @return + */ + int deleteByExample(BaseCriteria example); + +} diff --git a/src/main/java/com/ssmssm/core/entity/BaseCriteria.java b/src/main/java/com/ssmssm/core/entity/BaseCriteria.java new file mode 100644 index 0000000..7d3ac12 --- /dev/null +++ b/src/main/java/com/ssmssm/core/entity/BaseCriteria.java @@ -0,0 +1,27 @@ +package com.ssmssm.core.entity; + + + +public abstract class BaseCriteria { + /** + * This field was generated by MyBatis Generator. This field corresponds to the database table t_auth_user + * @mbggenerated + */ + protected Page page; + + /** + * This method was generated by MyBatis Generator. This method corresponds to the database table t_auth_user + * @mbggenerated + */ + public void setPage(Page page) { + this.page = page; + } + + /** + * This method was generated by MyBatis Generator. This method corresponds to the database table t_auth_user + * @mbggenerated + */ + public Page getPage() { + return page; + } +} \ No newline at end of file diff --git a/src/main/java/com/ssmssm/entity/BaseEntity.java b/src/main/java/com/ssmssm/core/entity/BaseEntity.java similarity index 96% rename from src/main/java/com/ssmssm/entity/BaseEntity.java rename to src/main/java/com/ssmssm/core/entity/BaseEntity.java index 21d9790..88d2999 100644 --- a/src/main/java/com/ssmssm/entity/BaseEntity.java +++ b/src/main/java/com/ssmssm/core/entity/BaseEntity.java @@ -1,4 +1,4 @@ -package com.ssmssm.entity; +package com.ssmssm.core.entity; import java.io.Serializable; import java.util.Date; diff --git a/src/main/java/com/ssmssm/entity/Page.java b/src/main/java/com/ssmssm/core/entity/Page.java similarity index 94% rename from src/main/java/com/ssmssm/entity/Page.java rename to src/main/java/com/ssmssm/core/entity/Page.java index 60a06bd..e899d4a 100644 --- a/src/main/java/com/ssmssm/entity/Page.java +++ b/src/main/java/com/ssmssm/core/entity/Page.java @@ -1,4 +1,4 @@ -package com.ssmssm.entity; +package com.ssmssm.core.entity; import java.math.BigDecimal; diff --git a/src/main/java/com/ssmssm/core/service/BaseService.java b/src/main/java/com/ssmssm/core/service/BaseService.java new file mode 100644 index 0000000..c57e5cf --- /dev/null +++ b/src/main/java/com/ssmssm/core/service/BaseService.java @@ -0,0 +1,270 @@ +package com.ssmssm.core.service; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.log4j.Logger; +import org.springframework.transaction.annotation.Transactional; + +import com.ssmssm.core.dao.BaseDao; +import com.ssmssm.core.entity.BaseCriteria; +import com.ssmssm.core.entity.BaseEntity; +import com.ssmssm.core.entity.Page; +import com.ssmssm.core.utils.ComConst; + +@Transactional(readOnly = true) +public abstract class BaseService { + + /** 日志记录对象. */ + private Logger logger = Logger.getLogger(getClass()); + + /** mapper(BaseDao):dao实例. */ + private BaseDao mapper; + + /** + * 设置Mapper + * @param mapper + */ + public void setMapper(BaseDao mapper) { + this.mapper = mapper; + } + + /** + * 获取Mapper + * @return + */ + protected BaseDao getMapper() { + return mapper; + } + + /** + * 根据主键检索数据 + * @param key + * @return + */ + public Map selectByExamplePagination(Integer start, Integer length, BaseCriteria example) { + Map resultMap = new HashMap(); + example.setPage(new Page(start, length)); + int cnt = getMapper().countByExample(example); + resultMap.put("recordsTotal", cnt); + resultMap.put("recordsFiltered", cnt); + resultMap.put("data", getMapper().selectByExample(example)); + return resultMap; + } + + /** + * 根据条件检索数据 + * @param example + * @return + */ + public Map selectByExample(BaseCriteria example) { + Map resultMap = new HashMap(); + int cnt = getMapper().countByExample(example); + resultMap.put("recordsTotal", cnt); + resultMap.put("recordsFiltered", cnt); + resultMap.put("data", getMapper().selectByExample(example)); + return resultMap; + } + + /** + * 新增数据 + * @param record + * @return + */ + @Transactional + protected Map insert(BaseEntity entity){ + Map resultMap = new HashMap(); + Integer cnt = 0; + try { + cnt = getMapper().insert(entity); + } catch (Exception e) { + resultMap.put(ComConst.RESULT_CODE, ComConst.RESULT_CODE_FAILD_9); + logger.error(e.getMessage()); + } + if (cnt == 0) { + resultMap.put(ComConst.RESULT_CODE, ComConst.RESULT_CODE_FAILD_1); + } else if (cnt == 1) { + resultMap.put(ComConst.RESULT_CODE, ComConst.RESULT_CODE_SUCCESS); + } else { + resultMap.put(ComConst.RESULT_CODE, ComConst.RESULT_CODE_FAILD_9); + } + return resultMap; + } + + /** + * 根据条件新增数据(null不处理) + * @param record + * @return + */ + @Transactional + protected Map insertSelective(BaseEntity entity){ + Map resultMap = new HashMap(); + Integer cnt = 0; + try { + cnt = getMapper().insertSelective(entity); + } catch (Exception e) { + resultMap.put(ComConst.RESULT_CODE, ComConst.RESULT_CODE_FAILD_9); + logger.error(e.getMessage()); + } + if (cnt == 0) { + resultMap.put(ComConst.RESULT_CODE, ComConst.RESULT_CODE_FAILD_1); + } else if (cnt == 1) { + resultMap.put(ComConst.RESULT_CODE, ComConst.RESULT_CODE_SUCCESS); + } else { + resultMap.put(ComConst.RESULT_CODE, ComConst.RESULT_CODE_FAILD_9); + } + return resultMap; + } + + /** + * 根据主键更新数据 + * @param record + * @return + */ + @Transactional + public Map updateByPrimaryKey(BaseEntity entity) { + Map resultMap = new HashMap(); + Integer cnt = 0; + try { + cnt = getMapper().updateByPrimaryKey(entity); + } catch (Exception e) { + resultMap.put(ComConst.RESULT_CODE, ComConst.RESULT_CODE_FAILD_9); + logger.error(e.getMessage()); + } + if (cnt == 0) { + resultMap.put(ComConst.RESULT_CODE, ComConst.RESULT_CODE_FAILD_2); + } else if (cnt == 1) { + resultMap.put(ComConst.RESULT_CODE, ComConst.RESULT_CODE_SUCCESS); + } else { + resultMap.put(ComConst.RESULT_CODE, ComConst.RESULT_CODE_FAILD_9); + } + return resultMap; + } + + /** + * 根据主键更新数据(null不处理) + * @param record + * @return + */ + @Transactional + public Map updateByPrimaryKeySelective(BaseEntity entity) { + Map resultMap = new HashMap(); + Integer cnt = 0; + try { + cnt = getMapper().updateByPrimaryKeySelective(entity); + } catch (Exception e) { + resultMap.put(ComConst.RESULT_CODE, ComConst.RESULT_CODE_FAILD_9); + logger.error(e.getMessage()); + } + if (cnt == 0) { + resultMap.put(ComConst.RESULT_CODE, ComConst.RESULT_CODE_FAILD_2); + } else if (cnt == 1) { + resultMap.put(ComConst.RESULT_CODE, ComConst.RESULT_CODE_SUCCESS); + } else { + resultMap.put(ComConst.RESULT_CODE, ComConst.RESULT_CODE_FAILD_9); + } + return resultMap; + } + + /** + * 根据条件更新数据 + * @param record + * @param example + * @return + */ + @Transactional + public Map updateByExample(BaseEntity record, BaseCriteria example) { + Map resultMap = new HashMap(); + Integer cnt = 0; + try { + cnt = getMapper().updateByExample(record, example); + } catch (Exception e) { + resultMap.put(ComConst.RESULT_CODE, ComConst.RESULT_CODE_FAILD_9); + logger.error(e.getMessage()); + } + if (cnt == 0) { + resultMap.put(ComConst.RESULT_CODE, ComConst.RESULT_CODE_FAILD_2); + } else if (cnt == 1) { + resultMap.put(ComConst.RESULT_CODE, ComConst.RESULT_CODE_SUCCESS); + } else { + resultMap.put(ComConst.RESULT_CODE, ComConst.RESULT_CODE_FAILD_9); + } + return resultMap; + } + + /** + * 根据条件更新数据(null不处理) + * @param record + * @param example + * @return + */ + @Transactional + public Map updateByExampleSelective(BaseEntity record, BaseCriteria example) { + Map resultMap = new HashMap(); + Integer cnt = 0; + try { + cnt = getMapper().updateByExampleSelective(record, example); + } catch (Exception e) { + resultMap.put(ComConst.RESULT_CODE, ComConst.RESULT_CODE_FAILD_9); + logger.error(e.getMessage()); + } + if (cnt == 0) { + resultMap.put(ComConst.RESULT_CODE, ComConst.RESULT_CODE_FAILD_2); + } else if (cnt == 1) { + resultMap.put(ComConst.RESULT_CODE, ComConst.RESULT_CODE_SUCCESS); + } else { + resultMap.put(ComConst.RESULT_CODE, ComConst.RESULT_CODE_FAILD_9); + } + return resultMap; + } + + /** + * 根据主键删除数据 + * @param key + * @return + */ + @Transactional + public Map deleteByPrimaryKey(BaseEntity entity) { + Map resultMap = new HashMap(); + Integer cnt = 0; + try { + cnt = getMapper().deleteByPrimaryKey(entity); + } catch (Exception e) { + resultMap.put(ComConst.RESULT_CODE, ComConst.RESULT_CODE_FAILD_9); + logger.error(e.getMessage()); + } + if (cnt == 0) { + resultMap.put(ComConst.RESULT_CODE, ComConst.RESULT_CODE_FAILD_2); + } else if (cnt == 1) { + resultMap.put(ComConst.RESULT_CODE, ComConst.RESULT_CODE_SUCCESS); + } else { + resultMap.put(ComConst.RESULT_CODE, ComConst.RESULT_CODE_FAILD_9); + } + return resultMap; + } + + /** + * 根据条件删除数据 + * @param example + * @return + */ + @Transactional + public Map deleteByExample(BaseCriteria example) { + Map resultMap = new HashMap(); + Integer cnt = 0; + try { + cnt = getMapper().deleteByExample(example); + } catch (Exception e) { + resultMap.put(ComConst.RESULT_CODE, ComConst.RESULT_CODE_FAILD_9); + logger.error(e.getMessage()); + } + if (cnt == 0) { + resultMap.put(ComConst.RESULT_CODE, ComConst.RESULT_CODE_FAILD_2); + } else if (cnt == 1) { + resultMap.put(ComConst.RESULT_CODE, ComConst.RESULT_CODE_SUCCESS); + } else { + resultMap.put(ComConst.RESULT_CODE, ComConst.RESULT_CODE_FAILD_9); + } + return resultMap; + } +} diff --git a/src/main/java/com/ssmssm/core/utils/ComConst.java b/src/main/java/com/ssmssm/core/utils/ComConst.java index 1c5266b..a97e2aa 100644 --- a/src/main/java/com/ssmssm/core/utils/ComConst.java +++ b/src/main/java/com/ssmssm/core/utils/ComConst.java @@ -52,10 +52,28 @@ public static ComConst getSingleton() { /** 返回值0:正常 */ public static final String RESULT_CODE_SUCCESS = "0"; + + /** 返回值1:一意制约 */ + public static final String RESULT_CODE_FAILD_1 = "1"; + + /** 返回值2:排他异常 */ + public static final String RESULT_CODE_FAILD_2 = "2"; /** 返回值0:Exception发生 */ public static final String RESULT_CODE_FAILD_9 = "9"; + /** 操作模式 */ + public static final String OPERATE_MODE_ID = "operate"; + + /** 操作模式(I:登录) */ + public static final String OPERATE_MODE_I = "I"; + + /** 操作模式(U:更新) */ + public static final String OPERATE_MODE_U = "U"; + + /** 操作模式(D:删除) */ + public static final String OPERATE_MODE_D = "D"; + /** 性别(100001) */ public static final Integer SEX_ID = 100001; diff --git a/src/main/java/com/ssmssm/dao/system/BolbFileMapper.java b/src/main/java/com/ssmssm/dao/system/BolbFileMapper.java index 51cc917..0b18cfe 100644 --- a/src/main/java/com/ssmssm/dao/system/BolbFileMapper.java +++ b/src/main/java/com/ssmssm/dao/system/BolbFileMapper.java @@ -1,16 +1,17 @@ package com.ssmssm.dao.system; +import java.util.List; + +import org.apache.ibatis.annotations.Param; + import com.ssmssm.core.annotation.MyBatisRepository; +import com.ssmssm.core.dao.BaseDao; import com.ssmssm.entity.system.BolbFile; import com.ssmssm.entity.system.BolbFileCriteria; import com.ssmssm.entity.system.BolbFileKey; -import java.util.List; - -import org.apache.ibatis.annotations.Param; - @MyBatisRepository -public interface BolbFileMapper { +public interface BolbFileMapper extends BaseDao{ /** * This method was generated by MyBatis Generator. This method corresponds to the database table t_sys_blob_file diff --git a/src/main/java/com/ssmssm/dao/system/BusinessLogsMapper.java b/src/main/java/com/ssmssm/dao/system/BusinessLogsMapper.java index eeedf9b..accea68 100644 --- a/src/main/java/com/ssmssm/dao/system/BusinessLogsMapper.java +++ b/src/main/java/com/ssmssm/dao/system/BusinessLogsMapper.java @@ -1,6 +1,7 @@ package com.ssmssm.dao.system; import com.ssmssm.core.annotation.MyBatisRepository; +import com.ssmssm.core.dao.BaseDao; import com.ssmssm.entity.system.BusinessLogs; import com.ssmssm.entity.system.BusinessLogsCriteria; import com.ssmssm.entity.system.BusinessLogsKey; @@ -10,7 +11,7 @@ import org.apache.ibatis.annotations.Param; @MyBatisRepository -public interface BusinessLogsMapper { +public interface BusinessLogsMapper extends BaseDao{ /** * This method was generated by MyBatis Generator. This method corresponds to the database table t_sys_business_logs diff --git a/src/main/java/com/ssmssm/dao/system/CommonCodeMapper.java b/src/main/java/com/ssmssm/dao/system/CommonCodeMapper.java index 62f1fc6..122584e 100644 --- a/src/main/java/com/ssmssm/dao/system/CommonCodeMapper.java +++ b/src/main/java/com/ssmssm/dao/system/CommonCodeMapper.java @@ -1,6 +1,7 @@ package com.ssmssm.dao.system; import com.ssmssm.core.annotation.MyBatisRepository; +import com.ssmssm.core.dao.BaseDao; import com.ssmssm.entity.system.CommonCode; import com.ssmssm.entity.system.CommonCodeCriteria; import com.ssmssm.entity.system.CommonCodeKey; @@ -10,7 +11,7 @@ import org.apache.ibatis.annotations.Param; @MyBatisRepository -public interface CommonCodeMapper { +public interface CommonCodeMapper extends BaseDao{ /** * This method was generated by MyBatis Generator. This method corresponds to the database table t_sys_common_code diff --git a/src/main/java/com/ssmssm/dao/system/ResourceMapper.java b/src/main/java/com/ssmssm/dao/system/ResourceMapper.java index 96c2a81..d581f05 100644 --- a/src/main/java/com/ssmssm/dao/system/ResourceMapper.java +++ b/src/main/java/com/ssmssm/dao/system/ResourceMapper.java @@ -1,6 +1,7 @@ package com.ssmssm.dao.system; import com.ssmssm.core.annotation.MyBatisRepository; +import com.ssmssm.core.dao.BaseDao; import com.ssmssm.entity.system.Resource; import com.ssmssm.entity.system.ResourceCriteria; import com.ssmssm.entity.system.ResourceKey; @@ -10,7 +11,7 @@ import org.apache.ibatis.annotations.Param; @MyBatisRepository -public interface ResourceMapper { +public interface ResourceMapper extends BaseDao{ /** * This method was generated by MyBatis Generator. This method corresponds to the database table t_auth_resource diff --git a/src/main/java/com/ssmssm/dao/system/RoleMapper.java b/src/main/java/com/ssmssm/dao/system/RoleMapper.java index 6f55a81..c8bcb00 100644 --- a/src/main/java/com/ssmssm/dao/system/RoleMapper.java +++ b/src/main/java/com/ssmssm/dao/system/RoleMapper.java @@ -1,6 +1,7 @@ package com.ssmssm.dao.system; import com.ssmssm.core.annotation.MyBatisRepository; +import com.ssmssm.core.dao.BaseDao; import com.ssmssm.entity.system.Role; import com.ssmssm.entity.system.RoleCriteria; import com.ssmssm.entity.system.RoleKey; @@ -10,7 +11,7 @@ import org.apache.ibatis.annotations.Param; @MyBatisRepository -public interface RoleMapper { +public interface RoleMapper extends BaseDao{ /** * This method was generated by MyBatis Generator. This method corresponds to the database table t_auth_role diff --git a/src/main/java/com/ssmssm/dao/system/RoleResourceMapper.java b/src/main/java/com/ssmssm/dao/system/RoleResourceMapper.java index 911f61e..2a74bd0 100644 --- a/src/main/java/com/ssmssm/dao/system/RoleResourceMapper.java +++ b/src/main/java/com/ssmssm/dao/system/RoleResourceMapper.java @@ -1,6 +1,7 @@ package com.ssmssm.dao.system; import com.ssmssm.core.annotation.MyBatisRepository; +import com.ssmssm.core.dao.BaseDao; import com.ssmssm.entity.system.RoleResource; import com.ssmssm.entity.system.RoleResourceCriteria; import com.ssmssm.entity.system.RoleResourceKey; @@ -10,7 +11,7 @@ import org.apache.ibatis.annotations.Param; @MyBatisRepository -public interface RoleResourceMapper { +public interface RoleResourceMapper extends BaseDao{ /** * This method was generated by MyBatis Generator. This method corresponds to the database table t_auth_role_resource diff --git a/src/main/java/com/ssmssm/dao/system/UserMapper.java b/src/main/java/com/ssmssm/dao/system/UserMapper.java index 585e97a..f1a7b64 100644 --- a/src/main/java/com/ssmssm/dao/system/UserMapper.java +++ b/src/main/java/com/ssmssm/dao/system/UserMapper.java @@ -1,6 +1,7 @@ package com.ssmssm.dao.system; import com.ssmssm.core.annotation.MyBatisRepository; +import com.ssmssm.core.dao.BaseDao; import com.ssmssm.entity.system.User; import com.ssmssm.entity.system.UserCriteria; import com.ssmssm.entity.system.UserKey; @@ -10,7 +11,7 @@ import org.apache.ibatis.annotations.Param; @MyBatisRepository -public interface UserMapper { +public interface UserMapper extends BaseDao{ /** * This method was generated by MyBatis Generator. This method corresponds to the database table t_auth_user diff --git a/src/main/java/com/ssmssm/dao/system/UserRoleMapper.java b/src/main/java/com/ssmssm/dao/system/UserRoleMapper.java index 69bd31c..a787945 100644 --- a/src/main/java/com/ssmssm/dao/system/UserRoleMapper.java +++ b/src/main/java/com/ssmssm/dao/system/UserRoleMapper.java @@ -1,6 +1,7 @@ package com.ssmssm.dao.system; import com.ssmssm.core.annotation.MyBatisRepository; +import com.ssmssm.core.dao.BaseDao; import com.ssmssm.entity.system.UserRole; import com.ssmssm.entity.system.UserRoleCriteria; import com.ssmssm.entity.system.UserRoleKey; @@ -10,7 +11,7 @@ import org.apache.ibatis.annotations.Param; @MyBatisRepository -public interface UserRoleMapper { +public interface UserRoleMapper extends BaseDao{ /** * This method was generated by MyBatis Generator. This method corresponds to the database table t_auth_user_role diff --git a/src/main/java/com/ssmssm/entity/system/BolbFileCriteria.java b/src/main/java/com/ssmssm/entity/system/BolbFileCriteria.java index d6f41aa..06751c5 100644 --- a/src/main/java/com/ssmssm/entity/system/BolbFileCriteria.java +++ b/src/main/java/com/ssmssm/entity/system/BolbFileCriteria.java @@ -4,9 +4,10 @@ import java.util.Date; import java.util.List; -import com.ssmssm.entity.Page; +import com.ssmssm.core.entity.BaseCriteria; +import com.ssmssm.core.entity.Page; -public class BolbFileCriteria { +public class BolbFileCriteria extends BaseCriteria { /** * This field was generated by MyBatis Generator. This field corresponds to the database table t_sys_blob_file * @mbggenerated diff --git a/src/main/java/com/ssmssm/entity/system/BolbFileKey.java b/src/main/java/com/ssmssm/entity/system/BolbFileKey.java index 4437603..e1e2635 100644 --- a/src/main/java/com/ssmssm/entity/system/BolbFileKey.java +++ b/src/main/java/com/ssmssm/entity/system/BolbFileKey.java @@ -1,6 +1,6 @@ package com.ssmssm.entity.system; -import com.ssmssm.entity.BaseEntity; +import com.ssmssm.core.entity.BaseEntity; import java.io.Serializable; diff --git a/src/main/java/com/ssmssm/entity/system/BusinessLogsCriteria.java b/src/main/java/com/ssmssm/entity/system/BusinessLogsCriteria.java index b3da0ad..cdf7c7e 100644 --- a/src/main/java/com/ssmssm/entity/system/BusinessLogsCriteria.java +++ b/src/main/java/com/ssmssm/entity/system/BusinessLogsCriteria.java @@ -4,9 +4,10 @@ import java.util.Date; import java.util.List; -import com.ssmssm.entity.Page; +import com.ssmssm.core.entity.BaseCriteria; +import com.ssmssm.core.entity.Page; -public class BusinessLogsCriteria { +public class BusinessLogsCriteria extends BaseCriteria { /** * This field was generated by MyBatis Generator. This field corresponds to the database table t_sys_business_logs * @mbggenerated diff --git a/src/main/java/com/ssmssm/entity/system/BusinessLogsKey.java b/src/main/java/com/ssmssm/entity/system/BusinessLogsKey.java index 0200c38..2caea7c 100644 --- a/src/main/java/com/ssmssm/entity/system/BusinessLogsKey.java +++ b/src/main/java/com/ssmssm/entity/system/BusinessLogsKey.java @@ -1,6 +1,6 @@ package com.ssmssm.entity.system; -import com.ssmssm.entity.BaseEntity; +import com.ssmssm.core.entity.BaseEntity; import java.io.Serializable; diff --git a/src/main/java/com/ssmssm/entity/system/CommonCodeCriteria.java b/src/main/java/com/ssmssm/entity/system/CommonCodeCriteria.java index 6b63e58..8cec465 100644 --- a/src/main/java/com/ssmssm/entity/system/CommonCodeCriteria.java +++ b/src/main/java/com/ssmssm/entity/system/CommonCodeCriteria.java @@ -4,9 +4,10 @@ import java.util.Date; import java.util.List; -import com.ssmssm.entity.Page; +import com.ssmssm.core.entity.BaseCriteria; +import com.ssmssm.core.entity.Page; -public class CommonCodeCriteria { +public class CommonCodeCriteria extends BaseCriteria { /** * This field was generated by MyBatis Generator. This field corresponds to the database table t_sys_common_code * @mbggenerated diff --git a/src/main/java/com/ssmssm/entity/system/CommonCodeKey.java b/src/main/java/com/ssmssm/entity/system/CommonCodeKey.java index e399502..55f256a 100644 --- a/src/main/java/com/ssmssm/entity/system/CommonCodeKey.java +++ b/src/main/java/com/ssmssm/entity/system/CommonCodeKey.java @@ -1,6 +1,6 @@ package com.ssmssm.entity.system; -import com.ssmssm.entity.BaseEntity; +import com.ssmssm.core.entity.BaseEntity; import java.io.Serializable; diff --git a/src/main/java/com/ssmssm/entity/system/ResourceCriteria.java b/src/main/java/com/ssmssm/entity/system/ResourceCriteria.java index 5f1e7d7..f76b5a1 100644 --- a/src/main/java/com/ssmssm/entity/system/ResourceCriteria.java +++ b/src/main/java/com/ssmssm/entity/system/ResourceCriteria.java @@ -4,9 +4,10 @@ import java.util.Date; import java.util.List; -import com.ssmssm.entity.Page; +import com.ssmssm.core.entity.BaseCriteria; +import com.ssmssm.core.entity.Page; -public class ResourceCriteria { +public class ResourceCriteria extends BaseCriteria { /** * This field was generated by MyBatis Generator. This field corresponds to the database table t_auth_resource * @mbggenerated diff --git a/src/main/java/com/ssmssm/entity/system/ResourceKey.java b/src/main/java/com/ssmssm/entity/system/ResourceKey.java index c85615d..b4719b4 100644 --- a/src/main/java/com/ssmssm/entity/system/ResourceKey.java +++ b/src/main/java/com/ssmssm/entity/system/ResourceKey.java @@ -1,6 +1,6 @@ package com.ssmssm.entity.system; -import com.ssmssm.entity.BaseEntity; +import com.ssmssm.core.entity.BaseEntity; import java.io.Serializable; diff --git a/src/main/java/com/ssmssm/entity/system/RoleCriteria.java b/src/main/java/com/ssmssm/entity/system/RoleCriteria.java index ca01340..8241c7d 100644 --- a/src/main/java/com/ssmssm/entity/system/RoleCriteria.java +++ b/src/main/java/com/ssmssm/entity/system/RoleCriteria.java @@ -4,9 +4,10 @@ import java.util.Date; import java.util.List; -import com.ssmssm.entity.Page; +import com.ssmssm.core.entity.BaseCriteria; +import com.ssmssm.core.entity.Page; -public class RoleCriteria { +public class RoleCriteria extends BaseCriteria { /** * This field was generated by MyBatis Generator. This field corresponds to the database table t_auth_role * @mbggenerated diff --git a/src/main/java/com/ssmssm/entity/system/RoleKey.java b/src/main/java/com/ssmssm/entity/system/RoleKey.java index 9d677fa..1ba3315 100644 --- a/src/main/java/com/ssmssm/entity/system/RoleKey.java +++ b/src/main/java/com/ssmssm/entity/system/RoleKey.java @@ -1,6 +1,6 @@ package com.ssmssm.entity.system; -import com.ssmssm.entity.BaseEntity; +import com.ssmssm.core.entity.BaseEntity; import java.io.Serializable; diff --git a/src/main/java/com/ssmssm/entity/system/RoleResourceCriteria.java b/src/main/java/com/ssmssm/entity/system/RoleResourceCriteria.java index 618f7f4..908558a 100644 --- a/src/main/java/com/ssmssm/entity/system/RoleResourceCriteria.java +++ b/src/main/java/com/ssmssm/entity/system/RoleResourceCriteria.java @@ -4,9 +4,10 @@ import java.util.Date; import java.util.List; -import com.ssmssm.entity.Page; +import com.ssmssm.core.entity.BaseCriteria; +import com.ssmssm.core.entity.Page; -public class RoleResourceCriteria { +public class RoleResourceCriteria extends BaseCriteria { /** * This field was generated by MyBatis Generator. This field corresponds to the database table t_auth_role_resource * @mbggenerated diff --git a/src/main/java/com/ssmssm/entity/system/RoleResourceKey.java b/src/main/java/com/ssmssm/entity/system/RoleResourceKey.java index 7e83f0a..6ca1f37 100644 --- a/src/main/java/com/ssmssm/entity/system/RoleResourceKey.java +++ b/src/main/java/com/ssmssm/entity/system/RoleResourceKey.java @@ -1,6 +1,6 @@ package com.ssmssm.entity.system; -import com.ssmssm.entity.BaseEntity; +import com.ssmssm.core.entity.BaseEntity; import java.io.Serializable; diff --git a/src/main/java/com/ssmssm/entity/system/UserCriteria.java b/src/main/java/com/ssmssm/entity/system/UserCriteria.java index 1d8117c..fc6c398 100644 --- a/src/main/java/com/ssmssm/entity/system/UserCriteria.java +++ b/src/main/java/com/ssmssm/entity/system/UserCriteria.java @@ -4,9 +4,10 @@ import java.util.Date; import java.util.List; -import com.ssmssm.entity.Page; +import com.ssmssm.core.entity.BaseCriteria; +import com.ssmssm.core.entity.Page; -public class UserCriteria { +public class UserCriteria extends BaseCriteria { /** * This field was generated by MyBatis Generator. This field corresponds to the database table t_auth_user * @mbggenerated diff --git a/src/main/java/com/ssmssm/entity/system/UserKey.java b/src/main/java/com/ssmssm/entity/system/UserKey.java index 0569533..a30a9ff 100644 --- a/src/main/java/com/ssmssm/entity/system/UserKey.java +++ b/src/main/java/com/ssmssm/entity/system/UserKey.java @@ -1,6 +1,6 @@ package com.ssmssm.entity.system; -import com.ssmssm.entity.BaseEntity; +import com.ssmssm.core.entity.BaseEntity; import java.io.Serializable; diff --git a/src/main/java/com/ssmssm/entity/system/UserRoleCriteria.java b/src/main/java/com/ssmssm/entity/system/UserRoleCriteria.java index 6ec6e35..95ee0f0 100644 --- a/src/main/java/com/ssmssm/entity/system/UserRoleCriteria.java +++ b/src/main/java/com/ssmssm/entity/system/UserRoleCriteria.java @@ -4,9 +4,10 @@ import java.util.Date; import java.util.List; -import com.ssmssm.entity.Page; +import com.ssmssm.core.entity.BaseCriteria; +import com.ssmssm.core.entity.Page; -public class UserRoleCriteria { +public class UserRoleCriteria extends BaseCriteria { /** * This field was generated by MyBatis Generator. This field corresponds to the database table t_auth_user_role * @mbggenerated diff --git a/src/main/java/com/ssmssm/entity/system/UserRoleKey.java b/src/main/java/com/ssmssm/entity/system/UserRoleKey.java index 8e71004..eb35b56 100644 --- a/src/main/java/com/ssmssm/entity/system/UserRoleKey.java +++ b/src/main/java/com/ssmssm/entity/system/UserRoleKey.java @@ -1,6 +1,6 @@ package com.ssmssm.entity.system; -import com.ssmssm.entity.BaseEntity; +import com.ssmssm.core.entity.BaseEntity; import java.io.Serializable; diff --git a/src/main/java/com/ssmssm/service/system/UserService.java b/src/main/java/com/ssmssm/service/system/UserService.java index 60bd9d8..5740f99 100644 --- a/src/main/java/com/ssmssm/service/system/UserService.java +++ b/src/main/java/com/ssmssm/service/system/UserService.java @@ -1,82 +1,98 @@ package com.ssmssm.service.system; -import java.util.HashMap; import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import com.google.code.ssm.api.InvalidateAssignCache; -import com.google.code.ssm.api.ParameterValueKeyProvider; -import com.google.code.ssm.api.ReadThroughSingleCache; -import com.google.code.ssm.api.format.Serialization; -import com.google.code.ssm.api.format.SerializationType; +import com.ssmssm.core.service.BaseService; import com.ssmssm.core.utils.ComConst; +import com.ssmssm.core.utils.EncodeUtils; import com.ssmssm.dao.system.UserMapper; -import com.ssmssm.entity.Page; import com.ssmssm.entity.system.User; import com.ssmssm.entity.system.UserCriteria; -import com.ssmssm.entity.system.UserKey; @Service("UserService") -public class UserService { +public class UserService extends BaseService { @Autowired private UserMapper userMapper; + @Autowired + public void setMapper(UserMapper dao) { + super.setMapper(dao); + } + /** * 检索所有的用户 + * * @param start * @param length * @return */ - @Serialization(SerializationType.JSON) - // @ReadThroughAssignCache(assignedKey = "userServicefindAll", namespace = "system", expiration = 3000) - @ReadThroughSingleCache(namespace = "system.userList", expiration = 3000) - public Map getUserListPagination(@ParameterValueKeyProvider(order = 0) - final Integer start, @ParameterValueKeyProvider(order = 1) - final Integer length) { - System.err.println("没有缓存命中"); - Map resultMap = new HashMap(); + // @Serialization(SerializationType.JSON) + // @ReadThroughSingleCache(namespace = "system.userList", expiration = 3000) + // public Map getUserListPagination(@ParameterValueKeyProvider(order = 0) + // final Integer start, @ParameterValueKeyProvider(order = 1) + // final Integer length) { + public Map getUserListPagination(Integer start, Integer length) { UserCriteria userCriteria = new UserCriteria(); userCriteria.createCriteria().andDelFlgEqualTo(ComConst.DEL_FLG_0); - userCriteria.setPage(new Page(start, length)); - int cnt = userMapper.countByExample(userCriteria); - resultMap.put("recordsTotal", cnt); - resultMap.put("recordsFiltered", cnt); - resultMap.put("data", userMapper.selectByExample(userCriteria)); - return resultMap; + return super.selectByExamplePagination(start, length, userCriteria); } + /** + * 新增用户 + * + * @param user + * @return + */ @Transactional - @InvalidateAssignCache(namespace = "system.userList", assignedKey = "0/50") + // @InvalidateAssignCache(namespace = "system.userList", assignedKey = "0/50") public Map insertUser(User user) { - Map resultMap = new HashMap(); - Integer cnt = userMapper.insert(user); - if (cnt == 1) { - resultMap.put(ComConst.RESULT_CODE, ComConst.RESULT_CODE_SUCCESS); - } else { - resultMap.put(ComConst.RESULT_CODE, ComConst.RESULT_CODE_FAILD_9); - } - return resultMap; + user.setUserPsw(EncodeUtils.MD5(user.getUserPsw(), user.getUserName())); + return super.insert(user); } /** + * 编辑用户 * - * @param userId + * @param user * @return */ + @Transactional + public Map updateUser(User user) { + user.setUserPsw(EncodeUtils.MD5(user.getUserPsw(), user.getUserName())); + return super.updateByPrimaryKey(user); + } - @Serialization(SerializationType.JSON) - @ReadThroughSingleCache(namespace = "system", expiration = 3000) - public User findById(@ParameterValueKeyProvider - final String userId) { - System.err.println("没有缓存命中"); - UserKey key = new UserKey(); - key.setId(userId); - User user = userMapper.selectByPrimaryKey(key); - - return user; + /** + * 删除用户 + * + * @param user + * @return + */ + @Transactional + public Map deleteUser(User user) { + return super.deleteByPrimaryKey(user); } + + // /** + // * + // * @param userId + // * @return + // */ + // + // @Serialization(SerializationType.JSON) + // @ReadThroughSingleCache(namespace = "system", expiration = 3000) + // public User findById(@ParameterValueKeyProvider + // final String userId) { + // System.err.println("没有缓存命中"); + // UserKey key = new UserKey(); + // key.setId(userId); + // User user = userMapper.selectByPrimaryKey(key); + // + // return user; + // } } diff --git a/src/main/java/com/ssmssm/view/system/UserController.java b/src/main/java/com/ssmssm/view/system/UserController.java index 7ef17d5..d3d9287 100644 --- a/src/main/java/com/ssmssm/view/system/UserController.java +++ b/src/main/java/com/ssmssm/view/system/UserController.java @@ -1,7 +1,5 @@ package com.ssmssm.view.system; -import java.io.IOException; -import java.util.HashMap; import java.util.List; import java.util.Map; @@ -12,9 +10,6 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.ssmssm.core.utils.ComConst; import com.ssmssm.core.view.BaseController; import com.ssmssm.entity.system.CommonCode; import com.ssmssm.entity.system.User; @@ -52,15 +47,32 @@ public String index() { * 新增用户 * * @return - * @throws IOException - * @throws JsonMappingException - * @throws JsonParseException */ @RequestMapping(value = "/user/insertUser", method = RequestMethod.POST) public @ResponseBody Map insertUser(User user){ return userService.insertUser(user); } + /*** + * 编辑用户 + * + * @return + */ + @RequestMapping(value = "/user/updateUser", method = RequestMethod.POST) + public @ResponseBody Map updateUser(User user){ + return userService.updateUser(user); + } + + /*** + * 删除用户 + * + * @return + */ + @RequestMapping(value = "/user/deleteUser", method = RequestMethod.POST) + public @ResponseBody Map deleteUser(User user){ + return userService.deleteUser(user); + } + @RequestMapping(value = "/user/getUserTypeList", method = RequestMethod.GET) public @ResponseBody List getUserTypeList(Integer userType) { // request = ((ServletRequestAttributes) RequestContextHolder diff --git a/src/main/java/org/mybatis/generator/plugins/PostgreSQLPaginationPlugin.java b/src/main/java/org/mybatis/generator/plugins/PostgreSQLPaginationPlugin.java index 3dcaade..ee3db89 100644 --- a/src/main/java/org/mybatis/generator/plugins/PostgreSQLPaginationPlugin.java +++ b/src/main/java/org/mybatis/generator/plugins/PostgreSQLPaginationPlugin.java @@ -27,7 +27,7 @@ public class PostgreSQLPaginationPlugin extends PluginAdapter { /** * Page类所在的类路径:其中Page类中一定要有begin和end属性(即:开始记录位置和结束记录位置) */ - public static final String pageClassPath = "com.ssmssm.entity.Page"; + public static final String pageClassPath = "com.ssmssm.core.entity.Page"; @Override public boolean modelExampleClassGenerated(TopLevelClass topLevelClass, diff --git a/src/main/resources/mybatis/generatorConfig.xml b/src/main/resources/mybatis/generatorConfig.xml index 5c85db5..6ff9859 100644 --- a/src/main/resources/mybatis/generatorConfig.xml +++ b/src/main/resources/mybatis/generatorConfig.xml @@ -36,7 +36,7 @@ - + diff --git a/src/main/webapp/WEB-INF/res/js/common/comconst.js b/src/main/webapp/WEB-INF/res/js/common/comconst.js index 2eabee8..ea8f7d2 100644 --- a/src/main/webapp/WEB-INF/res/js/common/comconst.js +++ b/src/main/webapp/WEB-INF/res/js/common/comconst.js @@ -2,4 +2,22 @@ var RESULT_CODE_SUCCESS = "0"; /** 返回值0:Exception发生 */ -var RESULT_CODE_FAILD_9 = "9"; \ No newline at end of file +var RESULT_CODE_FAILD_9 = "9"; + +/** 操作模式(I:登录) */ +var OPERATE_MODE_I = "I"; + +/** 操作模式(U:更新) */ +var OPERATE_MODE_U = "U"; + +/** 操作模式(D:删除) */ +var OPERATE_MODE_D = "D"; + +/** 操作模式(I:登录) */ +var OPERATE_MODENAME_I = "新增"; + +/** 操作模式(U:更新) */ +var OPERATE_MODENAME_U = "编辑"; + +/** 操作模式(D:删除) */ +var OPERATE_MODENAME_D = "删除"; \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/res/js/common/datatablesInit.js b/src/main/webapp/WEB-INF/res/js/common/datatablesInit.js index ddda15f..7272036 100644 --- a/src/main/webapp/WEB-INF/res/js/common/datatablesInit.js +++ b/src/main/webapp/WEB-INF/res/js/common/datatablesInit.js @@ -46,7 +46,7 @@ function datatablesInit() { "dom": "<'row'<'col-xs-2'l><'#mytool.col-xs-4'><'col-xs-6'f>r>" + "t" + "<'row'<'col-xs-6'i><'col-xs-6'p>>", initComplete: function () { if (btnAdd) { - $("#mytool").append(''); + $("#mytool").append(''); $("#btnAdd").on("click", funAdd); } lock = false; diff --git a/src/main/webapp/WEB-INF/res/js/system/user_index.js b/src/main/webapp/WEB-INF/res/js/system/user_index.js index 8648a17..67810cc 100644 --- a/src/main/webapp/WEB-INF/res/js/system/user_index.js +++ b/src/main/webapp/WEB-INF/res/js/system/user_index.js @@ -28,10 +28,10 @@ function initDataTables() { var staticResop = ""; staticResop = staticResop + "" + + row["id"] + "\')\">" + OPERATE_MODENAME_U + "" staticResop = staticResop - + "" + + "" return staticResop; }, "targets" : 6 @@ -55,8 +55,10 @@ function initDataTables() { * 添加按钮 **/ function funAdd() { - $("#hdnUserId").val(""); - $("#hdnMode").val("I"); + $("#id").val(""); + $("#hdnMode").val(OPERATE_MODE_I); + $("#myModalLabel")[0].innerHTML = OPERATE_MODENAME_I; + initDisable(); $("#myModal").modal("show"); }; @@ -64,8 +66,10 @@ function funAdd() { * 编辑按钮 **/ function funUpd(id) { - $("#hdnUserId").val(id); - $("#hdnMode").val("U"); + $("#id").val(id); + $("#hdnMode").val(OPERATE_MODE_U); + $("#myModalLabel")[0].innerHTML = OPERATE_MODENAME_U; + initDisable(); $("#myModal").modal("show"); }; @@ -73,8 +77,10 @@ function funUpd(id) { * 删除按钮 **/ function funDel(id) { - $("#hdnUserId").val(id); - $("#hdnMode").val("D"); + $("#id").val(id); + $("#hdnMode").val(OPERATE_MODE_D); + $("#myModalLabel")[0].innerHTML = OPERATE_MODENAME_D; + initDisable(); $("#myModal").modal("show"); }; @@ -82,14 +88,51 @@ function funDel(id) { * 保存按钮 **/ function funSave() { - ajaxPost('/user/insertUser', $("#subform").serialize(), function(data, + var url; + if (OPERATE_MODE_I == $("#hdnMode").val()) { + url = "/user/insertUser"; + } else if (OPERATE_MODE_U == $("#hdnMode").val()) { + url = "/user/updateUser"; + } else if (OPERATE_MODE_D == $("#hdnMode").val()) { + url = "/user/deleteUser"; + } + ajaxPost(url, $("#subform").serialize(), function(data, status) { funCallback(data, status); }); }; function funCallback(data, status) { if (data.RESULT_CODE == RESULT_CODE_SUCCESS) { + initModel(); $("#myModal").modal("hide"); $("#mytable").dataTable().fnReloadAjax(); } }; + +//删除模式下,控件不可用 +function initDisable() { + if (OPERATE_MODE_D == $("#hdnMode").val()) { + $("#subform").find(":input").each(function() { + if ($(this).attr("type") != "hidden" && $(this).attr("type") != "button") { + $(this).attr("disabled", "disabled"); + } + }); + $("#btnSave").attr("class", "btn btn-danger pull-right"); + } else { + $("#subform").find(":input").each(function() { + $(this).removeAttr("disabled"); + }); + if (OPERATE_MODE_I == $("#hdnMode").val()) { + $("#btnSave").attr("class", "btn btn-success pull-right"); + } else { + $("#btnSave").attr("class", "btn btn-primary pull-right"); + } + } + $("#btnSave")[0].innerHTML = $("#myModalLabel")[0].innerHTML; +} +// 初始化model +function initModel() { + $("#subform").find("*").each(function() { + $(this).val(""); + }); +} \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/views/user/index.jsp b/src/main/webapp/WEB-INF/views/user/index.jsp index c84b660..96f17dd 100644 --- a/src/main/webapp/WEB-INF/views/user/index.jsp +++ b/src/main/webapp/WEB-INF/views/user/index.jsp @@ -171,8 +171,8 @@