Database definition is this.
Background check code segment is that, more complicated, mainly through floorid, and pid loop query to obtain all the data we want, and we want spliced into a string according to certain rules.
Returned to the front on display treatment, may be better solved using a recursive tree, or maintain a path list, add data, other methods, there is no tried, for the first time developed today, first with the most common method tried it , uses a triple loop, if extended one level, we should add a heavy cycle, but our project, up to only about 3 layers, it is up to triple loop, although it is true, but is relatively unpopular.
public String getAllChapterQuestionbankTitle(@RequestParam(value = "subject", required = false) String subject) { System.out.println("all floors --- begin!\n"); System.out.println(subject); String resultStr = ""; subjectMapper sub = subjectService.selectBySubjectName(subject); System.out.println(sub.toString()); String subjectid = sub.getSubjectid(); System.out.println(subjectid); // Get the code portion of the section module List<floorMapper> floors = floorService.selectBySubjectId(subjectid); List<floorMapper> tempfloors = new ArrayList<floorMapper>(); System.out.println(floors); System.out.println("all floors --- \n"); // Find out the section appeared in the parent node is the beginning of each chapter, to add to the collection set if (floors != null && floors.size() > 0) { for (int i = 0; i < floors.size(); i++) { System.out.println(floors.get(i).toString()); int pid = floors.get(i).getPid(); floorMapper floor = floorService.selectByPrimaryKey(pid); if(floor.getFloorid()==floor.getPid()) tempfloors.add(floor); } } List<floorMapper> resultfloors = new ArrayList<floorMapper>(); resultfloors = removeDuplicateFlight(tempfloors); // Get the chapter for (int index = 0; index < resultfloors.size(); index++) { // here to request the contents of each chapter, a chapter to get here, once again get to the festival section int pid = resultfloors.get(index).getFloorid(); // first chapter splicing name resultStr +=resultfloors.get(index).getFloorname()+"【章】"; List<floorMapper> joins = floorService.selectByParentId(pid); joins = removeDuplicateFlight(joins); if(joins!=null) { // Get the Festival, the first festival names splicing for (int subindex = 0; subindex < joins.size(); subindex++) { // here to get to the festival, and once again get into the module section int pid2 = joins.get(subindex).getFloorid(); List<floorMapper> subjoins = floorService.selectByParentId(pid2); // Get some subjoins = removeDuplicateFlight(subjoins); if(subjoins!=null) { // Get the acquisition of parts, the first part of the mosaic acquired the name for (int k=0;k<subjoins.size();k++){ resultStr += subjoins.get(k).getFloorname()+"【部分】"; // No next level up! } } resultStr += joins.get(subindex).getFloorname()+"【节】"; } } // from each chapter, and obtaining the contents of each section /* resultStr += resultfloors.get(index).getFloorname() + ":" + resultfloors.get(index).getTitlenumber() +":"+ resultfloors.get(index).getState()+ "#"; */ resultStr +="#"; } resultStr = resultStr.substring(0, resultStr.length() - 1); return resultStr; }
Next is the front end of the rear end of the return data parsing,
The data returned is
The first chapter [chapter] [Day] the first part of the first [part II] [section] [section] Chapter III # [section] [section] Section this format,
And then manipulate it,
var len=""; $(document).ready(function () { // just come in requesting data about chapters, involves the floor table, questionbankid table, title list, option table, answer the table, analyse table // first call at floor level meter bar, floor linked to the subjectid, also linked to the questionbankid. var subject = $("#subject").text(); alert(subject); $.ajax({ type: 'Post', url: "/getAllChapterQuestionbankTitle", timeout: 0, async: false, contentType: "application/x-www-form-urlencoded; charset=UTF-8", data: { subject: subject }, success: function (result) { // Returns a string Information section var arrayList = new Array(1000); arrayList = result.split("#"); // returns xxxxx xxxxx [section] [section] array of strings // stitching each chapter information to a page showing X for (var index = 0; index < arrayList.length; index++) { var htmlstr = ""; var zhangjie = arrayList[index].split("【章】"); htmlstr += "<li><div style=\"background-color:#ccc;font-color:white;\" class=\"li\">" + zhangjie[0] + "<span style=\"background-color:white;z-index:99999;float:right;width:25px;height:25px;border:2px solid black;\" ><img th:src='@{/images/4.jpg}'></span></div>"; htmlstr += " <div class=\"else\">"; var lastjie = zhangjie[1].lastIndexOf("【节】"); var jiestr = zhangjie [1] .substring (0, lastjie); // Get Section X X X Day Day var mokuaistr = zhangjie [1] .substring (lastjie, zhangjie [1] .length); // after the section module var jiestrs = jiestr.split ( "[Section]"); for (var i = 0; i < jiestrs.length; i++) { // To determine whether this string section containing [section], len = 0; // initially assigned the value 0 if (jiestrs [i] .indexOf ( "[section]")> 0) {// containing portion, the sub-portion made of string len = 1; // As long as there have been a part of it assigned to 1 var lastbufen = jiestrs[i].lastIndexOf("【部分】"); var jiesubstr = jiestrs[i].substring(lastbufen, jiestrs[i].length); var bufen = jiestrs [i] .substring (0, lastbufen); // Get the foregoing substring [section] jiestrs [i] = jiesubstr.substring (4, jiesubstr.length); // re-assigned to a section of the string } if(bufen!="") { if (bufen.indexOf("【部分】") > 0) { // more than one part, split it var bufenstrs = bufen.split ( "[section]"); len = bufenstrs.length; // depending on how many parts the length provided } } if (i == 0) {// first htmlstr += "<div class=\"else-list first\" style='height:"+(len+1)*35+"px;'>" + jiestrs[i]+"<span style=\"background-color:white;z-index:99999;float:right;width:25px;height:25px;border:2px solid black;\" ><img th:src='@{/images/4.jpg}'></span>"; // add the next level section if(bufen!=""){ if (bufen.indexOf("【部分】") > 0){ // more than one part, split it var bufenstrs = bufen.split ( "[section]"); for(var per = 0 ;per<bufenstrs.length;per++){ if(per == 0) { htmlstr += "<div class=\"bufen first\">" + bufenstrs[per] + "<span style=\"background-color:white;z-index:99999;float:right;width:25px;height:25px;border:2px solid black;\" ><img th:src='@{/images/4.jpg}'></span></div>"; }else{ htmlstr += "<div class=\"bufen\">" + bufenstrs[per] + "<span style=\"background-color:white;z-index:99999;float:right;width:25px;height:25px;border:2px solid black;\" ><img th:src='@{/images/4.jpg}'></span></div>"; } } }else{ htmlstr += "<div class=\"bufen first\">" + bufen + "<span style=\"background-color:white;z-index:99999;float:right;width:25px;height:25px;border:2px solid black;\" ><img th:src='@{/images/4.jpg}'></span></div>"; } } bufen = ""; htmlstr += "</div>"; } else { htmlstr += "<div class=\"else-list first\" style='height:"+(len+1)*35+"px;'>" + jiestrs[i]+"<span style=\"background-color:white;z-index:99999;float:right;width:25px;height:25px;border:2px solid black;\" ><img th:src='@{/images/4.jpg}'></span>"; // add the next level section if(bufen!=""){ if (bufen.indexOf("【部分】") > 0){ // more than one part, split it var bufenstrs = bufen.split ( "[section]"); for(var per = 0 ;per<bufenstrs.length;per++){ if(per == 0) { htmlstr += "<div class=\"bufen first\">" + bufenstrs[per] + "<span style=\"background-color:white;z-index:99999;float:right;width:25px;height:25px;border:2px solid black;\"><img th:src='@{/images/4.jpg}'></span></div>"; }else{ htmlstr += "<div class=\"bufen\">" + bufenstrs[per] + "<span style=\"background-color:white;z-index:99999;float:right;width:25px;height:25px;border:2px solid black;\"><img th:src='@{/images/4.jpg}'></span></div>"; } } }else{ htmlstr += "<div class=\"bufen first\">" + bufen + "<span style=\"background-color:white;z-index:99999;float:right;width:25px;height:25px;border:2px solid black;\"><img th:src='@{/images/4.jpg}'></span></div>"; } } bufen = ""; htmlstr += "</div>"; } } htmlstr += " </div ></id>"; $(".list").append(htmlstr); } }, error: function (error) { } }); });
The whole process is very complex resolution, requires a lot of patience to complete, but if this is not the first to write code to write, still a novice, definitely will not be completed in this way, the current needs of the project is simply to meet the estimated over time, it was reconstructed, under the record of tedious code is recorded, a practice regarded as the process of it.