commit
b161fcb07c
@ -0,0 +1,34 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="module" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="src" path="src/main/java"/>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v10.0">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="owner.project.facets" value="jst.web"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
|
||||||
|
<classpathentry kind="lib" path="C:/Users/lenovo/.m2/repository/org/mybatis/mybatis/3.4.4/mybatis-3.4.4.jar" sourcepath="C:/Users/lenovo/.m2/repository/org/mybatis/mybatis/3.4.4/mybatis-3.4.4-sources.jar">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
<attribute name="maven.groupId" value="org.mybatis"/>
|
||||||
|
<attribute name="maven.artifactId" value="mybatis"/>
|
||||||
|
<attribute name="maven.version" value="3.4.4"/>
|
||||||
|
<attribute name="maven.scope" value="compile"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="lib" path="src/main/webapp/WEB-INF/lib/mybatis-3.5.7.jar"/>
|
||||||
|
<classpathentry kind="lib" path="src/main/webapp/WEB-INF/lib/mysql-connector-java-8.0.26.jar"/>
|
||||||
|
<classpathentry kind="lib" path="D:/Tomcat 10.0/lib/servlet-api.jar">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="javadoc_location" value="https://docs.oracle.com/javaee/6/api/"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="lib" path="src/main/webapp/WEB-INF/lib/javax.servlet-api-4.0.1.jar"/>
|
||||||
|
<classpathentry kind="output" path="build/classes"/>
|
||||||
|
</classpath>
|
@ -0,0 +1 @@
|
|||||||
|
/build/
|
@ -0,0 +1,31 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>Hero-Select-Online</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.wst.common.project.facet.core.builder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.wst.validation.validationbuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
|
||||||
|
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
|
||||||
|
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry excluding="**/bower_components/*|**/node_modules/*|**/*.min.js" kind="src" path="src/main/webapp"/>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.WebProject">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="hide" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/>
|
||||||
|
<classpathentry kind="output" path=""/>
|
||||||
|
</classpath>
|
@ -0,0 +1,2 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
encoding//src/main/webapp/index.jsp=UTF-8
|
@ -0,0 +1,10 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
|
||||||
|
org.eclipse.jdt.core.compiler.compliance=11
|
||||||
|
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
|
||||||
|
org.eclipse.jdt.core.compiler.release=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.source=11
|
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
|
||||||
|
<wb-module deploy-name="Hero-Select-Online">
|
||||||
|
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
|
||||||
|
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
|
||||||
|
<property name="context-root" value="Hero-Select-Online"/>
|
||||||
|
<property name="java-output-path" value="/Hero-Select-Online/build/classes"/>
|
||||||
|
</wb-module>
|
||||||
|
</project-modules>
|
@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<faceted-project>
|
||||||
|
<runtime name="Apache Tomcat v10.0"/>
|
||||||
|
<fixed facet="jst.web"/>
|
||||||
|
<fixed facet="java"/>
|
||||||
|
<fixed facet="wst.jsdt.web"/>
|
||||||
|
<installed facet="java" version="11"/>
|
||||||
|
<installed facet="jst.web" version="2.5"/>
|
||||||
|
<installed facet="wst.jsdt.web" version="1.0"/>
|
||||||
|
</faceted-project>
|
@ -0,0 +1 @@
|
|||||||
|
org.eclipse.wst.jsdt.launching.baseBrowserLibrary
|
@ -0,0 +1 @@
|
|||||||
|
Window
|
@ -0,0 +1,24 @@
|
|||||||
|
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>com.markma</groupId>
|
||||||
|
<artifactId>Markma-Hero-Select</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mybatis</groupId>
|
||||||
|
<artifactId>mybatis</artifactId>
|
||||||
|
<version>3.4.4</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mybatis</groupId>
|
||||||
|
<artifactId>mybatis-spring</artifactId>
|
||||||
|
<version>1.3.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
|
<version>8.0.26</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,71 @@
|
|||||||
|
package controller;
|
||||||
|
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.Writer;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.http.HttpServlet;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import dao.*;
|
||||||
|
import entity.Hero;
|
||||||
|
import utils.*;
|
||||||
|
/**
|
||||||
|
* Servlet implementation class SelectServlet
|
||||||
|
*/
|
||||||
|
public class SelectServlet extends HttpServlet {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor.
|
||||||
|
*/
|
||||||
|
public SelectServlet() {
|
||||||
|
// TODO Auto-generated constructor stub
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
|
||||||
|
*/
|
||||||
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||||
|
{
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
//response.getWriter().append("Served at: ").append(request.getContextPath());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
|
||||||
|
*/
|
||||||
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
|
||||||
|
{
|
||||||
|
String undName = new String(request.getParameter("Name").getBytes("iso-8859-1"), "utf-8");
|
||||||
|
String undPro = new String(request.getParameter("Pro").getBytes("iso-8859-1"), "utf-8");
|
||||||
|
if(undName != null || undPro != null)
|
||||||
|
{
|
||||||
|
NameProDivider divNamePro = new NameProDivider(undName,undPro);
|
||||||
|
divNamePro.divideName();
|
||||||
|
divNamePro.dividePro();
|
||||||
|
|
||||||
|
HeroDao hd = new HeroDao();
|
||||||
|
List<Hero> heroList = hd.find(divNamePro.getDividedName());
|
||||||
|
|
||||||
|
PropertiesDao pd = new PropertiesDao();
|
||||||
|
String[] printHeroInfo = pd.find(heroList, divNamePro.getDividedProperties());
|
||||||
|
|
||||||
|
response.setCharacterEncoding("UTF-8");
|
||||||
|
response.setContentType("text/plain");
|
||||||
|
|
||||||
|
ReturnWriter returnwriter = new ReturnWriter();
|
||||||
|
returnwriter.write(printHeroInfo);
|
||||||
|
|
||||||
|
request.getRequestDispatcher("return.jsp").forward(request, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package dao;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import org.apache.ibatis.session.SqlSession;
|
||||||
|
import entity.*;
|
||||||
|
import utils.*;
|
||||||
|
public class HeroDao
|
||||||
|
{
|
||||||
|
public List<Hero> find(String[] dividedName)
|
||||||
|
{
|
||||||
|
List<Hero> heroList = new ArrayList<Hero>();
|
||||||
|
SqlSession session = DBUtils.getConnection();
|
||||||
|
HeroMapper mapper = session.getMapper(HeroMapper.class);
|
||||||
|
for(String name:dividedName)
|
||||||
|
{
|
||||||
|
if(name.equals("-a"))
|
||||||
|
{
|
||||||
|
heroList = mapper.findAll();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(mapper.find(name) != null)
|
||||||
|
{
|
||||||
|
heroList.addAll(mapper.find(name));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
session.commit();
|
||||||
|
return heroList;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package dao;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import entity.Hero;
|
||||||
|
public class PropertiesDao
|
||||||
|
{
|
||||||
|
public String[] find(List<Hero> heroList,String[] dividedPro)
|
||||||
|
{
|
||||||
|
String pro = dividedPro[0];
|
||||||
|
String[] findPro = new String[heroList.size()];
|
||||||
|
int j = 0;
|
||||||
|
if(pro.equals("-a"))
|
||||||
|
{
|
||||||
|
for (Hero i : heroList)
|
||||||
|
{
|
||||||
|
findPro[j] = i.toString();
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (Hero i : heroList)
|
||||||
|
{
|
||||||
|
findPro[j] = i.partToString(dividedPro);
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return findPro;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -0,0 +1,56 @@
|
|||||||
|
package utils;
|
||||||
|
/**
|
||||||
|
* Args分离函数
|
||||||
|
* 将用户输入的带逗号的查询方式分离到数组中去
|
||||||
|
* 例子:“刘备,曹操”->dividedName[0]="刘备",dividedName[1]="曹操"
|
||||||
|
* 例子:“ID,attackValue”->dividedProperties[0]="ID",dividedName[1]="attackValue"
|
||||||
|
* @author markma
|
||||||
|
* @date 修改时间:2021年8月2日 上午11:36:50
|
||||||
|
*/
|
||||||
|
public class NameProDivider
|
||||||
|
{
|
||||||
|
final int MAX_NAME = 1000,MAX_PRO = 1000;
|
||||||
|
String undividedName,undividedProperties;
|
||||||
|
String dividedName[],dividedProperties[];
|
||||||
|
public NameProDivider()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] getDividedName()
|
||||||
|
{
|
||||||
|
return dividedName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDividedName(String[] dividedName)
|
||||||
|
{
|
||||||
|
this.dividedName = dividedName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] getDividedProperties()
|
||||||
|
{
|
||||||
|
return dividedProperties;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDividedProperties(String[] dividedProperties)
|
||||||
|
{
|
||||||
|
this.dividedProperties = dividedProperties;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NameProDivider(String mainUndName,String mainUndProperties)
|
||||||
|
{
|
||||||
|
undividedName = mainUndName;
|
||||||
|
undividedProperties = mainUndProperties;
|
||||||
|
}
|
||||||
|
public void divideName()
|
||||||
|
{
|
||||||
|
dividedName = new String[MAX_NAME];
|
||||||
|
dividedName = undividedName.split(",");
|
||||||
|
}
|
||||||
|
public void dividePro()
|
||||||
|
{
|
||||||
|
dividedProperties = new String[MAX_PRO];
|
||||||
|
dividedProperties = undividedProperties.split(",");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
package utils;
|
||||||
|
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class ReturnWriter
|
||||||
|
{
|
||||||
|
public void write(String [] out) throws IOException
|
||||||
|
{
|
||||||
|
FileWriter fileWriterClear = new FileWriter("D:\\eclipse-workspace\\Hero-Select-Online\\src\\main\\webapp\\return.jsp");
|
||||||
|
fileWriterClear.close();
|
||||||
|
|
||||||
|
FileWriter fileWriter = new FileWriter("D:\\eclipse-workspace\\Hero-Select-Online\\src\\main\\webapp\\return.jsp",true);
|
||||||
|
fileWriter.write("<%@ page language=\"java\" contentType=\"text/html; charset=UTF-8\" pageEncoding=\"UTF-8\"%>\n"
|
||||||
|
+"<html>\n<body>\n");
|
||||||
|
for(String s:out)
|
||||||
|
{
|
||||||
|
fileWriter.write("<p>"+s+"</p>\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
fileWriter.write("<p>"+"共找到"+ out.length + "条结果" +"</p>\n");
|
||||||
|
fileWriter.write("</body>\n</html>\n");
|
||||||
|
fileWriter.close();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE configuration
|
||||||
|
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-config.dtd">
|
||||||
|
<configuration>
|
||||||
|
<environments default="development">
|
||||||
|
<environment id="development">
|
||||||
|
<transactionManager type="JDBC"/>
|
||||||
|
<dataSource type="POOLED">
|
||||||
|
<property name="driver" value="com.mysql.cj.jdbc.Driver"/>
|
||||||
|
<property name="url" value="jdbc:mysql://127.0.0.1:3306/test"/>
|
||||||
|
<property name="username" value="root"/>
|
||||||
|
<property name="password" value="root"/>
|
||||||
|
</dataSource>
|
||||||
|
</environment>
|
||||||
|
</environments>
|
||||||
|
<mappers>
|
||||||
|
<package name="utils"/>
|
||||||
|
</mappers>
|
||||||
|
</configuration>
|
@ -0,0 +1,3 @@
|
|||||||
|
Manifest-Version: 1.0
|
||||||
|
Class-Path:
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,22 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://JAVA.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
|
||||||
|
<display-name>Hero-Select-Online</display-name>
|
||||||
|
<welcome-file-list>
|
||||||
|
<welcome-file>index.html</welcome-file>
|
||||||
|
<welcome-file>index.htm</welcome-file>
|
||||||
|
<welcome-file>index.jsp</welcome-file>
|
||||||
|
<welcome-file>default.html</welcome-file>
|
||||||
|
<welcome-file>default.htm</welcome-file>
|
||||||
|
<welcome-file>default.jsp</welcome-file>
|
||||||
|
</welcome-file-list>
|
||||||
|
<servlet>
|
||||||
|
<description></description>
|
||||||
|
<display-name>SelectServlet</display-name>
|
||||||
|
<servlet-name>SelectServlet</servlet-name>
|
||||||
|
<servlet-class>controller.SelectServlet</servlet-class>
|
||||||
|
</servlet>
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>SelectServlet</servlet-name>
|
||||||
|
<url-pattern>/SelectServlet</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
</web-app>
|
@ -0,0 +1,19 @@
|
|||||||
|
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||||
|
<title>查询界面</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<p>三国查询系统1.0</p>
|
||||||
|
<p>属性:properties名称:姓名name,武器weaponName,生日birthday,卒日deathday,介绍introduction,ID ID,血量bloodValue,攻击力attackValue</p>
|
||||||
|
<p>查找多个人名,属性用英文逗号连接</p>
|
||||||
|
<p>例:刘备,曹操 ID,bloodValue</p>
|
||||||
|
<p>by markma</p>
|
||||||
|
<form action="SelectServlet" method="post">
|
||||||
|
查询对象:<input type="text" id="heroId" name="Name" placeholder="输入对象姓名" /><br>
|
||||||
|
查询属性:<input type="text" id="proId" name="Pro" placeholder="输入查询属性" /><br>
|
||||||
|
<button type="submit">查询</button><br>
|
||||||
|
</form>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -0,0 +1,7 @@
|
|||||||
|
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
|
||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
<p>Hero [name=刘备,ID=1]</p>
|
||||||
|
<p>共找到1条结果</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in new issue