From c6d75c0e41a18c9841deebcdda09cbc5a7ab8454 Mon Sep 17 00:00:00 2001 From: tamguo Date: Fri, 13 Jul 2018 14:10:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/tamguo/dao/ChapterMapper.java | 7 ++++ .../com/tamguo/service/IChapterService.java | 4 +- .../tamguo/service/impl/ChapterService.java | 40 +++++++++++++++++++ .../main/resources/mappers/ChapterMapper.xml | 6 +++ .../com/tamguo/ModifyChpaterQuestionNum.java | 29 ++++++++++++++ .../src/main/resources/static/js/subject.js | 2 +- 6 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 tamguo-crawler/src/main/java/com/tamguo/service/impl/ChapterService.java create mode 100644 tamguo-crawler/src/test/java/com/tamguo/ModifyChpaterQuestionNum.java diff --git a/tamguo-crawler/src/main/java/com/tamguo/dao/ChapterMapper.java b/tamguo-crawler/src/main/java/com/tamguo/dao/ChapterMapper.java index cc10c3d..28d0f6c 100644 --- a/tamguo-crawler/src/main/java/com/tamguo/dao/ChapterMapper.java +++ b/tamguo-crawler/src/main/java/com/tamguo/dao/ChapterMapper.java @@ -1,9 +1,16 @@ package com.tamguo.dao; +import java.util.List; + +import org.apache.ibatis.annotations.Param; + +import com.baomidou.mybatisplus.plugins.pagination.Pagination; import com.tamguo.config.dao.SuperMapper; import com.tamguo.model.ChapterEntity; public interface ChapterMapper extends SuperMapper{ + List queryList(Pagination questionPage); + Integer queryCount(@Param(value="uid")String uid); } diff --git a/tamguo-crawler/src/main/java/com/tamguo/service/IChapterService.java b/tamguo-crawler/src/main/java/com/tamguo/service/IChapterService.java index 33fa4a4..1c4a500 100644 --- a/tamguo-crawler/src/main/java/com/tamguo/service/IChapterService.java +++ b/tamguo-crawler/src/main/java/com/tamguo/service/IChapterService.java @@ -3,7 +3,7 @@ package com.tamguo.service; public interface IChapterService { /** - * 爬取章节数据 + * 修改章节数量 */ - void crawlerChapter(); + void modifyQuestionNum(); } diff --git a/tamguo-crawler/src/main/java/com/tamguo/service/impl/ChapterService.java b/tamguo-crawler/src/main/java/com/tamguo/service/impl/ChapterService.java new file mode 100644 index 0000000..faefc11 --- /dev/null +++ b/tamguo-crawler/src/main/java/com/tamguo/service/impl/ChapterService.java @@ -0,0 +1,40 @@ +package com.tamguo.service.impl; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.baomidou.mybatisplus.plugins.Page; +import com.tamguo.dao.ChapterMapper; +import com.tamguo.model.ChapterEntity; +import com.tamguo.service.IChapterService; + +@Service +public class ChapterService implements IChapterService{ + + @Autowired + ChapterMapper chapterMapper; + + @Override + public void modifyQuestionNum() { + int page = 1; + int pageSize = 1000; + while(true) { + Page chapterPage = new Page(page , pageSize); + List chapterList = chapterMapper.queryList(chapterPage); + for(int i=0 ;i + + \ No newline at end of file diff --git a/tamguo-crawler/src/test/java/com/tamguo/ModifyChpaterQuestionNum.java b/tamguo-crawler/src/test/java/com/tamguo/ModifyChpaterQuestionNum.java new file mode 100644 index 0000000..f7d19ca --- /dev/null +++ b/tamguo-crawler/src/test/java/com/tamguo/ModifyChpaterQuestionNum.java @@ -0,0 +1,29 @@ +package com.tamguo; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import com.tamguo.service.IChapterService; + +/** + * Num - 修改章节题目数量 + * + * @author tamguo + * + */ +@RunWith(SpringRunner.class) +@SpringBootTest +public class ModifyChpaterQuestionNum { + + @Autowired + IChapterService iChapterService; + + @Test + public void crawlerSubject() throws Exception { + iChapterService.modifyQuestionNum(); + } + +} diff --git a/tamguo/src/main/resources/static/js/subject.js b/tamguo/src/main/resources/static/js/subject.js index b408986..d08647f 100644 --- a/tamguo/src/main/resources/static/js/subject.js +++ b/tamguo/src/main/resources/static/js/subject.js @@ -17,7 +17,7 @@ $(function(){ var courseId = $(this).attr("courseid"); $.ajax({ type : "get", - url : mainHttp + "course/findChapter.html?courseId=" +courseId+".html", + url : mainHttp + "course/findChapter.html?courseId=" +courseId, async : true, dataType : "json", success : function(data) {// 返回数据根据结果进行相应的处理,无论请求成功还是失败,都会走这个方法的