数据交换项目

parents
HELP.md
/target/
!.mvn/wrapper/maven-wrapper.jar
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
/build/
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.util.Properties;
public class MavenWrapperDownloader {
/**
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
*/
private static final String DEFAULT_DOWNLOAD_URL =
"https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar";
/**
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
* use instead of the default one.
*/
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
".mvn/wrapper/maven-wrapper.properties";
/**
* Path where the maven-wrapper.jar will be saved to.
*/
private static final String MAVEN_WRAPPER_JAR_PATH =
".mvn/wrapper/maven-wrapper.jar";
/**
* Name of the property which should be used to override the default download url for the wrapper.
*/
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
public static void main(String args[]) {
System.out.println("- Downloader started");
File baseDirectory = new File(args[0]);
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
// If the maven-wrapper.properties exists, read it and check if it contains a custom
// wrapperUrl parameter.
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
String url = DEFAULT_DOWNLOAD_URL;
if(mavenWrapperPropertyFile.exists()) {
FileInputStream mavenWrapperPropertyFileInputStream = null;
try {
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
Properties mavenWrapperProperties = new Properties();
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
} catch (IOException e) {
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
} finally {
try {
if(mavenWrapperPropertyFileInputStream != null) {
mavenWrapperPropertyFileInputStream.close();
}
} catch (IOException e) {
// Ignore ...
}
}
}
System.out.println("- Downloading from: : " + url);
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
if(!outputFile.getParentFile().exists()) {
if(!outputFile.getParentFile().mkdirs()) {
System.out.println(
"- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'");
}
}
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
try {
downloadFileFromURL(url, outputFile);
System.out.println("Done");
System.exit(0);
} catch (Throwable e) {
System.out.println("- Error downloading");
e.printStackTrace();
System.exit(1);
}
}
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
URL website = new URL(urlString);
ReadableByteChannel rbc;
rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream(destination);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
fos.close();
rbc.close();
}
}
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip
#!/bin/sh
# ----------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# ----------------------------------------------------------------------------
# ----------------------------------------------------------------------------
# Maven2 Start Up Batch script
#
# Required ENV vars:
# ------------------
# JAVA_HOME - location of a JDK home dir
#
# Optional ENV vars
# -----------------
# M2_HOME - location of maven2's installed home dir
# MAVEN_OPTS - parameters passed to the Java VM when running Maven
# e.g. to debug Maven itself, use
# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
# MAVEN_SKIP_RC - flag to disable loading of mavenrc files
# ----------------------------------------------------------------------------
if [ -z "$MAVEN_SKIP_RC" ] ; then
if [ -f /etc/mavenrc ] ; then
. /etc/mavenrc
fi
if [ -f "$HOME/.mavenrc" ] ; then
. "$HOME/.mavenrc"
fi
fi
# OS specific support. $var _must_ be set to either true or false.
cygwin=false;
darwin=false;
mingw=false
case "`uname`" in
CYGWIN*) cygwin=true ;;
MINGW*) mingw=true;;
Darwin*) darwin=true
# Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
# See https://developer.apple.com/library/mac/qa/qa1170/_index.html
if [ -z "$JAVA_HOME" ]; then
if [ -x "/usr/libexec/java_home" ]; then
export JAVA_HOME="`/usr/libexec/java_home`"
else
export JAVA_HOME="/Library/Java/Home"
fi
fi
;;
esac
if [ -z "$JAVA_HOME" ] ; then
if [ -r /etc/gentoo-release ] ; then
JAVA_HOME=`java-config --jre-home`
fi
fi
if [ -z "$M2_HOME" ] ; then
## resolve links - $0 may be a link to maven's home
PRG="$0"
# need this for relative symlinks
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG="`dirname "$PRG"`/$link"
fi
done
saveddir=`pwd`
M2_HOME=`dirname "$PRG"`/..
# make it fully qualified
M2_HOME=`cd "$M2_HOME" && pwd`
cd "$saveddir"
# echo Using m2 at $M2_HOME
fi
# For Cygwin, ensure paths are in UNIX format before anything is touched
if $cygwin ; then
[ -n "$M2_HOME" ] &&
M2_HOME=`cygpath --unix "$M2_HOME"`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
[ -n "$CLASSPATH" ] &&
CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
fi
# For Mingw, ensure paths are in UNIX format before anything is touched
if $mingw ; then
[ -n "$M2_HOME" ] &&
M2_HOME="`(cd "$M2_HOME"; pwd)`"
[ -n "$JAVA_HOME" ] &&
JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
# TODO classpath?
fi
if [ -z "$JAVA_HOME" ]; then
javaExecutable="`which javac`"
if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
# readlink(1) is not available as standard on Solaris 10.
readLink=`which readlink`
if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
if $darwin ; then
javaHome="`dirname \"$javaExecutable\"`"
javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
else
javaExecutable="`readlink -f \"$javaExecutable\"`"
fi
javaHome="`dirname \"$javaExecutable\"`"
javaHome=`expr "$javaHome" : '\(.*\)/bin'`
JAVA_HOME="$javaHome"
export JAVA_HOME
fi
fi
fi
if [ -z "$JAVACMD" ] ; then
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
else
JAVACMD="`which java`"
fi
fi
if [ ! -x "$JAVACMD" ] ; then
echo "Error: JAVA_HOME is not defined correctly." >&2
echo " We cannot execute $JAVACMD" >&2
exit 1
fi
if [ -z "$JAVA_HOME" ] ; then
echo "Warning: JAVA_HOME environment variable is not set."
fi
CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
# traverses directory structure from process work directory to filesystem root
# first directory with .mvn subdirectory is considered project base directory
find_maven_basedir() {
if [ -z "$1" ]
then
echo "Path not specified to find_maven_basedir"
return 1
fi
basedir="$1"
wdir="$1"
while [ "$wdir" != '/' ] ; do
if [ -d "$wdir"/.mvn ] ; then
basedir=$wdir
break
fi
# workaround for JBEAP-8937 (on Solaris 10/Sparc)
if [ -d "${wdir}" ]; then
wdir=`cd "$wdir/.."; pwd`
fi
# end of workaround
done
echo "${basedir}"
}
# concatenates all lines of a file
concat_lines() {
if [ -f "$1" ]; then
echo "$(tr -s '\n' ' ' < "$1")"
fi
}
BASE_DIR=`find_maven_basedir "$(pwd)"`
if [ -z "$BASE_DIR" ]; then
exit 1;
fi
##########################################################################################
# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
# This allows using the maven wrapper in projects that prohibit checking in binary data.
##########################################################################################
if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then
if [ "$MVNW_VERBOSE" = true ]; then
echo "Found .mvn/wrapper/maven-wrapper.jar"
fi
else
if [ "$MVNW_VERBOSE" = true ]; then
echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
fi
jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"
while IFS="=" read key value; do
case "$key" in (wrapperUrl) jarUrl="$value"; break ;;
esac
done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties"
if [ "$MVNW_VERBOSE" = true ]; then
echo "Downloading from: $jarUrl"
fi
wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar"
if command -v wget > /dev/null; then
if [ "$MVNW_VERBOSE" = true ]; then
echo "Found wget ... using wget"
fi
wget "$jarUrl" -O "$wrapperJarPath"
elif command -v curl > /dev/null; then
if [ "$MVNW_VERBOSE" = true ]; then
echo "Found curl ... using curl"
fi
curl -o "$wrapperJarPath" "$jarUrl"
else
if [ "$MVNW_VERBOSE" = true ]; then
echo "Falling back to using Java to download"
fi
javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
if [ -e "$javaClass" ]; then
if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
if [ "$MVNW_VERBOSE" = true ]; then
echo " - Compiling MavenWrapperDownloader.java ..."
fi
# Compiling the Java class
("$JAVA_HOME/bin/javac" "$javaClass")
fi
if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
# Running the downloader
if [ "$MVNW_VERBOSE" = true ]; then
echo " - Running MavenWrapperDownloader.java ..."
fi
("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR")
fi
fi
fi
fi
##########################################################################################
# End of extension
##########################################################################################
export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
if [ "$MVNW_VERBOSE" = true ]; then
echo $MAVEN_PROJECTBASEDIR
fi
MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
# For Cygwin, switch paths to Windows format before running java
if $cygwin; then
[ -n "$M2_HOME" ] &&
M2_HOME=`cygpath --path --windows "$M2_HOME"`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
[ -n "$CLASSPATH" ] &&
CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
[ -n "$MAVEN_PROJECTBASEDIR" ] &&
MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
fi
WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
exec "$JAVACMD" \
$MAVEN_OPTS \
-classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
"-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
@REM ----------------------------------------------------------------------------
@REM Licensed to the Apache Software Foundation (ASF) under one
@REM or more contributor license agreements. See the NOTICE file
@REM distributed with this work for additional information
@REM regarding copyright ownership. The ASF licenses this file
@REM to you under the Apache License, Version 2.0 (the
@REM "License"); you may not use this file except in compliance
@REM with the License. You may obtain a copy of the License at
@REM
@REM http://www.apache.org/licenses/LICENSE-2.0
@REM
@REM Unless required by applicable law or agreed to in writing,
@REM software distributed under the License is distributed on an
@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@REM KIND, either express or implied. See the License for the
@REM specific language governing permissions and limitations
@REM under the License.
@REM ----------------------------------------------------------------------------
@REM ----------------------------------------------------------------------------
@REM Maven2 Start Up Batch script
@REM
@REM Required ENV vars:
@REM JAVA_HOME - location of a JDK home dir
@REM
@REM Optional ENV vars
@REM M2_HOME - location of maven2's installed home dir
@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
@REM e.g. to debug Maven itself, use
@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
@REM ----------------------------------------------------------------------------
@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
@echo off
@REM set title of command window
title %0
@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
@REM set %HOME% to equivalent of $HOME
if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
@REM Execute a user defined script before this one
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
@REM check for pre script, once with legacy .bat ending and once with .cmd ending
if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
:skipRcPre
@setlocal
set ERROR_CODE=0
@REM To isolate internal variables from possible post scripts, we use another setlocal
@setlocal
@REM ==== START VALIDATION ====
if not "%JAVA_HOME%" == "" goto OkJHome
echo.
echo Error: JAVA_HOME not found in your environment. >&2
echo Please set the JAVA_HOME variable in your environment to match the >&2
echo location of your Java installation. >&2
echo.
goto error
:OkJHome
if exist "%JAVA_HOME%\bin\java.exe" goto init
echo.
echo Error: JAVA_HOME is set to an invalid directory. >&2
echo JAVA_HOME = "%JAVA_HOME%" >&2
echo Please set the JAVA_HOME variable in your environment to match the >&2
echo location of your Java installation. >&2
echo.
goto error
@REM ==== END VALIDATION ====
:init
@REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
@REM Fallback to current working directory if not found.
set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
set EXEC_DIR=%CD%
set WDIR=%EXEC_DIR%
:findBaseDir
IF EXIST "%WDIR%"\.mvn goto baseDirFound
cd ..
IF "%WDIR%"=="%CD%" goto baseDirNotFound
set WDIR=%CD%
goto findBaseDir
:baseDirFound
set MAVEN_PROJECTBASEDIR=%WDIR%
cd "%EXEC_DIR%"
goto endDetectBaseDir
:baseDirNotFound
set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
cd "%EXEC_DIR%"
:endDetectBaseDir
IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
@setlocal EnableExtensions EnableDelayedExpansion
for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
:endReadAdditionalConfig
SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"
FOR /F "tokens=1,2 delims==" %%A IN (%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties) DO (
IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
)
@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
@REM This allows using the maven wrapper in projects that prohibit checking in binary data.
if exist %WRAPPER_JAR% (
echo Found %WRAPPER_JAR%
) else (
echo Couldn't find %WRAPPER_JAR%, downloading it ...
echo Downloading from: %DOWNLOAD_URL%
powershell -Command "(New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"
echo Finished downloading %WRAPPER_JAR%
)
@REM End of extension
%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
if ERRORLEVEL 1 goto error
goto end
:error
set ERROR_CODE=1
:end
@endlocal & set ERROR_CODE=%ERROR_CODE%
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
@REM check for post script, once with legacy .bat ending and once with .cmd ending
if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
:skipRcPost
@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
if "%MAVEN_BATCH_PAUSE%" == "on" pause
if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
exit /B %ERROR_CODE%
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>solrdatacomparison</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>SolrDataComparison</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- swagger生成接口API 启动SpringBoot项目,访问 http://localhost:8080/swagger-ui.html-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.7.0</version>
</dependency>
<!-- 接口API生成html文档 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.7.0</version>
</dependency>
<!-- ********************* swagger导出PDF/HTML所需依赖 START ********************************* -->
<dependency>
<groupId>io.github.swagger2markup</groupId>
<artifactId>swagger2markup</artifactId>
<version>1.3.1</version> </dependency>
<!-- ********************* swagger导出PDF/HTML所需依赖 END ********************************* -->
<!-- 引入spring-data-solr-->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-solr</artifactId>
</dependency>
<!-- 引入spring-boot-starter-data-jpa -->
<!-- <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>-->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!--此插件生成ASCIIDOC-->
<plugin>
<groupId>io.github.swagger2markup</groupId>
<artifactId>swagger2markup-maven-plugin</artifactId>
<version>1.2.0</version> <configuration>
<!--此处端口一定要是当前项目启动所用的端口-->
<swaggerInput>http://localhost:8081/v2/api-docs</swaggerInput>
<outputDir>src/docs/asciidoc/generated</outputDir>
<config>
<!-- 除了ASCIIDOC之外,还有MARKDOWN和CONFLUENCE_MARKUP可选 -->
<swagger2markup.markupLanguage>ASCIIDOC</swagger2markup.markupLanguage>
</config>
</configuration>
</plugin>
</plugins>
</build>
</project>
package com.cc.solr;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SolrDataComparisonApplication {
public static void main(String[] args) {
SpringApplication.run(SolrDataComparisonApplication.class, args);
}
}
package com.cc.solr.conf;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.concurrent.Executor;
/**
* Created by changc on 2018/9/12.
*/
@Configuration
@EnableAsync
public class AsyncConfig {
/*
此处成员变量应该使用@Value从配置中读取
*/
@Value("${ThreadPool.corePoolSize}")
private int corePoolSize;
@Value("${ThreadPool.maxPoolSize}")
private int maxPoolSize;
@Value("${ThreadPool.queueCapacity}")
private int queueCapacity;
@Bean
public Executor taskExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(corePoolSize);
executor.setMaxPoolSize(maxPoolSize);
executor.setQueueCapacity(queueCapacity);
executor.initialize();
return executor;
}
}
package com.cc.solr.conf;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.security.Timestamp;
import java.util.Date;
@Configuration
@EnableSwagger2
public class Swagger2Config {
public static final String BASE_PACKAGE = "com.cc";
@Value("${swagger.enable}")
private boolean enableSwagger;
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo()) // 生产环境的时候关闭 swagger 比较安全
.enable(enableSwagger) //将Timestamp类型全部转为Long类型
.directModelSubstitute(Timestamp.class, Long.class) //将Date类型全部转为Long类型
.directModelSubstitute(Date.class, Long.class)
.select() // 扫描接口的包路径,不要忘记改成自己的
.apis(RequestHandlerSelectors.basePackage(BASE_PACKAGE))
.paths(PathSelectors.any())
.build();
} private ApiInfo apiInfo() { return new ApiInfoBuilder()
.title("XZXT RESTful APIs")
.description("XZXT API 服务")
.termsOfServiceUrl("http://swagger.io/")
.contact(new Contact("changchao", "127.0.0.1", "zhenghhgz@163.com"))
.version("1.0")
.build();
}
}
package com.cc.solr.conf;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
/**
* Created by changc on 2019/3/4.
*/
@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {
@Override public void addResourceHandlers(ResourceHandlerRegistry registry) {
// registry.addResourceHandler("/js*//**").addResourceLocations("classpath:/js/");
// registry.addResourceHandler("swagger-ui.html") .addResourceLocations("classpath:/META-INF/resources/");
// registry.addResourceHandler("/webjars*//**") .addResourceLocations("classpath:/META-INF/resources/webjars/");
}
}
package com.cc.solr.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
/**
* 筱进GG
*/
@RestController
public class HelloController {
//@ApiIgnore (去掉api 注释)
@RequestMapping(value = "/hello", method = RequestMethod.GET)
public String index() {
return "Hello World";
}
}
\ No newline at end of file
package com.cc.solr.controller;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController1 {
@Value("${person.last-name}")
private String name;
@RequestMapping("/sayHello")
public String sayHello(){
return "Hello "+name;
}
}
package com.cc.solr.controller;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@Api(value = "首页", description = "首页")
@RequestMapping("/")
@RestController
public class IndexController {
@ApiOperation(value = "Hello Spring Boot", notes = "Hello Spring Boot")
@RequestMapping(value = "/", method = RequestMethod.GET)
public String index() {
return "Hello Spring Boot";
}
@ApiOperation(value = "API 页面", notes = "接口列表")
@RequestMapping(value = "/api", method = RequestMethod.GET)
public void api(HttpServletResponse response) throws IOException {
response.sendRedirect("swagger-ui.html");
}
}
package com.cc.solr.controller;
import com.cc.solr.entity.UserInfo;
import io.swagger.annotations.*;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
import org.apache.solr.common.SolrInputDocument;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 优化:抽取 Id、text 为一个 JavaBean
* @author linhongcun
*
*/
@Api(value = "solr增删改查", description = "提供solr增删改成接口")
@RestController
@RequestMapping("/solr")
public class SolrController {
@Autowired
private SolrClient client;
/**
* 1、增
* @param map
* @return
* @throws IOException
* @throws SolrServerException
*/
//方法描述
@ApiOperation(value = "插入接口-插入map数据", notes = "插入map数据")
//参数描述
@ApiImplicitParam(name = "map", value = "{\"SFSJDQPCL_PDBZ\":\"0\",\"LADW_GAJGJGDM\":\"150000000000\",\"AJMC\":\"张岩现金被盗窃案\",\"ASJLYDM\":\"0100\",\"ASJFSSJ_ASJFSKSSJ\":\"2018-06-01\",\"XXDJDW_GAJGJGDM\":\"660000000000\",\"ASJFSSJ_ASJFSJSSJ\":\"2018-05-01\",\"SFSH_PDBZ\":\"0\",\"AJLBDM\":\"01000000\",\"LADW_GAJGMC\":\"内蒙古公安厅\",\"SFMA_PDBZ\":\"1\",\"ZCJDDM\":\"0400\",\"ASJFSDD_XZQHDM\":\"150100\",\"SFGM_PDBZ\":\"0\",\"LARQ\":\"2018-09-05\",\"SFSQ_PDBZ\":\"0\",\"ID\":\"A5111021400002017120001\",\"JYAQ\":\"蒙HKH255和蒙IJK456哇哈哈和新KJH和新K8H1K1无敌2017年01月04日18时41分,张岩报案称:在满洲里市道北四道街仁和洗浴内,被盗人民币3400元。00-23-8B-A0-09-0A;00-1F-16-17-CF-42;20-CF-30-69-C9-F3;08-9E-01-00-27-7E;\"}")
//返回值描述
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK"),
@ApiResponse(code = 405, message = "插入失败")
})
@PostMapping("/insert")
public String insert(@RequestBody Map<String, String> map) throws IOException, SolrServerException {
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmmss");
String dateString = sdf.format(new Date());
try {
SolrInputDocument doc = new SolrInputDocument();
doc.setField("ID", map.get("ID"));
doc.setField("SFSJDQPCL_PDBZ", map.get("SFSJDQPCL_PDBZ"));
doc.setField("LADW_GAJGJGDM", map.get("LADW_GAJGJGDM"));
doc.setField("AJMC", map.get("AJMC"));
doc.setField("ASJLYDM", map.get("ASJLYDM"));
doc.setField("ASJFSSJ_ASJFSKSSJ", map.get("ASJFSSJ_ASJFSKSSJ"));
doc.setField("AJLBDM", map.get("AJLBDM"));
doc.setField("XXDJDW_GAJGJGDM", map.get("XXDJDW_GAJGJGDM"));
doc.setField("ASJFSSJ_ASJFSJSSJ", map.get("ASJFSSJ_ASJFSJSSJ"));
doc.setField("SFSH_PDBZ", map.get("SFSH_PDBZ"));
doc.setField("AJLBDM", map.get("AJLBDM"));
doc.setField("LADW_GAJGMC", map.get("LADW_GAJGMC"));
doc.setField("SFMA_PDBZ", map.get("SFMA_PDBZ"));
doc.setField("ZCJDDM", map.get("ZCJDDM"));
doc.setField("ASJFSDD_XZQHDM", map.get("ASJFSDD_XZQHDM"));
doc.setField("SFGM_PDBZ", map.get("SFGM_PDBZ"));
doc.setField("JYAQ", map.get("JYAQ"));
/*
* 如果 spring.data.solr.host 里面配置到 core了, 那么这里就不需要传 collection1 这个参数 下面都是一样的 即
* client.commit();
*/
client.add("itaem", doc);
client.commit("itaem");
return map.get("ID");
} catch (Exception e) {
e.printStackTrace();
}
return "error";
}
/**
* 2、查 id
* @param id
* @return
* @throws SolrServerException
* @throws IOException
*/
@GetMapping("/get/{id}")
//方法描述
@ApiOperation(value = "插入接口-传入id", notes = "根据id查询数据")
//参数描述
@ApiImplicitParam(name = "id",value = "案件编号", required = true, dataType = "string", paramType = "path")
//返回值描述
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK"),
@ApiResponse(code = 405, message = "查询失败")
})
public String getDocumentById(@PathVariable String id) throws SolrServerException, IOException {
SolrDocument document = client.getById("itaem", id);
System.out.println(document);
return document.toString();
}
/**
* 3、删 id
* @return
*/
//方法描述
@ApiOperation(value = "插入接口-传入id", notes = "根据id删除数据")
//参数描述 //path 以地址的形式提交数据 如果不写 paramType = "query" 直接跟参数完成自动映射赋值
@ApiImplicitParam(name = "id",value = "案件编号", required = true, dataType = "string", paramType = "path")
//返回值描述
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK"),
@ApiResponse(code = 500, message = "删除失败")
})
@DeleteMapping("/delete/{id}")
public String getAllDocuments(@PathVariable String id) {
try {
client.deleteById("itaem", id);
client.commit("itaem");
return id;
} catch (Exception e) {
e.printStackTrace();
}
return "error";
}
/**
* 4、删 all
* @return
*/
@DeleteMapping("deleteAll")
//方法描述
@ApiOperation(value = "插入接口-删除所有", notes = "删除所有数据")
//返回值描述
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK"),
@ApiResponse(code = 405, message = "删除失败")
})
public String deleteAll() {
try {
client.deleteByQuery("itaem", "*:*");
client.commit("itaem");
return "success";
} catch (Exception e) {
e.printStackTrace();
}
return "error";
}
/**
* 5、改
* @param jyaq
* @return
* @throws IOException
* @throws SolrServerException
*/
@PutMapping("/update")
//方法描述
@ApiOperation(value = "插入接口-传入id、jyaq", notes = "更新id、jyaq")
//参数描述 //paramType = "query"
@ApiImplicitParams({
@ApiImplicitParam(name = "id",value = "案件编号", required = true, dataType = "string", paramType = "query"),
@ApiImplicitParam(name = "jyaq",value = "简要案情", required = true, dataType = "string",paramType = "query"),
})
//返回值描述
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK"),
@ApiResponse(code = 405, message = "查询失败")
})
public String update(@RequestParam String id, @RequestParam String jyaq) throws IOException, SolrServerException {
try {
SolrInputDocument doc = new SolrInputDocument();
doc.setField("ID", id);
doc.setField("JYAQ", jyaq);
/*
* 如果 spring.data.solr.host 里面配置到 core了, 那么这里就不需要传 itaem 这个参数 下面都是一样的 即
* client.commit();
*/
client.add("itaem", doc);
client.commit("itaem");
return doc.toString();
} catch (Exception e) {
e.printStackTrace();
}
return "error";
}
/**
* 6、全
* @return
* @throws SolrServerException
* @throws IOException
*/
@GetMapping("/get/all")
//方法描述
@ApiOperation(value = "插入接口-查询所有", notes = "查询所有")
//返回值描述
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK"),
@ApiResponse(code = 405, message = "查询失败")
})
public Map<String, Object> getAll()
throws SolrServerException, IOException {
Map<String, Object> map = new HashMap<String, Object>();
return map;
}
/**
* 7、查 ++:关键字、高亮、分页 ✔
* @return
* @return
* @throws SolrServerException
* @throws IOException
*/
@GetMapping("/select/{q}/{page}/{size}")
//方法描述
@ApiOperation(value = "插入接口-分页查询", notes = "分页查询")
//参数描述
@ApiImplicitParams({
@ApiImplicitParam(name = "q",value = "查询条件", required = true),
@ApiImplicitParam(name = "fq",value = "过虑查询", required = true),
@ApiImplicitParam(name = "page",value = "第几页", required = true),
@ApiImplicitParam(name = "size",value = "显示条数", required = true),
})
//返回值描述
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK"),
@ApiResponse(code = 405, message = "查询失败")
})
public Map<String, Object> select(@PathVariable String q,@PathVariable String fq, @PathVariable Integer page, @PathVariable Integer size)
throws SolrServerException, IOException {
SolrQuery params = new SolrQuery();
// fq – (filter query)过虑查询,作用:在q查询符合结果中同时是fq查询符合的,
// 查询条件
params.set("q", q);
// 排序
params.addSort("ID", SolrQuery.ORDER.desc);
// 分页
params.setStart(page);
params.setRows(size);
// 默认域 默认的查询字段,一般默认指定
params.set("df", "JYAQ");
params.set("fq", fq);
// 只查询指定域 返回指定字段
params.set("fl", "ID,JYAQ");
// 开启高亮
params.setHighlight(true);
// 设置前缀
params.setHighlightSimplePre("<span style='color:red'>");
// 设置后缀
params.setHighlightSimplePost("</span>");
// solr数据库是 itaem
QueryResponse queryResponse = client.query("itaem", params);
SolrDocumentList results = queryResponse.getResults();
// 数量,分页用
long total = results.getNumFound();// JS 使用 size=MXA 和 data.length 即可知道长度了(但不合理)
// 获取高亮显示的结果, 高亮显示的结果和查询结果是分开放的
Map<String, Map<String, List<String>>> highlight = queryResponse.getHighlighting();
Map<String, Object> map = new HashMap<String, Object>();
map.put("total", total);
map.put("data", highlight);
return map;
}
}
package com.cc.solr.controller;
import io.swagger.annotations.*;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
import org.apache.solr.common.SolrInputDocument;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 优化:抽取 Id、text 为一个 JavaBean
* @author linhongcun
*
*/
@Api(value = "solr数据比对", description = "提供solr比对数据接口")
@RestController
@RequestMapping("/solrdatecomparison")
public class SolrDateComparisonController {
@Autowired
private SolrClient client;
/**
* 1、增
* @param map
* @return
* @throws IOException
* @throws SolrServerException
*/
//方法描述
@ApiOperation(value = "插入接口-插入map数据", notes = "插入map数据")
//参数描述
@ApiImplicitParam(name = "map", value = "{\"SFSJDQPCL_PDBZ\":\"0\",\"LADW_GAJGJGDM\":\"150000000000\",\"AJMC\":\"张岩现金被盗窃案\",\"ASJLYDM\":\"0100\",\"ASJFSSJ_ASJFSKSSJ\":\"2018-06-01\",\"XXDJDW_GAJGJGDM\":\"660000000000\",\"ASJFSSJ_ASJFSJSSJ\":\"2018-05-01\",\"SFSH_PDBZ\":\"0\",\"AJLBDM\":\"01000000\",\"LADW_GAJGMC\":\"内蒙古公安厅\",\"SFMA_PDBZ\":\"1\",\"ZCJDDM\":\"0400\",\"ASJFSDD_XZQHDM\":\"150100\",\"SFGM_PDBZ\":\"0\",\"LARQ\":\"2018-09-05\",\"SFSQ_PDBZ\":\"0\",\"ID\":\"A5111021400002017120001\",\"JYAQ\":\"蒙HKH255和蒙IJK456哇哈哈和新KJH和新K8H1K1无敌2017年01月04日18时41分,张岩报案称:在满洲里市道北四道街仁和洗浴内,被盗人民币3400元。00-23-8B-A0-09-0A;00-1F-16-17-CF-42;20-CF-30-69-C9-F3;08-9E-01-00-27-7E;\"}")
//返回值描述
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK"),
@ApiResponse(code = 405, message = "插入失败")
})
@PostMapping("/insert")
public String insert(@RequestBody Map<String, String> map) throws IOException, SolrServerException {
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmmss");
String dateString = sdf.format(new Date());
try {
SolrInputDocument doc = new SolrInputDocument();
doc.setField("ID", map.get("ID"));
doc.setField("SFSJDQPCL_PDBZ", map.get("SFSJDQPCL_PDBZ"));
doc.setField("LADW_GAJGJGDM", map.get("LADW_GAJGJGDM"));
doc.setField("AJMC", map.get("AJMC"));
doc.setField("ASJLYDM", map.get("ASJLYDM"));
doc.setField("ASJFSSJ_ASJFSKSSJ", map.get("ASJFSSJ_ASJFSKSSJ"));
doc.setField("AJLBDM", map.get("AJLBDM"));
doc.setField("XXDJDW_GAJGJGDM", map.get("XXDJDW_GAJGJGDM"));
doc.setField("ASJFSSJ_ASJFSJSSJ", map.get("ASJFSSJ_ASJFSJSSJ"));
doc.setField("SFSH_PDBZ", map.get("SFSH_PDBZ"));
doc.setField("AJLBDM", map.get("AJLBDM"));
doc.setField("LADW_GAJGMC", map.get("LADW_GAJGMC"));
doc.setField("SFMA_PDBZ", map.get("SFMA_PDBZ"));
doc.setField("ZCJDDM", map.get("ZCJDDM"));
doc.setField("ASJFSDD_XZQHDM", map.get("ASJFSDD_XZQHDM"));
doc.setField("SFGM_PDBZ", map.get("SFGM_PDBZ"));
doc.setField("JYAQ", map.get("JYAQ"));
/*
* 如果 spring.data.solr.host 里面配置到 core了, 那么这里就不需要传 collection1 这个参数 下面都是一样的 即
* client.commit();
*/
client.add("itaem", doc);
client.commit("itaem");
return map.get("ID");
} catch (Exception e) {
e.printStackTrace();
}
return "error";
}
/**
* 2、查 id
* @param id
* @return
* @throws SolrServerException
* @throws IOException
*/
@GetMapping("/get/{id}")
//方法描述
@ApiOperation(value = "插入接口-传入id", notes = "根据id查询数据")
//参数描述
@ApiImplicitParam(name = "id",value = "案件编号", required = true, dataType = "string", paramType = "path")
//返回值描述
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK"),
@ApiResponse(code = 405, message = "查询失败")
})
public String getDocumentById(@PathVariable String id) throws SolrServerException, IOException {
SolrDocument document = client.getById("itaem", id);
System.out.println(document);
return document.toString();
}
/**
* 3、删 id
* @return
*/
//方法描述
@ApiOperation(value = "插入接口-传入id", notes = "根据id删除数据")
//参数描述 //path 以地址的形式提交数据 如果不写 paramType = "query" 直接跟参数完成自动映射赋值
@ApiImplicitParam(name = "id",value = "案件编号", required = true, dataType = "string", paramType = "path")
//返回值描述
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK"),
@ApiResponse(code = 500, message = "删除失败")
})
@DeleteMapping("/delete/{id}")
public String getAllDocuments(@PathVariable String id) {
try {
client.deleteById("itaem", id);
client.commit("itaem");
return id;
} catch (Exception e) {
e.printStackTrace();
}
return "error";
}
/**
* 4、删 all
* @return
*/
@DeleteMapping("deleteAll")
//方法描述
@ApiOperation(value = "插入接口-删除所有", notes = "删除所有数据")
//返回值描述
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK"),
@ApiResponse(code = 405, message = "删除失败")
})
public String deleteAll() {
try {
client.deleteByQuery("itaem", "*:*");
client.commit("itaem");
return "success";
} catch (Exception e) {
e.printStackTrace();
}
return "error";
}
/**
* 5、改
* @param jyaq
* @return
* @throws IOException
* @throws SolrServerException
*/
@PutMapping("/update")
//方法描述
@ApiOperation(value = "插入接口-传入id、jyaq", notes = "更新id、jyaq")
//参数描述 //paramType = "query"
@ApiImplicitParams({
@ApiImplicitParam(name = "id",value = "案件编号", required = true, dataType = "string", paramType = "query"),
@ApiImplicitParam(name = "jyaq",value = "简要案情", required = true, dataType = "string",paramType = "query"),
})
//返回值描述
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK"),
@ApiResponse(code = 405, message = "查询失败")
})
public String update(@RequestParam String id, @RequestParam String jyaq) throws IOException, SolrServerException {
try {
SolrInputDocument doc = new SolrInputDocument();
doc.setField("ID", id);
doc.setField("JYAQ", jyaq);
/*
* 如果 spring.data.solr.host 里面配置到 core了, 那么这里就不需要传 itaem 这个参数 下面都是一样的 即
* client.commit();
*/
client.add("itaem", doc);
client.commit("itaem");
return doc.toString();
} catch (Exception e) {
e.printStackTrace();
}
return "error";
}
/**
* 6、全
* @return
* @throws SolrServerException
* @throws IOException
*/
@GetMapping("/get/all")
//方法描述
@ApiOperation(value = "插入接口-查询所有", notes = "查询所有")
//返回值描述
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK"),
@ApiResponse(code = 405, message = "查询失败")
})
public Map<String, Object> getAll()
throws SolrServerException, IOException {
Map<String, Object> map = new HashMap<String, Object>();
return map;
}
/**
* 7、查 ++:关键字、高亮、分页 ✔
* @return
* @return
* @throws SolrServerException
* @throws IOException
*/
@GetMapping("/select/{q}/{page}/{size}")
//方法描述
@ApiOperation(value = "插入接口-分页查询", notes = "分页查询")
//参数描述
@ApiImplicitParams({
@ApiImplicitParam(name = "q",value = "查询条件", required = true),
@ApiImplicitParam(name = "fq",value = "过虑查询", required = true),
@ApiImplicitParam(name = "page",value = "第几页", required = true),
@ApiImplicitParam(name = "size",value = "显示条数", required = true),
})
//返回值描述
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK"),
@ApiResponse(code = 405, message = "查询失败")
})
public Map<String, Object> select(@PathVariable String q,@PathVariable String fq, @PathVariable Integer page, @PathVariable Integer size)
throws SolrServerException, IOException {
SolrQuery params = new SolrQuery();
// fq – (filter query)过虑查询,作用:在q查询符合结果中同时是fq查询符合的,
// 查询条件
params.set("q", q);
// 排序
params.addSort("ID", SolrQuery.ORDER.desc);
// 分页
params.setStart(page);
params.setRows(size);
// 默认域 默认的查询字段,一般默认指定
params.set("df", "JYAQ");
params.set("fq", fq);
// 只查询指定域 返回指定字段
params.set("fl", "ID,JYAQ");
// 开启高亮
params.setHighlight(true);
// 设置前缀
params.setHighlightSimplePre("<span style='color:red'>");
// 设置后缀
params.setHighlightSimplePost("</span>");
// solr数据库是 itaem
QueryResponse queryResponse = client.query("itaem", params);
SolrDocumentList results = queryResponse.getResults();
// 数量,分页用
long total = results.getNumFound();// JS 使用 size=MXA 和 data.length 即可知道长度了(但不合理)
// 获取高亮显示的结果, 高亮显示的结果和查询结果是分开放的
Map<String, Map<String, List<String>>> highlight = queryResponse.getHighlighting();
Map<String, Object> map = new HashMap<String, Object>();
map.put("total", total);
map.put("data", highlight);
return map;
}
}
package com.cc.solr.controller;
import com.cc.solr.util.TestTask;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
* Created by changc on 2019/3/5.
*/
public class TaskController {
@Autowired
private TestTask asyncTask;
@ResponseBody
@RequestMapping("/hello")
public String hello() throws Exception {
long starttime = System.currentTimeMillis();
//Future<String> task1 = asyncTask.test1();
//Future<String> task2 = asyncTask.test2(); //等待任务都执行完
//Future<String> task3 = asyncTask.test3();
for (int i = 0; i <= 30; i++) {
asyncTask.test2();
// System.out.println(ss);
}
/* while(true){
if(task1.isDone() && task2.isDone()){ break;
}
}*/
long endtime = System.currentTimeMillis();
System.out.println("执行任务总用时:" + (endtime - starttime) + "毫秒");
return "Hello World111!";
}
}
package com.cc.solr.controller;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;
import javax.servlet.http.HttpServletRequest;
/**
* Created by changc on 2019/3/4.
*/
@RestController
@Api(value = "测试接口", tags = "TestController", description = "测试接口相关")
@RequestMapping(value = "/test")
@ApiIgnore
public class TestController {
@ResponseBody
@ApiOperation(tags = "打招呼测试接口", value = "进行打招呼户测试", notes = "请求返回打招呼的字符串")
@RequestMapping(value = "/printHello")
public String pringHello() {
return "Hello SpringBoot";
}
@ResponseBody
@ApiOperation(tags = "打招呼测试接口", value = "进行打招呼户测试", notes = "请求返回打招呼的字符串")
@RequestMapping(value = "/printHello1") public String pringHello1() {
return "Hello SpringBoot";
}
@ResponseBody
@ApiOperation(tags = "获取上下文路径接口", value = "获取上下文路径", notes = "依据getContextPath获取上下文的路径")
@RequestMapping(value = "/getContextPath")
public String getContextPath(HttpServletRequest request) {
return request.getContextPath();
}
@ResponseBody
@ApiOperation(tags = "获取上下文的路径接口", value = "获取Servlet路径", notes = "依据getServletPath获取上下文的路径")
@RequestMapping(value = "/getServletPath")
public String getServletPath(HttpServletRequest request) {
return request.getServletPath();
}
@ResponseBody
@ApiOperation(tags = "获取路径信息接口", value = "获取路径信息", notes = "依据getPathInfo获取路径信息")
@RequestMapping(value = "/getPathInfo")
public String getPathInfo(HttpServletRequest request) {
return request.getPathInfo();
}
}
package com.cc.solr.controller;
import com.cc.solr.entity.User;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import java.util.*;
/**
* 筱进GG
*/
@RestController
@RequestMapping(value="/users") // 通过这里配置使下面的映射都在/users下,可去除
public class UserController1 {
static Map<Long, User> users = Collections.synchronizedMap(new HashMap<Long, User>());
@ApiOperation(value="获取用户列表", notes="")
@RequestMapping(value={""}, method= RequestMethod.GET)
public List<User> getUserList() {
List<User> r = new ArrayList<User>(users.values());
return r;
}
@ApiOperation(value="创建用户", notes="根据User对象创建用户")
@ApiImplicitParam(name = "user", value = "用户详细实体user", required = true, dataType = "User")
@RequestMapping(value="", method= RequestMethod.POST)
public String postUser(@RequestBody User user) {
users.put(user.getId(), user);
return "success";
}
@ApiOperation(value="获取用户详细信息", notes="根据url的id来获取用户详细信息")
@ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "Long")
@RequestMapping(value="/{id}", method= RequestMethod.GET)
public User getUser(@PathVariable Long id) {
return users.get(id);
}
@ApiOperation(value="更新用户详细信息", notes="根据url的id来指定更新对象,并根据传过来的user信息来更新用户详细信息")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "Long"),
@ApiImplicitParam(name = "user", value = "用户详细实体user", required = true, dataType = "User")
})
@RequestMapping(value="/{id}", method= RequestMethod.PUT)
public String putUser(@PathVariable String id, @RequestBody User user) {
User u = users.get(id);
u.setName(user.getName());
u.setAge(user.getAge());
//users.put(id, u);
return "success";
}
@ApiOperation(value="删除用户", notes="根据url的id来指定删除对象")
@ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "Long")
@RequestMapping(value="/{id}", method= RequestMethod.DELETE)
public String deleteUser(@PathVariable Long id) {
users.remove(id);
return "success";
}
}
\ No newline at end of file
package com.cc.solr.controller;
import com.cc.solr.entity.UserInfo;
import io.swagger.annotations.*;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
@Api(value = "用户", description = "用户")
@RequestMapping("/userInfo")
@RestController
public class UserInfoController {
@ApiOperation(value = "登录接口-多值传值方式", notes = "输入用户名和密码登录")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK", response = UserInfo.class, responseContainer = "userInfo"),
@ApiResponse(code = 405, message = "账号名或密码错误")
})
@ApiImplicitParam(name = "map", value = "{\"userName\":\"JackMa\",\"passWord\":\"123\"}")
@RequestMapping(value = "loginForMap", method = RequestMethod.POST, produces= MediaType.APPLICATION_JSON_UTF8_VALUE)
ResponseEntity<UserInfo> loginForMap(@RequestBody Map<String, String> map) {
if (!map.get("userName").equalsIgnoreCase("JackMa") || !map.get("passWord").equalsIgnoreCase("123")) {
return ResponseEntity.status(HttpStatus.METHOD_NOT_ALLOWED).build();
}
UserInfo user = new UserInfo();
user.setId(1L);
user.setUserName("JackMa");
user.setFirstName("马");
user.setLastName("云");
user.setEmail("zhenghhgz@163.com");
user.setUserStatus(1);
return ResponseEntity.ok(user);
}
@ApiOperation(value = "登录接口-多值传输方式", notes = "输入用户名和密码登录")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK", response = UserInfo.class, responseContainer = "userInfo"),
@ApiResponse(code = 405, message = "账号名或密码错误")
})
@ApiImplicitParams({
@ApiImplicitParam(name = "userName",value = "用户名", required = true, dataType = "string", paramType = "query"),
@ApiImplicitParam(name = "passWord",value = "密码", required = true, dataType = "string",paramType = "query"),
})
@RequestMapping(value = "loginForParams", method = RequestMethod.POST, produces= MediaType.APPLICATION_JSON_UTF8_VALUE)
ResponseEntity<UserInfo> loginForMap(@RequestParam String userName, @RequestParam String passWord) {
if (!userName.equalsIgnoreCase("JackMa") || !passWord.equalsIgnoreCase("123")) {
return ResponseEntity.status(HttpStatus.METHOD_NOT_ALLOWED).build();
}
UserInfo user = new UserInfo();
user.setId(1L);
user.setUserName("JackMa");
user.setFirstName("马");
user.setLastName("云");
user.setEmail("jackma@163.com");
user.setUserStatus(1);
return ResponseEntity.ok(user);
}
}
package com.cc.solr.entity;
/**
* 筱进GG
*/
public class User {
private Long id;
private String name;
private Integer age;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
}
package com.cc.solr.entity;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModelProperty;
public class UserInfo {
@ApiModelProperty("编号")
private Long id;
@ApiModelProperty("用户名")
private String userName;
@ApiModelProperty("姓")
private String firstName;
@ApiModelProperty("名")
private String lastName;
@ApiModelProperty("邮箱")
private String email;
@ApiModelProperty(hidden = true)// 密码不传输
@JsonIgnore
private String password;
@ApiModelProperty("状态")
private Integer userStatus;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public Integer getUserStatus() {
return userStatus;
}
public void setUserStatus(Integer userStatus) {
this.userStatus = userStatus;
}
@Override
public String toString() {
return "UserInfo{" +
"id=" + id +
", userName='" + userName + '\'' +
", firstName='" + firstName + '\'' +
", lastName='" + lastName + '\'' +
", email='" + email + '\'' +
", password='" + password + '\'' +
", userStatus=" + userStatus +
'}';
}
}
package com.cc.solr.util;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
/**
* Created by changc on 2018/9/11.
*/
@Component
public class ServiceReport {
@Scheduled(cron = "0/2 * * * * *")
public void work() {
//获取当前时间
LocalDateTime localDateTime = LocalDateTime.now();
System.out.println("当前时间为:" + localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
}
}
package com.cc.solr.util;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Component;
import java.util.concurrent.Future;
@Component
public class TestTask {
//异步任务此处必须返回Future,可以是Future<String>,也可以是Future<Integer>,自己定义具体的返回内容
@Async
public Future<String> test1() throws Exception{
Thread.sleep(1000);
System.out.println("线程:"+Thread.currentThread().getName()+"---执行任务1,用时1秒");
return new AsyncResult<>("test1");
}
@Async("taskExecutor")
public Future<String> test2() throws Exception{
Thread.sleep(1500);
System.out.println("线程:"+Thread.currentThread().getName()+"---执行任务2,用时1.5秒");
return new AsyncResult<>("test2");
}
//@Async("taskExecutor")
public Future<String> test3() throws Exception{
Thread.sleep(1500);
System.out.println("线程:"+Thread.currentThread().getName()+"---执行任务3,用时1.5秒");
return new AsyncResult<>("test2");
}
@Async("taskExecutor")
public Future<String> doReturn(int i){
try {
// 这个方法需要调用500毫秒
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
// 消息汇总
return new AsyncResult<>(String.format("这个是第{%s}个异步调用的证书", i));
}
}
person.last-name=2222
server.port=8081
swagger.enable=true
#也就是说,线程池优先要创建出基本线程池大小(corePoolSize)的线程数量,
#没有达到这个数量时,每次提交新任务都会直接创建一个新线程,
#当达到了基本线程数量后,又有新任务到达,优先放入等待队列,
#如果队列满了,才去创建新的线程(不能超过线程池的最大数maxmumPoolSize)。
#核心线程数
ThreadPool.corePoolSize: 20
#最大线程数
ThreadPool.maxPoolSize: 200
#任务队列容量(阻塞队列)
ThreadPool.queueCapacity: 10
\ No newline at end of file
server:
port: 8080
spring:
data:
solr:
host: http://127.0.0.1:9090/solr/
\ No newline at end of file
package com.cc.solr;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class SolrDataComparisonApplicationTests {
@Test
public void contextLoads() {
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment