Skip to content

Commit 1de9695

Browse files
committed
added codes
1 parent a48e6fd commit 1de9695

File tree

18 files changed

+920
-0
lines changed

18 files changed

+920
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
### Maven ###
2+
/target/
3+
### STS ###
4+
.apt_generated
5+
.classpath
6+
.factorypath
7+
.project
8+
.settings
9+
.springBeans
10+
.sts4-cache
11+
.settings
12+
13+
### IntelliJ IDEA ###
14+
.idea
15+
*.iws
16+
*.iml
17+
*.ipr
18+
19+
### NetBeans ###
20+
/nbproject/private/
21+
/nbbuild/
22+
/dist/
23+
/nbdist/
24+
/.nb-gradle/
25+
/build/
26+
27+
### VS Code ###
28+
.vscode/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.xingyun</groupId>
5+
<artifactId>helloworld_web_maven_sample</artifactId>
6+
<packaging>war</packaging>
7+
<version>0.0.1-SNAPSHOT</version>
8+
<name>helloworld_web_maven_sample Maven Webapp</name>
9+
<url>http://maven.apache.org</url>
10+
<description>http://localhost:8080/helloapp/,run maven build as tomcat7:run </description>
11+
12+
<properties>
13+
<servlet.version>3.1.0</servlet.version>
14+
</properties>
15+
16+
<dependencies>
17+
<dependency>
18+
<groupId>javax.servlet</groupId>
19+
<artifactId>javax.servlet-api</artifactId>
20+
<version>${servlet.version}</version>
21+
<type>jar</type>
22+
<scope>provided</scope>
23+
</dependency>
24+
</dependencies>
25+
<build>
26+
<finalName>helloapp</finalName>
27+
<plugins>
28+
<plugin>
29+
<groupId>org.apache.tomcat.maven</groupId>
30+
<artifactId>tomcat7-maven-plugin</artifactId>
31+
<version>2.2</version>
32+
<configuration>
33+
<url>http://localhost:8080/manager/text</url>
34+
<!-- server、username、password对应maven的setting下的配置 -->
35+
<server>tomcat</server>
36+
<username>admin</username>
37+
<password>admin</password>
38+
<path>/${project.build.finalName}</path>
39+
</configuration>
40+
</plugin>
41+
42+
<plugin>
43+
<artifactId>maven-compiler-plugin</artifactId>
44+
<version>3.0</version>
45+
<configuration>
46+
<source>1.8</source>
47+
<target>1.8</target>
48+
<encoding>UTF-8</encoding>
49+
</configuration>
50+
</plugin>
51+
</plugins>
52+
</build>
53+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<!DOCTYPE web-app PUBLIC
2+
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
3+
"http://java.sun.com/dtd/web-app_2_3.dtd" >
4+
5+
<web-app>
6+
<display-name>Archetype Created Web Application</display-name>
7+
</web-app>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<html>
2+
<body>
3+
<h2>Hello World!</h2>
4+
</body>
5+
</html>

