commit b161fcb07cce0fac520efbc30e0fecc1abec59ad Author: markma <750975972@qq.com> Date: Tue Aug 3 17:39:31 2021 +0800 0.0.1 Signed-off-by: markma <750975972@qq.com> diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..3f87023 --- /dev/null +++ b/.classpath @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..84c048a --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/build/ diff --git a/.project b/.project new file mode 100644 index 0000000..87523c4 --- /dev/null +++ b/.project @@ -0,0 +1,31 @@ + + + Hero-Select-Online + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + org.eclipse.wst.validation.validationbuilder + + + + + + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.jdt.core.javanature + org.eclipse.wst.jsdt.core.jsNature + + diff --git a/.settings/.jsdtscope b/.settings/.jsdtscope new file mode 100644 index 0000000..81672d4 --- /dev/null +++ b/.settings/.jsdtscope @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..3d6cbf0 --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding//src/main/webapp/index.jsp=UTF-8 diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..7adc0fb --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component new file mode 100644 index 0000000..3de29f1 --- /dev/null +++ b/.settings/org.eclipse.wst.common.component @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/.settings/org.eclipse.wst.common.project.facet.core.xml b/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..65f298b --- /dev/null +++ b/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/.settings/org.eclipse.wst.jsdt.ui.superType.container b/.settings/org.eclipse.wst.jsdt.ui.superType.container new file mode 100644 index 0000000..3bd5d0a --- /dev/null +++ b/.settings/org.eclipse.wst.jsdt.ui.superType.container @@ -0,0 +1 @@ +org.eclipse.wst.jsdt.launching.baseBrowserLibrary \ No newline at end of file diff --git a/.settings/org.eclipse.wst.jsdt.ui.superType.name b/.settings/org.eclipse.wst.jsdt.ui.superType.name new file mode 100644 index 0000000..05bd71b --- /dev/null +++ b/.settings/org.eclipse.wst.jsdt.ui.superType.name @@ -0,0 +1 @@ +Window \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..da45eb8 --- /dev/null +++ b/README.md @@ -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 + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..27f566b --- /dev/null +++ b/pom.xml @@ -0,0 +1,24 @@ + + 4.0.0 + com.markma + Markma-Hero-Select + 0.0.1-SNAPSHOT + + + org.mybatis + mybatis + 3.4.4 + + + org.mybatis + mybatis-spring + 1.3.0 + + + mysql + mysql-connector-java + 8.0.26 + + + + \ No newline at end of file diff --git a/src/main/java/controller/SelectServlet.java b/src/main/java/controller/SelectServlet.java new file mode 100644 index 0000000..532acb2 --- /dev/null +++ b/src/main/java/controller/SelectServlet.java @@ -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 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); + } + + + + + + } + +} diff --git a/src/main/java/dao/HeroDao.java b/src/main/java/dao/HeroDao.java new file mode 100644 index 0000000..7e98f85 --- /dev/null +++ b/src/main/java/dao/HeroDao.java @@ -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 find(String[] dividedName) + { + List heroList = new ArrayList(); + 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; + } +} diff --git a/src/main/java/dao/PropertiesDao.java b/src/main/java/dao/PropertiesDao.java new file mode 100644 index 0000000..e4096fc --- /dev/null +++ b/src/main/java/dao/PropertiesDao.java @@ -0,0 +1,32 @@ +package dao; + +import java.util.List; +import entity.Hero; +public class PropertiesDao +{ + public String[] find(List 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; + } +} + + diff --git a/src/main/java/entity/Hero.java b/src/main/java/entity/Hero.java new file mode 100644 index 0000000..2976a90 --- /dev/null +++ b/src/main/java/entity/Hero.java @@ -0,0 +1,196 @@ +package entity; +/** + * hero类 + * 包含hero的各项属性 + * 包含这些属性的get、set方法 + * 包含toString重写,输出全属性hero + * 包含partToString(),输出只有部分属性的hero + * @author markma + * @date 修改时间:2021年8月2日 上午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 find(@Param("name") String name); + @Select("SELECT * FROM heros") + List findAll(); + @Delete("DELETE * FROM heros WHERE name = #{name}") + void remove(String name); + @Update("") + void update(Hero b); +} \ No newline at end of file diff --git a/src/main/java/utils/NameProDivider.java b/src/main/java/utils/NameProDivider.java new file mode 100644 index 0000000..257701e --- /dev/null +++ b/src/main/java/utils/NameProDivider.java @@ -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(","); + } + +} diff --git a/src/main/java/utils/ReturnWriter.java b/src/main/java/utils/ReturnWriter.java new file mode 100644 index 0000000..0436ad3 --- /dev/null +++ b/src/main/java/utils/ReturnWriter.java @@ -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" + +"\n\n"); + for(String s:out) + { + fileWriter.write("

