Skip to content

Commit

Permalink
修改表格为ajax表格
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangkaitao committed Mar 16, 2013
1 parent bd85ac3 commit 8272927
Show file tree
Hide file tree
Showing 157 changed files with 4,439 additions and 2,380 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/**
* Copyright (c) 2005-2012 https://github.com/zhangkaitao
*
* Licensed under the Apache License, Version 2.0 (the "License");
*/
package com.sishuok.es.common.exception;

import com.sishuok.es.common.utils.MessageUtils;
import com.sishuok.es.common.utils.SpringUtils;
import org.springframework.context.MessageSource;
import org.springframework.util.StringUtils;

import java.util.Locale;

/**
* 基础异常
* <p>User: Zhang Kaitao
* <p>Date: 13-3-11 下午8:19
* <p>Version: 1.0
*/
public class BaseException extends RuntimeException {

//所属模块
private String module;

/**
* 错误码
*/
private String code;

/**
* 错误码对应的参数
*/
private Object[] args;

/**
* 错误消息
*/
private String defaultMessage;


public BaseException(String module, String code, Object[] args, String defaultMessage) {
this.module = module;
this.code = code;
this.args = args;
this.defaultMessage = defaultMessage;
}

public BaseException(String module, String code, Object[] args) {
this(module, code, args, null);
}

public BaseException(String module, String defaultMessage) {
this(module, null, null, defaultMessage);
}

public BaseException(String code, Object[] args) {
this(null, code, args, null);
}

public BaseException(String defaultMessage) {
this(null, null, null, defaultMessage);
}

@Override
public String getMessage() {
String message = null;
if(StringUtils.hasLength(code)) {
message = MessageUtils.message(code, args);
}
if(message == null) {
message = defaultMessage;
}
return message;
}


public String getModule() {
return module;
}

public String getCode() {
return code;
}

public Object[] getArgs() {
return args;
}

public String getDefaultMessage() {
return defaultMessage;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static interface Status {
* 审核状态
*/
public static enum AuditStatus implements Status {
fail("审核失败"), success("审核成功");
waiting("等待审核"),fail("审核失败"), success("审核成功");
private final String info;

private AuditStatus(String info) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,6 @@ public M save(M m) {
return super.save(m);
}

@Override
public M saveAndFlush(M m) {
if (m.getWeight() == null) {
m.setWeight(findNextWeight());
}
return super.save(m);
}

/**
* 按照降序进行移动
* 把{fromId}移动到{}toId}之后
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,6 @@ public M save(M m) {
return super.save(m);
}

@Override
public M saveAndFlush(M m) {
if(m.getWeight() == null) {
m.setWeight(nextWeight(m.getParentId()));
}
return super.saveAndFlush(m);
}

@Transactional
public void deleteSelfAndChild(M m) {
baseRepositoryImpl.batchUpdate(DELETE_CHILDREN_QL, m.getId(), m.makeSelfAsNewParentIds());
Expand All @@ -81,7 +73,7 @@ public void appendChild(M parent, M child) {
}

public int nextWeight(ID id) {
return baseRepositoryImpl.findOne(FIND_NEXT_WEIGHT_QL, id);
return baseRepositoryImpl.<Integer>findOne(FIND_NEXT_WEIGHT_QL, id);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ public M save(M m) {
}

public M saveAndFlush(M m) {
return baseRepository.saveAndFlush(m);
m = save(m);
baseRepository.flush();
return m;
}

/**
Expand Down Expand Up @@ -248,4 +250,5 @@ public Long count(Searchable searchable) {
return baseRepository.count(searchable.getSpecifications(entityClass));
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
*/
public class MessageUtils {

private static MessageSource messageSource;

/**
* 根据消息键和参数 获取消息
* 委托给spring messageSource
Expand All @@ -22,6 +24,9 @@ public class MessageUtils {
* @return
*/
public static String message(String code, Object... args) {
return SpringUtils.getBean(MessageSource.class).getMessage(code, args, null);
if(messageSource == null) {
messageSource = SpringUtils.getBean(MessageSource.class);
}
return messageSource.getMessage(code, args, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer m
Map<String, String[]> pageableMap = getPrefixParameterMap(pageableNamePrefix, webRequest, true);
Map<String, String[]> sortMap = getPrefixParameterMap(sortNamePrefix, webRequest, false);

Sort sort = getSort(sortNamePrefix, sortMap, defaultPageRequest);
Sort sort = getSort(sortNamePrefix, sortMap, defaultPageRequest, webRequest);
if (pageableMap.size() == 0) {
return new PageRequest(defaultPageRequest.getPageNumber(), defaultPageRequest.getPageSize(), sort == null ? defaultPageRequest.getSort() : sort);
}
Expand All @@ -153,7 +153,7 @@ public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer m

}

private Sort getSort(String sortNamePrefix, Map<String, String[]> sortMap, Pageable defaultPageRequest) {
private Sort getSort(String sortNamePrefix, Map<String, String[]> sortMap, Pageable defaultPageRequest, NativeWebRequest webRequest) {
Sort sort = null;
List<OrderedSort> orderedSortList = Lists.newArrayList();
for (String name : sortMap.keySet()) {
Expand All @@ -177,6 +177,13 @@ private Sort getSort(String sortNamePrefix, Map<String, String[]> sortMap, Pagea
orderedSortList.add(new OrderedSort(property, direction, order));
}

//jq grid sort
String sortProperty = webRequest.getParameter("sidx");
String direction = webRequest.getParameter("sord");
if(StringUtils.hasLength(sortProperty)) {
orderedSortList.add(new OrderedSort(sortProperty, Sort.Direction.fromString(direction), 0));
}

Collections.sort(orderedSortList);
for(OrderedSort orderedSort : orderedSortList) {
Sort newSort = new Sort(orderedSort.direction, orderedSort.property);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
import com.sishuok.es.common.entity.BaseEntity;
import com.sishuok.es.common.entity.search.Searchable;
import com.sishuok.es.common.service.BaseService;
import com.sishuok.es.common.utils.ReflectUtils;
import com.sishuok.es.common.web.bind.annotation.PageableDefaults;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.ui.Model;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
Expand Down Expand Up @@ -45,12 +43,27 @@ protected void setCommonData(Model model) {
}

@RequestMapping(method = RequestMethod.GET)
@PageableDefaults(value = 10, sort = "id=desc")
@PageableDefaults(sort = "id=desc")
public String list(Searchable searchable, Model model) {
model.addAttribute("page", baseService.findAll(searchable));
return getViewPrefix() + "/list";
}

/**
* 仅返回表格数据
* @param searchable
* @param model
* @return
*/
@RequestMapping(method = RequestMethod.GET, headers = "table=true")
@PageableDefaults(sort = "id=desc")
public String listTable(Searchable searchable, Model model) {
list(searchable, model);
return getViewPrefix() + "/listTable";
}



@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public String view(Model model, @PathVariable("id") M m) {
setCommonData(model);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* Licensed under the Apache License, Version 2.0 (the "License");
*/
package com.sishuok.es.common.web.filter;
package com.sishuok.es.common.web.interceptor;

import com.sishuok.es.common.Constants;
import org.springframework.context.ApplicationContext;
Expand Down Expand Up @@ -44,12 +44,18 @@
*/
public class SetCommonDataInterceptor extends HandlerInterceptorAdapter {

private String[] excludeParameterPattern = new String[] {
private static final String[] DEFAULT_EXCLUDE_PARAMETER_PATTERN = new String[] {
"\\&\\w*page.pn=\\d+",
"\\?\\w*page.pn=\\d+",
"\\&\\w*page.size=\\d+"
};

private String[] excludeParameterPattern = DEFAULT_EXCLUDE_PARAMETER_PATTERN;

public void setExcludeParameterPattern(String[] excludeParameterPattern) {
this.excludeParameterPattern = excludeParameterPattern;
}

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

Expand Down
1 change: 1 addition & 0 deletions common/src/main/resources/spring-common.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@

<context:component-scan base-package="com.sishuok.es.common.utils"></context:component-scan>


</beans>
8 changes: 4 additions & 4 deletions common/src/test/resources/spring-test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd">

<context:component-scan base-package="com.sishuok.es.common.service"></context:component-scan>

<bean id="conversion-service" class="org.springframework.format.support.FormattingConversionServiceFactoryBean"/>

<jdbc:embedded-database id="dataSource" type="H2"/>

Expand Down Expand Up @@ -43,7 +46,7 @@
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>

<tx:annotation-driven transaction-manager="transactionManager"/>
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>

<jpa:repositories
base-package="com.sishuok.es.common.repository"
Expand All @@ -52,8 +55,5 @@
transaction-manager-ref="transactionManager">
</jpa:repositories>

<context:component-scan base-package="com.sishuok.es.common.service"></context:component-scan>

<bean id="conversion-service" class="org.springframework.format.support.FormattingConversionServiceFactoryBean"/>

</beans>
Loading

0 comments on commit 8272927

Please sign in to comment.