发表于: 2018-01-18 21:54:18
1 588
一。插入两千万条数据还没有搞,试一下。
一开始,报SQL语句错误,You have an error in your SQL syntax; check the manual that corresponds to
然后我发现我写成逗号了,应该是分号。
"+"," +i+"英雄"+j+ "," + "," + 500 + "," + 40+"
,改好之后,接着运行,报错:
Field 'id' doesn't have a default value
意思是字段ID没有默认值。
百度一下原因,发现是ID忘了弄成自增的了
改好之后,继续运行。时间是187s:
打开数据库看一下有没有写进去:
下面看一看加了索引的。
mysql的索引有5种:主键索引、普通索引、唯一索引、全文索引、聚合索引(多列索引)。
唯一索引和全文索引用的很少,我们主要关注主键索引、普通索引和聚合索引。
1)主键索引:主键索引是加在主键上的索引,设置主键(primary key)的时候,mysql会自动创建主键索引;
2)普通索引:创建在非主键列上的索引;
3)聚合索引:创建在多列上的索引。
因为我ID用了主键,所以算是有索引。下面我把主键取消再试试。(不能取消主键,后来是在name上加了索引alter table hero add index(name);)
费时263秒。可以看到对比,加了name索引的两千万数据插入是263秒,比不加name索引的187秒慢了点。
二。pom.xml
注释掉一段的每一句话,选中那句话,
按住Ctrl,再按住啊斜杠,就行了
注释掉一段,选中那一段,按住shift+Ctrl,加斜杠,就可以变灰了
今天学了个骚操作,按住Maven Projects,按住啊倒数第三个,那个分支图,就会出来架构图。选定一个红线连接的,右键Exculed。
昨天找到爆红的问题,就是所有搜索都是版本问题的那个。今天我们把lib那个文件夹删除了,所有用到的jar包,都用pom表示。
问题就解决了,运行正常。
我要继续进行任务了,用注解的方式重新编译CategoryDao。
public int addCategoryByXML(Category category);
public void deleteCategoryByXML(int id);
public Category getCategoryByXML(int id);
public int updateCategoryByXML(Category category);
public List<Category> listCategoryByXML();
public int countCategoryByXML();
变成:
@Insert(" insert into category_( name ) values (#{name}) ")
public int addCategoryByAnnotation(Category category);
@Delete(" delete form category_ where id=#{id} ")
public void deleteCategoryByAnnotation(int id);
@Select("select * from category_ where id= #{id} ")//获取Category类本身
public Category getCategoryByAnnotation(int id);
@Update("update category_ set name=#{name} where id=#{id} ")
public int updateCategoryByAnnotation(Category category);
@Select(" select * from category_")//获取Category类本身
public List<Category> list();
add变成了addCategoryByAnnotation意思类的增加方法通过注释。
删掉Category.xml里面的这些内容
因为运行的时候,报错,说Mapped Statements collection already contains value for .......
目前知道有三个原因:
1.parameterMap改成parameterType...
2. id 重复
3 parameterType参数有问题
大概率是第二个原因,于是就把下面的内容删掉了。
</insert>
<delete id="deleteCategory" parameterType="Category">
delete from category_ where id= #{id}
</delete>
<select id="getCategory" parameterType="_int" resultType="Category">
select * from category_ where id= #{id}
</select>
<update id="updateCategory" parameterType="Category" >
update category_ set name=#{name} where id=#{id}
</update>
<select id="listCategory" resultType="Category">
select * from category_
</select>
最后Category.xml就变成了这个样子。
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.how2java.dao.CategoryDao">
</mapper>
运行,成功。如图:
是不是任务一就算完成了?
明天的计划:如果完成验收,就进行任务二
遇到的问题:基本上解决了
今天的收获:学会了加索引插入数据,完成了mybatis注解
java任务一开始时间:2017.12.05
预计demo时间:2018.01-05
可能有延期风险,原因是:已经延期了,基础比较差,
禅道链接地址:http://task.ptteng.com/zentao/project-task-501.html
评论