"+s+"

\n"); + } + + fileWriter.write("

"+"共找到"+ out.length + "条结果" +"

\n"); + fileWriter.write("\n\n"); + fileWriter.close(); + } +} diff --git a/src/main/java/utils/config.xml b/src/main/java/utils/config.xml new file mode 100644 index 0000000..bef44bc --- /dev/null +++ b/src/main/java/utils/config.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + diff --git a/src/main/webapp/META-INF/MANIFEST.MF b/src/main/webapp/META-INF/MANIFEST.MF new file mode 100644 index 0000000..254272e --- /dev/null +++ b/src/main/webapp/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Class-Path: + diff --git a/src/main/webapp/WEB-INF/lib/javax.servlet-api-4.0.1.jar b/src/main/webapp/WEB-INF/lib/javax.servlet-api-4.0.1.jar new file mode 100644 index 0000000..844ec7f Binary files /dev/null and b/src/main/webapp/WEB-INF/lib/javax.servlet-api-4.0.1.jar differ diff --git a/src/main/webapp/WEB-INF/lib/mybatis-3.5.7.jar b/src/main/webapp/WEB-INF/lib/mybatis-3.5.7.jar new file mode 100644 index 0000000..6edc13f Binary files /dev/null and b/src/main/webapp/WEB-INF/lib/mybatis-3.5.7.jar differ diff --git a/src/main/webapp/WEB-INF/lib/mysql-connector-java-8.0.26.jar b/src/main/webapp/WEB-INF/lib/mysql-connector-java-8.0.26.jar new file mode 100644 index 0000000..c5c07f6 Binary files /dev/null and b/src/main/webapp/WEB-INF/lib/mysql-connector-java-8.0.26.jar differ diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..4a4a551 --- /dev/null +++ b/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,22 @@ + + + Hero-Select-Online + + index.html + index.htm + index.jsp + default.html + default.htm + default.jsp + + + + SelectServlet + SelectServlet + controller.SelectServlet + + + SelectServlet + /SelectServlet + + \ No newline at end of file diff --git a/src/main/webapp/index.jsp b/src/main/webapp/index.jsp new file mode 100644 index 0000000..c9945f6 --- /dev/null +++ b/src/main/webapp/index.jsp @@ -0,0 +1,19 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> + + + +查询界面 + + +

三国查询系统1.0

+

属性:properties名称:姓名name,武器weaponName,生日birthday,卒日deathday,介绍introduction,ID ID,血量bloodValue,攻击力attackValue

+

查找多个人名,属性用英文逗号连接

+

例:刘备,曹操 ID,bloodValue

+

by markma

+
+ 查询对象:
+ 查询属性:
+
+
+ + diff --git a/src/main/webapp/return.jsp b/src/main/webapp/return.jsp new file mode 100644 index 0000000..380c902 --- /dev/null +++ b/src/main/webapp/return.jsp @@ -0,0 +1,7 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> + + +

Hero [name=刘备,ID=1]

+

共找到1条结果

+ +