Skip to content

Commit

Permalink
user insert(datatables refresh bug)
Browse files Browse the repository at this point in the history
  • Loading branch information
westxixia committed Dec 31, 2015
1 parent 793e343 commit 9075969
Show file tree
Hide file tree
Showing 16 changed files with 322 additions and 179 deletions.
9 changes: 8 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,14 @@
<groupId>com.google.code.simple-spring-memcached</groupId>
<artifactId>xmemcached-provider</artifactId>
<version>3.6.0</version>
</dependency>
</dependency>

<!-- validation -->
<!-- <dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version>
</dependency> -->
</dependencies>
<build>
<plugins>
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/com/ssmssm/core/logger/LoggerInterceptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.opensymphony.xwork2.ActionSupport;
import com.ssmssm.core.utils.BeanUtils;
import com.ssmssm.core.utils.ComConst;
import com.ssmssm.core.utils.WebUtilsEx;
import com.ssmssm.core.view.BaseController;
import com.ssmssm.core.view.listener.StartupListener;
import com.ssmssm.entity.system.BusinessLogs;
import com.ssmssm.entity.system.User;

Expand Down Expand Up @@ -182,10 +180,6 @@ else if (classLogger != null) {

public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView mav)
throws Exception {
if (mav == null) {
mav = new ModelAndView();
}
mav.addObject("commonCodeList", BeanUtils.toJson(StartupListener.commonCodeList));
if (isLogger) {
// System.out.println("This is postHandle!");
}
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/ssmssm/core/utils/ComConst.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ public static ComConst getSingleton() {
/** 删除区分(R:资源) */
public static final String DEL_FLG_R = "R";

/** 返回值 */
public static final String RESULT_CODE = "RESULT_CODE";

/** 返回值0:正常 */
public static final String RESULT_CODE_SUCCESS = "0";

/** 返回值0:Exception发生 */
public static final String RESULT_CODE_FAILD_9 = "9";

/** 性别(100001) */
public static final Integer SEX_ID = 100001;

Expand Down
20 changes: 19 additions & 1 deletion src/main/java/com/ssmssm/core/view/BaseController.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,43 @@
package com.ssmssm.core.view;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

public abstract class BaseController {
import com.fasterxml.jackson.core.JsonProcessingException;
import com.ssmssm.core.utils.BeanUtils;
import com.ssmssm.core.view.listener.StartupListener;

public abstract class BaseController extends AbstractController {

@Autowired
protected HttpServletRequest request;

/** 存储操作日志内容. */
private StringBuilder logger;

@ModelAttribute("commonCodeList")
public String getCommonCodeList() throws JsonProcessingException {
return BeanUtils.toJson(StartupListener.commonCodeList);
}

@ExceptionHandler
public void exception(HttpServletRequest request, Exception e) {
//添加自己的异常处理逻辑,如日志记录
request.setAttribute("exceptionMessage", e.getMessage());
appendLogger(e.getMessage());
}

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
throws Exception {
return null;
}

/**
* 将日志重置为指定的文本.
Expand Down
29 changes: 28 additions & 1 deletion src/main/java/com/ssmssm/service/system/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

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;
Expand All @@ -23,9 +25,15 @@ public class UserService {
@Autowired
private UserMapper userMapper;

/**
* 检索所有的用户
* @param start
* @param length
* @return
*/
@Serialization(SerializationType.JSON)
// @ReadThroughAssignCache(assignedKey = "userServicefindAll", namespace = "system", expiration = 3000)
@ReadThroughSingleCache(namespace = "system", expiration = 3000)
@ReadThroughSingleCache(namespace = "system.userList", expiration = 3000)
public Map<String, Object> getUserListPagination(@ParameterValueKeyProvider(order = 0)
final Integer start, @ParameterValueKeyProvider(order = 1)
final Integer length) {
Expand All @@ -41,6 +49,25 @@ public Map<String, Object> getUserListPagination(@ParameterValueKeyProvider(orde
return resultMap;
}

@Transactional
@InvalidateAssignCache(namespace = "system.userList", assignedKey = "0/50")
public Map<String, String> insertUser(User user) {
Map<String, String> resultMap = new HashMap<String, String>();
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;
}

/**
*
* @param userId
* @return
*/

@Serialization(SerializationType.JSON)
@ReadThroughSingleCache(namespace = "system", expiration = 3000)
public User findById(@ParameterValueKeyProvider
Expand Down
21 changes: 20 additions & 1 deletion src/main/java/com/ssmssm/view/system/UserController.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.ssmssm.view.system;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

Expand All @@ -10,8 +12,12 @@
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;
import com.ssmssm.service.system.CommonCodeService;
import com.ssmssm.service.system.UserService;

Expand Down Expand Up @@ -42,7 +48,20 @@ public String index() {
return resultMap;
}

@RequestMapping(value = "/user/getUserTypeList", method = RequestMethod.POST)
/***
* 新增用户
*
* @return
* @throws IOException
* @throws JsonMappingException
* @throws JsonParseException
*/
@RequestMapping(value = "/user/insertUser", method = RequestMethod.POST)
public @ResponseBody Map<String, String> insertUser(User user){
return userService.insertUser(user);
}

@RequestMapping(value = "/user/getUserTypeList", method = RequestMethod.GET)
public @ResponseBody List<CommonCode> getUserTypeList(Integer userType) {
// request = ((ServletRequestAttributes) RequestContextHolder
// .getRequestAttributes()).getRequest();
Expand Down
25 changes: 24 additions & 1 deletion src/main/resources/springweb/spring-servlet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,29 @@
</mvc:interceptors>

<mvc:resources mapping="/res/**" location="/WEB-INF/res/"/>
<mvc:default-servlet-handler />
<mvc:default-servlet-handler />

<!-- 全局异常配置 start -->
<beans:bean id="exceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<beans:property name="exceptionMappings">
<beans:props>
<beans:prop key="java.lang.Exception">errors/error</beans:prop>
<beans:prop key="java.lang.Throwable">errors/err</beans:prop>
</beans:props>
</beans:property>
<beans:property name="statusCodes">
<beans:props>
<beans:prop key="errors/error">500</beans:prop>
<beans:prop key="errors/404">404</beans:prop>
</beans:props>
</beans:property>
<!-- 设置日志输出级别,不定义则默认不输出警告等错误日志信息 -->
<beans:property name="warnLogCategory" value="WARN"></beans:property>
<!-- 默认错误页面,当找不到上面mappings中指定的异常对应视图时,使用本默认配置 -->
<beans:property name="defaultErrorView" value="errors/error"></beans:property>
<!-- 默认HTTP状态码 -->
<beans:property name="defaultStatusCode" value="500"></beans:property>
</beans:bean>
<!-- 全局异常配置 end -->

</beans:beans>
23 changes: 13 additions & 10 deletions src/main/webapp/WEB-INF/layouts/default.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
<script>
$.widget.bridge('uibutton', $.ui.button);
contextPath = '${ctx}';
var headers = {};
headers['X-CSRF-TOKEN'] = ($("meta[name=_csrf]")).attr("content");
</script>
<!-- Bootstrap 3.3.5 -->
<script src="${ctx}/res/AdminLTE/bootstrap/js/bootstrap.min.js"></script>
Expand Down Expand Up @@ -60,8 +62,6 @@
src="${ctx}/res/AdminLTE/plugins/datatables/jquery.dataTables.min.js"></script>
<script
src="${ctx}/res/AdminLTE/plugins/datatables/dataTables.bootstrap.min.js"></script>
<script src="${ctx}/res/js/common/datatablesEx.js"></script>
<script src="${ctx}/res/js/common/datatablesInit.js"></script>
<!-- Slimscroll -->
<script
src="${ctx}/res/AdminLTE/plugins/slimScroll/jquery.slimscroll.min.js"></script>
Expand All @@ -74,17 +74,20 @@
<!-- AdminLTE for demo purposes -->
<script src="${ctx}/res/AdminLTE/dist/js/demo.js"></script>
<!-- InputMask -->
<script src="${ctx}/res/AdminLTE/plugins/input-mask/jquery.inputmask.js"></script>
<!-- <script src="${ctx}/res/AdminLTE/plugins/input-mask/jquery.inputmask.js"></script>
<script src="${ctx}/res/AdminLTE/plugins/input-mask/jquery.inputmask.date.extensions.js"></script>
<script src="${ctx}/res/AdminLTE/plugins/input-mask/jquery.inputmask.extensions.js"></script>
<script src="${ctx}/res/AdminLTE/plugins/input-mask/jquery.inputmask.extensions.js"></script> -->

<%-- ajax提交的工具类 --%>
<script src="${ctx}/res/js/common/ajaxPost.js"></script>
<%-- 共通定数类 --%>
<script src="${ctx}/res/js/common/comconst.js"></script>
<%-- datatables的工具类 --%>
<script src="${ctx}/res/js/common/datatablesEx.js"></script>
<script src="${ctx}/res/js/common/datatablesInit.js"></script>
<script src="${ctx}/res/js/common/fnReloadAjax.js"></script>
<%-- 打开弹出窗口的工具类 --%>
<script src="${ctx}/res/js/common/OpenWinUtil.js"></script>
<%-- jqGrid-4.6.0 核心 JavaScript 文件 --%>
<!-- <script src="${ctx}/res/js/jqGrid-4.6.0/jquery.jqGrid.min.js"></script>
<script src="${ctx}/res/js/common/jqGridInit.js"></script>
<script src="${ctx}/res/js/common/customDropDown.js"></script>
<script src="${ctx}/res/js/common/ajaxPost.js"></script> -->
<!-- <script src="${ctx}/res/js/common/OpenWinUtil.js"></script> -->
<script type="text/javascript">
function logout() {
if (confirm('确定要退出吗?')) {
Expand Down
12 changes: 9 additions & 3 deletions src/main/webapp/WEB-INF/res/js/common/ajaxPost.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
function ajaxPost(url, dataParam, callback) {
// 防止多次提交
if (lock) {
return;
}
lock = true;
var retData = null;
// var headers = {};
// headers['X-CSRF-TOKEN'] = ($("meta[name=_csrf]")).attr("content");
$.ajax({
type : "post",
url : url,
url : contextPath + url,
headers: headers,
data : dataParam,
dataType : "json",
//contentType : "application/json;charset=utf-8",
success : function(data, status) {
lock = false;
retData = data;
if (callback != null && callback != "" && callback != undefined)
callback(data, status);
},
error : function(err, err1, err2) {
lock = false;
alert("调用方法发生异常:" + JSON.stringify(err) + "err1"
+ JSON.stringify(err1) + "err2:" + JSON.stringify(err2));
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/webapp/WEB-INF/res/js/common/comconst.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/** 返回值0:正常 */
var RESULT_CODE_SUCCESS = "0";

/** 返回值0:Exception发生 */
var RESULT_CODE_FAILD_9 = "9";
35 changes: 0 additions & 35 deletions src/main/webapp/WEB-INF/res/js/common/customDropDown.js

This file was deleted.

6 changes: 2 additions & 4 deletions src/main/webapp/WEB-INF/res/js/common/datatablesInit.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ function datatablesInit() {
return;
}
lock = true;
var headers = {};
headers['X-CSRF-TOKEN'] = ($("meta[name=_csrf]")).attr("content");
var t = $('#' + tableId).DataTable({
var mytable = $('#' + tableId).DataTable({
"ajax" : $.fn.dataTable.pipeline({
"url" : contextPath + paramUrl,
"type" : "POST",
Expand Down Expand Up @@ -55,7 +53,7 @@ function datatablesInit() {
}
});
// // 前台添加序号
// t.on('order.dt search.dt', function() {
// mytable.on('order.dt search.dt', function() {
// t.column(0, {
// "search" : 'applied',
// "order" : 'applied'
Expand Down
Loading

0 comments on commit 9075969

Please sign in to comment.