Maven_Sample/readme.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
项目代码 | 项目博文名称
3+
---|---
4+
[helloworld_web_maven_sample](https://github.com/geekxingyun/JavaEE-Framework-Sample/tree/master/Maven_Sample/helloworld_web_maven_sample) | [版本依赖管理之 Maven 修炼手册](https://yq.aliyun.com/articles/675672?spm=a2c4e.11155435.0.0.30516094r7rLoN)
5+
6+

lucene-sample/.gitignore

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
### Maven ###
2+
/target/
3+
### STS ###
4+
.apt_generated
5+
.classpath
6+
.factorypath
7+
.project
8+
.settings
9+
.springBeans
10+
.sts4-cache
11+
.settings
12+
13+
### IntelliJ IDEA ###
14+
.idea
15+
*.iws
16+
*.iml
17+
*.ipr
18+
19+
### NetBeans ###
20+
/nbproject/private/
21+
/nbbuild/
22+
/dist/
23+
/nbdist/
24+
/.nb-gradle/
25+
/build/
26+
27+
### VS Code ###
28+
.vscode/

lucene-sample/pom.xml

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<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">
2+
<modelVersion>4.0.0</modelVersion>
3+
<groupId>com.xingyun</groupId>
4+
<artifactId>lucene-sample</artifactId>
5+
<version>0.0.1-SNAPSHOT</version>
6+
<packaging>jar</packaging>
7+
8+
<name>lucene-sample</name>
9+
10+
<properties>
11+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
12+
</properties>
13+
14+
<build>
15+
<plugins>
16+
<plugin>
17+
<groupId>org.codehaus.mojo</groupId>
18+
<artifactId>exec-maven-plugin</artifactId>
19+
<version>1.3.2</version>
20+
<executions>
21+
<execution>
22+
<id>ex</id>
23+
<phase>package</phase>
24+
<goals>
25+
<goal>exec</goal>
26+
</goals>
27+
<configuration>
28+
<executable>java</executable>
29+
<arguments>
30+
<argument>-classpath</argument>
31+
<classpath />
32+
<argument>HelloLucene.HelloLucene</argument>
33+
</arguments>
34+
</configuration>
35+
</execution>
36+
</executions>
37+
</plugin>
38+
</plugins>
39+
</build>
40+
41+
<dependencies>
42+
<dependency>
43+
<groupId>org.apache.lucene</groupId>
44+
<artifactId>lucene-core</artifactId>
45+
<version>7.1.0</version>
46+
</dependency>
47+
<dependency>
48+
<groupId>org.apache.lucene</groupId>
49+
<artifactId>lucene-queries</artifactId>
50+
<version>7.1.0</version>
51+
</dependency>
52+
<dependency>
53+
<groupId>org.apache.lucene</groupId>
54+
<artifactId>lucene-test-framework</artifactId>
55+
<version>7.1.0</version>
56+
</dependency>
57+
<dependency>
58+
<groupId>org.apache.lucene</groupId>
59+
<artifactId>lucene-analyzers-common</artifactId>
60+
<version>7.1.0</version>
61+
</dependency>
62+
<dependency>
63+
<groupId>org.apache.lucene</groupId>
64+
<artifactId>lucene-queryparser</artifactId>
65+
<version>7.1.0</version>
66+
</dependency>
67+
</dependencies>
68+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package com.xingyun;
2+
3+
import java.io.IOException;
4+
import java.text.ParseException;
5+
6+
import org.apache.lucene.analysis.standard.StandardAnalyzer;
7+
import org.apache.lucene.document.Document;
8+
import org.apache.lucene.document.Field;
9+
import org.apache.lucene.document.StringField;
10+
import org.apache.lucene.document.TextField;
11+
import org.apache.lucene.index.DirectoryReader;
12+
import org.apache.lucene.index.IndexReader;
13+
import org.apache.lucene.index.IndexWriter;
14+
import org.apache.lucene.index.IndexWriterConfig;
15+
import org.apache.lucene.queryparser.classic.QueryParser;
16+
import org.apache.lucene.search.IndexSearcher;
17+
import org.apache.lucene.search.Query;
18+
import org.apache.lucene.search.ScoreDoc;
19+
import org.apache.lucene.search.TopScoreDocCollector;
20+
import org.apache.lucene.store.Directory;
21+
import org.apache.lucene.store.RAMDirectory;
22+
import org.apache.lucene.util.Version;
23+
24+
public class HelloLucene {
25+
26+
public static void main(String[] args) throws IOException, ParseException {
27+
28+
// 对于这个简单的例子,我们将从一些字符串中创建一个内存索引。
29+
// 0. Specify the analyzer for tokenizing text.
30+
// The same analyzer should be used for indexing and searching
31+
StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_40);
32+
33+
// 1. create the index
34+
Directory index = new RAMDirectory();
35+
36+
IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_40, analyzer);
37+
38+
IndexWriter w = new IndexWriter(index, config);
39+
addDoc(w, "Lucene in Action", "193398817");
40+
addDoc(w, "Lucene for Dummies", "55320055Z");
41+
addDoc(w, "Managing Gigabytes", "55063554A");
42+
addDoc(w, "The Art of Computer Science", "9900333X");
43+
w.close();
44+
45+
// 2. query
46+
String querystr = args.length > 0 ? args[0] : "lucene";
47+
48+
// the "title" arg specifies the default field to use
49+
// when no field is explicitly specified in the query.
50+
Query q = null;
51+
try {
52+
q = new QueryParser(Version.LUCENE_40, "title", analyzer).parse(querystr);
53+
} catch (org.apache.lucene.queryparser.classic.ParseException e) {
54+
e.printStackTrace();
55+
}
56+
57+
// 3. search
58+
int hitsPerPage = 10;
59+
IndexReader reader = DirectoryReader.open(index);
60+
IndexSearcher searcher = new IndexSearcher(reader);
61+
TopScoreDocCollector collector = TopScoreDocCollector.create(hitsPerPage, true);
62+
searcher.search(q, collector);
63+
ScoreDoc[] hits = collector.topDocs().scoreDocs;
64+
65+
// 4. display results
66+
System.out.println("Found " + hits.length + " hits.");
67+
for (int i = 0; i < hits.length; ++i) {
68+
int docId = hits[i].doc;
69+
Document d = searcher.doc(docId);
70+
System.out.println((i + 1) + ". " + d.get("isbn") + "\t" + d.get("title"));
71+
}
72+
73+
// reader can only be closed when there
74+
// is no need to access the documents any more.
75+
reader.close();
76+
}
77+
78+
private static void addDoc(IndexWriter w, String title, String isbn) throws IOException {
79+
Document doc = new Document();
80+
doc.add(new TextField("title", title, Field.Store.YES));
81+
82+
// use a string field for isbn because we don't want it tokenized
83+
doc.add(new StringField("isbn", isbn, Field.Store.YES));
84+
w.addDocument(doc);
85+
}
86+
87+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/target/
2+
!.mvn/wrapper/maven-wrapper.jar
3+
4+
### STS ###
5+
.apt_generated
6+
.classpath
7+
.factorypath
8+
.project
9+
.settings
10+
.springBeans
11+
.sts4-cache
12+
13+
### IntelliJ IDEA ###
14+
.idea
15+
*.iws
16+
*.iml
17+
*.ipr
18+
19+
### NetBeans ###
20+
/nbproject/private/
21+
/nbbuild/
22+
/dist/
23+
/nbdist/
24+
/.nb-gradle/
25+
/build/
26+
27+
### VS Code ###
28+
.vscode/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<!--设置本项目的groupId artifactId 和版本信息-->
8+
<groupId>com.xingyun</groupId>
9+
<artifactId>learning-mybatis-xml-sample</artifactId>
10+
<version>1.0-SNAPSHOT</version>
11+
12+
<properties>
13+
<!-- 设置项目所使用的编码为UTF-8 -->
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
<!--设置项目所用JDK版本,也可以使用低版本,建议使用JDK1.8以上版本-->
16+
<java.version>1.8</java.version>
17+
<maven.compiler.source>${java.version}</maven.compiler.source>
18+
<maven.compiler.target>${java.version}</maven.compiler.target>
19+
<maven.compiler.plugin.version>3.5.1</maven.compiler.plugin.version>
20+
<!--是否跳过测试-->
21+
<skipTests>true</skipTests>
22+
<!--设置项目使用第三方依赖包,建议以后都采用这种方式,统一在一个地方声明版本号,这样对项目可以统一管理,方便以后升级-->
23+
<mybatis.version>3.5.2</mybatis.version>
24+
<h2.version>1.4.199</h2.version>
25+
<lombok.version>1.18.8</lombok.version>
26+
</properties>
27+
28+
<dependencies>
29+
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
30+
<dependency>
31+
<groupId>org.projectlombok</groupId>
32+
<artifactId>lombok</artifactId>
33+
<version>${lombok.version}</version>
34+
<scope>provided</scope>
35+
</dependency>
36+
<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
37+
<dependency>
38+
<groupId>org.mybatis</groupId>
39+
<artifactId>mybatis</artifactId>
40+
<version>${mybatis.version}</version>
41+
</dependency>
42+
<!-- https://mvnrepository.com/artifact/com.h2database/h2 -->
43+
<dependency>
44+
<groupId>com.h2database</groupId>
45+
<artifactId>h2</artifactId>
46+
<version>${h2.version}</version>
47+
<scope>runtime</scope>
48+
</dependency>
49+
</dependencies>
50+
51+
<build>
52+
<plugins>
53+
<!--该插件限定Maven 打包时所使用的版本,避免出现版本不匹配问题-->
54+
<plugin>
55+
<groupId>org.apache.maven.plugins</groupId>
56+
<artifactId>maven-compiler-plugin</artifactId>
57+
<version>${maven.compiler.plugin.version}</version>
58+
<configuration>
59+
<source>${java.version}</source>
60+
<target>${java.version}</target>
61+
</configuration>
62+
</plugin>
63+
</plugins>
64+
</build>
65+
66+
</project>

0 commit comments

Comments
 (0)