Bläddra i källkod

Merge branch 'dev' of LiTaohong/jkzl-starter2.0 into dev

LiTaohong 6 år sedan
förälder
incheckning
8266da701d

+ 36 - 0
.idea/inspectionProfiles/Project_Default.xml

@ -0,0 +1,36 @@
<component name="InspectionProjectProfileManager">
  <profile version="1.0">
    <option name="myName" value="Project Default" />
    <inspection_tool class="JavaDoc" enabled="true" level="WARNING" enabled_by_default="true">
      <option name="TOP_LEVEL_CLASS_OPTIONS">
        <value>
          <option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
          <option name="REQUIRED_TAGS" value="" />
        </value>
      </option>
      <option name="INNER_CLASS_OPTIONS">
        <value>
          <option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
          <option name="REQUIRED_TAGS" value="" />
        </value>
      </option>
      <option name="METHOD_OPTIONS">
        <value>
          <option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
          <option name="REQUIRED_TAGS" value="@return@param@throws or @exception" />
        </value>
      </option>
      <option name="FIELD_OPTIONS">
        <value>
          <option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
          <option name="REQUIRED_TAGS" value="" />
        </value>
      </option>
      <option name="IGNORE_DEPRECATED" value="false" />
      <option name="IGNORE_JAVADOC_PERIOD" value="true" />
      <option name="IGNORE_DUPLICATED_THROWS" value="false" />
      <option name="IGNORE_POINT_TO_ITSELF" value="false" />
      <option name="myAdditionalJavadocTags" value="date" />
    </inspection_tool>
  </profile>
</component>

+ 6 - 0
.idea/vcs.xml

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="VcsDirectoryMappings">
    <mapping directory="" vcs="Git" />
  </component>
</project>

+ 46 - 0
mysql-starter/src/main/java/com/yihu/mysql/query/BaseJpaService.java

@ -5,6 +5,8 @@ import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.repository.CrudRepository;
@ -312,4 +314,48 @@ public abstract class BaseJpaService<T, R extends CrudRepository> {
        }
        return buffer.toString();
    }
    /**
     * 排序条件 第一个字符为 + 表示升序,第一个字符为 - 表示减序,不包含 + 或者 - 默认升序
     * @param sorts
     * @return
     */
    public Sort createSort(String sorts){
        Sort sort = null;
        if (!org.springframework.util.StringUtils.isEmpty(sorts)) {
            // 默认升序
            if(sorts.contains("-")){
                sort = new Sort(Sort.Direction.DESC,sorts.substring(1,sorts.length()).split(","));
            }else if(sorts.contains("+")){
                sort = new Sort(Sort.Direction.ASC,sorts.substring(1,sorts.length()).split(","));
            }else{
                sort = new Sort(Sort.Direction.ASC,sorts.split(","));
            }
        }
        return sort;
    }
    /**
     * 创建分页对象
     * @param page
     * @param size
     * @param sorts
     * @return
     */
    public Pageable creatPage(Integer page, Integer size, String sorts){
        PageRequest pageRequest = null;
        if(null == page || page <= 0){
            page = defaultPage;
        }
        if(null == size || size <= 0){
            size = defaultSize;
        }
        if(!org.apache.commons.lang3.StringUtils.isEmpty(sorts)){
            pageRequest = new PageRequest(page,size,createSort(sorts));
        }else{
            pageRequest = new PageRequest(page,size);
        }
        return pageRequest;
    }
}