Signed-off-by: markma <750975972@qq.com>
master
markma 4 years ago
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>

1
.gitignore vendored

@ -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,8 @@
该程序是用来筛选数据库上的武将信息,带网页版。
有关该项目资料的查询https://www.wolai.com/81653LDk4k71WzqBnokQ5r?theme=light
我的其他项目资料https://www.wolai.com/k3a8LkCjN8xnEKTvKYPqum?theme=light
https://www.wolai.com/tqqpCNJ3U7jUHCPx13Qorx?theme=light

@ -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,196 @@
package entity;
/**
* hero
* hero
* getset
* toStringhero
* partToString()hero
* @author markma
* @date :202182 11:44:07
*/
public class Hero {
final String COLORCODE = "31";
private int ID = 0,
bloodValue = 0,
attackValue = 0;
private String name = "",
weaponName = "",
birthday = "",
deathday = "",
introduction = "";
// create table books(id int primary key auto_increment,title varchar(40),author varchar(40),price int);
public Hero()
{
}
public Hero(int ID,
int bloodValue,
int attackValue,
String name,
String weaponName,
String birthday,
String deathday,
String introduction)
{
super();
this.ID = ID;
this.bloodValue = bloodValue;
this.attackValue = attackValue;
this.name = name;
this.weaponName = weaponName;
this.birthday = birthday;
this.deathday = deathday;
this.introduction = introduction;
}
public int getID()
{
return ID;
}
public void setID(int iD)
{
ID = iD;
}
public int getBloodValue()
{
return bloodValue;
}
public void setBloodValue(int bloodValue)
{
this.bloodValue = bloodValue;
}
public int getAttackValue()
{
return attackValue;
}
public void setAttackValue(int attackValue)
{
this.attackValue = attackValue;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public String getWeaponName()
{
return weaponName;
}
public void setWeaponName(String weaponName)
{
this.weaponName = weaponName;
}
public String getBirthday()
{
return birthday;
}
public void setBirthday(String birthday)
{
this.birthday = birthday;
}
public String getDeathday()
{
return deathday;
}
public void setDeathday(String deathday)
{
this.deathday = deathday;
}
public String getIntroduction()
{
return introduction;
}
public void setIntroduction(String introduction)
{
this.introduction = introduction;
}
@Override
public String toString()
{
return "Hero [ID=" + ID
+ ", bloodValue=" + bloodValue
+ ", attackValue=" + attackValue
+ ", name=" + name
+ ", weaponName=" + weaponName
+ ", birthday=" + birthday
+ ", deathday=" + deathday
+ ", introduction=" + introduction
+ "]";
}
public String partToString(String dividedPro[])
{
String printString = "Hero [";
printString += "name=";
printString += name;
printString += ",";
//String pro:dividedPro
for(int i = 0;i<dividedPro.length;i++)
{
String pro = dividedPro[i];
if(pro.equals("weaponName"))
{
printString += "weaponName=";
printString += weaponName;
}
if(pro.equals("birthday"))
{
printString += "birthday=";
printString += birthday;
}
if(pro.equals("deathday"))
{
printString += "deathday=";
printString += deathday;
}
if(pro.equals("introduction"))
{
printString += "introduction=";
printString += introduction;
}
if(pro.equals("ID"))
{
printString += "ID=";
printString += ID;
}
if(pro.equals("bloodValue"))
{
printString += "bloodValue=";
printString += bloodValue;
}
if(pro.equals("attackValue"))
{
printString += "attackValue=";
printString += attackValue;
}
if(i != dividedPro.length-1)
{
printString += ",";
}
}
printString += "]";
return printString;
}
}

@ -0,0 +1,35 @@
package utils;
import java.io.IOException;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
//controller层调用 service层 service层在调用dao层dao层处理完数据返回 service层 service层在返回controller层controller层最终返回前端。
public class DBUtils
{
public static SqlSession getConnection()
{
SqlSession session = null;
try
{
SqlSessionFactory factory = new SqlSessionFactoryBuilder()
.build(Resources.getResourceAsReader("utils/config.xml"));
// 一次会话
// Connection
session = factory.openSession();
// 获得了接口的一个具体实现(实例)
// mybatis 根据注解创建了接口的实例
}
catch (IOException e)
{
e.printStackTrace();
}
return session;
}
}

@ -0,0 +1,38 @@
package utils;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import entity.Hero;
/**
* HeroMapperSQL
*
* savehero
* findhero
* findAllhero
* remove:hero
* update:hero)
* @author markma
* @date :202182 11:47:18
*/
public interface HeroMapper
{
@Insert("insert into heros(ID,bloodValue,attackValue,name,weaponName,birthday,deathday,introduction) "
+ "values(#{ID}, #{bloodValue}, #{attackValue},#{name},#{weaponName},#{birthday},#{deathday},#{introduction})")
void save(Hero b);
@Select("SELECT * FROM heros WHERE name = #{name}")
List<Hero> find(@Param("name") String name);
@Select("SELECT * FROM heros")
List<Hero> findAll();
@Delete("DELETE * FROM heros WHERE name = #{name}")
void remove(String name);
@Update("")
void update(Hero b);
}

@ -0,0 +1,56 @@
package utils;
/**
* Args
*
* :,->dividedName[0]="刘备",dividedName[1]="曹操"
* :ID,attackValue->dividedProperties[0]="ID",dividedName[1]="attackValue"
* @author markma
* @date :202182 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:

@ -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…
Cancel
Save