forked from pghs975uc/Markma-Hero-Select
commit
7670366989
@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="test" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="test" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<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="output" path="target/classes"/>
|
||||
</classpath>
|
@ -0,0 +1 @@
|
||||
/target/
|
@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>Markma-Hero-Select</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
@ -0,0 +1,8 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
|
||||
org.eclipse.jdt.core.compiler.compliance=1.5
|
||||
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
|
||||
org.eclipse.jdt.core.compiler.release=disabled
|
||||
org.eclipse.jdt.core.compiler.source=1.5
|
@ -0,0 +1,4 @@
|
||||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
resolveWorkspaceProjects=true
|
||||
version=1
|
@ -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,11 @@
|
||||
|
||||
import tools.ArgsHandler;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
ArgsHandler argsHandler = new ArgsHandler(args);
|
||||
argsHandler.switchModel();
|
||||
}
|
||||
}
|
@ -0,0 +1,188 @@
|
||||
package hero;
|
||||
|
||||
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 hero;
|
||||
|
||||
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;
|
||||
|
||||
/*
|
||||
* 映射 SQL方法
|
||||
*/
|
||||
public interface HeroMapper
|
||||
{
|
||||
/*int ID,
|
||||
int bloodValue,
|
||||
int attackValue,
|
||||
String name,
|
||||
String weaponName,
|
||||
String birthday,
|
||||
String deathday,
|
||||
String introduction*/
|
||||
@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("")
|
||||
void remove(String title);
|
||||
@Update("")
|
||||
void update(Hero b);
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package tools;
|
||||
public class ArgsDivider
|
||||
{
|
||||
final int MAX_NAME = 1000,MAX_PRO = 1000;
|
||||
String undividedName,undividedProperties;
|
||||
String dividedName[],dividedProperties[];
|
||||
public ArgsDivider()
|
||||
{
|
||||
|
||||
}
|
||||
public ArgsDivider(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,78 @@
|
||||
package tools;
|
||||
|
||||
public class ArgsHandler
|
||||
{
|
||||
String args[];
|
||||
final String VERSION = "0.0.1";
|
||||
public ArgsHandler()
|
||||
{
|
||||
|
||||
}
|
||||
public ArgsHandler(String mainArgs[])
|
||||
{
|
||||
args = new String[mainArgs.length];
|
||||
System.arraycopy(mainArgs, 0, args, 0, mainArgs.length);
|
||||
}
|
||||
public void printHelp()
|
||||
{
|
||||
System.out.println("-s name properties 搜索模式");
|
||||
System.out.println("多个name和properties用,连接 查询全部为-a");
|
||||
System.out.println("properties名称:姓名name,武器weaponName,生日birthday,卒日deathday,"
|
||||
+ "介绍introduction,ID ID,血量bloodValue,攻击力attackValue");
|
||||
System.out.println("例: -s 刘备,曹操 ID,bloodValue");
|
||||
System.out.println("例: -s -a ID");
|
||||
System.out.println("-v 显示版本");
|
||||
return;
|
||||
}
|
||||
public void switchModel()
|
||||
{
|
||||
switch(args.length)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
System.out.println("三国人物查找系统");
|
||||
System.out.println("命令后缀名:");
|
||||
printHelp();
|
||||
return;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
if(args[0].equals("-v"))
|
||||
{
|
||||
System.out.println("version:"+VERSION);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("后缀名输入错误");
|
||||
printHelp();
|
||||
return;
|
||||
}
|
||||
}
|
||||
case 3:
|
||||
{
|
||||
if(args[0].equals("-s"))
|
||||
{
|
||||
ArgsDivider argsDivider = new ArgsDivider(args[1],args[2]);
|
||||
argsDivider.divideName();
|
||||
argsDivider.dividePro();
|
||||
SQLReader sqlReader = new SQLReader();
|
||||
sqlReader.read(argsDivider.dividedName, argsDivider.dividedProperties);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("后缀名输入错误");
|
||||
printHelp();
|
||||
return;
|
||||
}
|
||||
}
|
||||
default:
|
||||
{
|
||||
System.out.println("后缀名数目输入错误");
|
||||
printHelp();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
package tools;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.io.Resources;
|
||||
import org.apache.ibatis.session.SqlSession;
|
||||
import org.apache.ibatis.session.SqlSessionFactory;
|
||||
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
|
||||
|
||||
import hero.Hero;
|
||||
import hero.HeroMapper;
|
||||
|
||||
public class SQLReader
|
||||
{
|
||||
public SQLReader()
|
||||
{
|
||||
|
||||
}
|
||||
public void read(String [] dividedName,String [] dividedPro)
|
||||
{
|
||||
try
|
||||
{
|
||||
SqlSessionFactory factory = new SqlSessionFactoryBuilder()
|
||||
.build(Resources.getResourceAsReader("tools/config.xml"));
|
||||
|
||||
// 一次会话
|
||||
// Connection
|
||||
SqlSession session = factory.openSession();
|
||||
|
||||
// 获得了接口的一个具体实现(实例)
|
||||
// mybatis 根据注解创建了接口的实力
|
||||
HeroMapper mapper = session.getMapper(HeroMapper.class);
|
||||
List<Hero> heroList = new ArrayList<Hero>();
|
||||
for(String name:dividedName)
|
||||
{
|
||||
if(name.equals("-a"))
|
||||
{
|
||||
heroList = mapper.findAll();
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(mapper.find(name) != null)
|
||||
{
|
||||
heroList.addAll(mapper.find(name));
|
||||
}
|
||||
}
|
||||
}
|
||||
String pro = dividedPro[0];
|
||||
if(pro.equals("-a"))
|
||||
{
|
||||
for (Hero i : heroList)
|
||||
{
|
||||
System.out.println(i);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (Hero i : heroList)
|
||||
{
|
||||
System.out.println(i.partToString(dividedPro));
|
||||
}
|
||||
}
|
||||
|
||||
// 会话提交
|
||||
session.commit();
|
||||
System.out.println("查询完毕,共找到"+heroList.size()+"条结果");
|
||||
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -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="hero"/>
|
||||
</mappers>
|
||||
</configuration>
|
Loading…
Reference in new issue