Skip to content

Commit a446c88

Browse files
committed
get paragraph order by score and rand
1 parent 619f3e0 commit a446c88

File tree

4 files changed

+40
-5
lines changed

4 files changed

+40
-5
lines changed

WebRoot/Article.jsp

+2
Original file line numberDiff line numberDiff line change
@@ -386,12 +386,14 @@ $(function(){
386386
<ul>
387387
<s:iterator value="#request.paragraph_list.get(0)" id="paragraph" status="st">
388388
<li><a href="#"><img width="630" height="210" src="images/pic_0x${st.index + 1}.jpg" alt="<s:property value="#paragraph.content"/>" /></a></li>
389+
<input type="text" style="display: none;" value="<s:property value="#paragraph.paragraph_id"/>">
389390
</s:iterator>
390391
<s:bean name="org.apache.struts2.util.Counter" id="counter">
391392
<s:param name="first" value="#request.paragraph_list.get(0).size() + 1" />
392393
<s:param name="last" value="5" />
393394
<s:iterator>
394395
<li><a href="#"><img width="630" height="210" src="images/pic_0<s:property/>.jpg" alt="" /></a></li>
396+
<input type="text" style="display: none;" value="-1">
395397
</s:iterator>
396398
</s:bean>
397399

Binary file not shown.

WebRoot/js/HTMLMaker.js

+15-4
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,27 @@ function starHTMLMaker(potitionId,id0,id1){
1515
var o=$('#'+potitionId);
1616
arr.push('<table><tr>');
1717
arr.push('<td>时间: 2010-03-16 <span class="pipe">|</span>评分:</td>');
18-
arr.push('<td><div id="star'+id0+id1+'" style="width:140px"/></td>');
19-
arr.push('<td><div id="result'+id0+id1+'" style="display:none"/></td>');//从这个id为result的div能够读到 当前用户评分的值
18+
//arr.push('<td><div id="star'+id0+id1+'" style="width:140px"/></td>');
19+
//arr.push('<td><div id="result'+id0+id1+'" style="display:none"/></td>');
20+
21+
arr.push('<td><form action="logout" method="post" target="id_iframe"><select id="pointList" name="pointList">');
22+
arr.push('<option value="1">1</option>');
23+
arr.push('<option value="2">2</option>');
24+
arr.push('<option value="3">3</option>');
25+
arr.push('<option value="4">4</option>');
26+
arr.push('<option value="5">5</option>');
27+
arr.push('</select>');
28+
arr.push('<input type="submit" value="提交" />');
29+
arr.push('</form>');
30+
arr.push('<iframe id="id_iframe" name="id_iframe" style="display:none;"></iframe>');
31+
2032
arr.push('</tr></table>');
2133
o.append(arr.join(' '));
2234
}
23-
//这个函数会调用上面两个函数来生成 评分以及评分上面的东西
2435
function starHTMLMakerGrounp(potition,id0,number){
2536
for(var i=0;i<number;i++){
2637
starHTMLMaker(potition+id0+i,id0,i);
27-
starOperation(id0,i);
38+
//starOperation(id0,i);
2839
}
2940
}
3041
//这个函数会用来生成"我的看法"

src/com/dao/impl/JournalDAOImpl.java

+23-1
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,35 @@ public List<List<Paragraph>> find_paragraph_of_chapter(Integer chapter_id) {
7676

7777

7878
for (int i = 0; i <= max_sequence; ++i) {
79+
hql = "from Paragraph paragraph where chapter_id = :chapter_id and sequence = :sequence order by paragraph.score desc";
80+
query = session.createQuery(hql);
81+
query.setInteger("chapter_id", chapter_id);
82+
query.setInteger("sequence", i);
83+
query.setFirstResult(0);
84+
query.setMaxResults(3);
85+
List<Paragraph> high_score_paragraphs = query.list();
7986
hql = "from Paragraph paragraph where chapter_id = :chapter_id and sequence = :sequence order by rand()";
8087
query = session.createQuery(hql);
8188
query.setInteger("chapter_id", chapter_id);
8289
query.setInteger("sequence", i);
8390
query.setFirstResult(0);
8491
query.setMaxResults(5);
85-
res.add(query.list());
92+
List<Paragraph> random_score_paragraphs = query.list();
93+
int count = 0;
94+
for (int j = 0; count < 2 && j < random_score_paragraphs.size(); ++j) {
95+
boolean isDuplicate = false;
96+
for (int k = 0; k < high_score_paragraphs.size(); ++k) {
97+
if(random_score_paragraphs.get(j).getParagraph_id() == high_score_paragraphs.get(k).getParagraph_id()) {
98+
isDuplicate = true;
99+
break;
100+
}
101+
}
102+
if (!isDuplicate) {
103+
high_score_paragraphs.add(random_score_paragraphs.get(j));
104+
++count;
105+
}
106+
}
107+
res.add(high_score_paragraphs);
86108
}
87109
session.close();
88110
return res;

0 commit comments

Comments
 (0)