360首页检索小说效果如下:
个人完成编写的schoolnet校园网主页如下
在小说模块中,包括:小说类别编号:a、校园爱情 b、动漫同人 c、校园魔法 d、轻小说 e、校园励志 f、校园修真 g、名人传记 h、古典小说 i、 国外小说。小说状态:a、连载中 b、已完结。用户可以阅读完整小说、添加小说进入书架、查看目录、投推荐票(限制只能投一次),用户有权管理自己的书架。
页面效果如下:
1、
2、
3、
4、
5、
数据库相关表设计:
xiaoshuo小说表:包含主键id、小说类别编号typeid、小说状态state、小说标题title、小说文档docu、小说推荐率recommend、点击次数click、小说描述content、更新时间creTime、小说封面photo等。
xiaoshuotype小说分类表:包含主键id、类别名称name。
bookrack书架表:包含主键id、用户userid、小说xiaoshuoid。
votereco小说推荐投票表:包含主键id、用户userid、小说xiaoshuoid
1、小说主页面html代码
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
校园小说页面_校园网
2、小说详情页面html代码
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
校园小说页面_校园网
3、小说章数目录页面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
校园小说页面_校园网
4、小说内容阅读页面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
校园新小说页面_校园网
相关java代码
int PagesSize=10;
String pageNow=request.getParameter("pageNow");
String id=request.getParameter("id");
//选择小说类型为全部
if("all".equals(id)){
//分页查询
int pageNows=Integer.valueOf(pageNow);
int allrows=userService.queryallrows("from Xiaoshuo", null);
int PageCount=(allrows-1)/PagesSize+1;
if(pageNows<1)
{
pageNows=1;
}
if(pageNows>PageCount)
{
pageNows=PageCount;
}
//获取小说
List xiaoshuos=userService.executeQueryByPage("from Xiaoshuo order by id desc", null, pageNows, PagesSize);
//获取小说分类
List xiaoshuotypes=userService.getResult("from Xiaoshuotype", null);
request.setAttribute("xiaoshuotypes", xiaoshuotypes);
request.setAttribute("xiaoshuos", xiaoshuos);
request.setAttribute("pageNow", pageNows);
request.setAttribute("PageCount", PageCount);
request.setAttribute("allrows", allrows);
}
//获取连载中的小说
else if("lianzai".equals(xiaoshuotypeid)){
List xiaoshuos=universityService.executeQueryByPage("from Xiaoshuo where state=1 order by id desc", null, pageNow, pageSize);
}
//获取已完结的小说
else if("wanjie".equals(xiaoshuotypeid)){
List xiaoshuos=universityService.executeQueryByPage("from Xiaoshuo where state=2 order by id desc", null, pageNow, pageSize);
}
//选择小说类型为单类
else {
int pageNows=Integer.valueOf(pageNow);
int allrows=userService.queryallrows("from Xiaoshuo where xiaoshuotype.id=?", new Object[]{Integer.valueOf(id)});
int PageCount=(allrows-1)/PagesSize+1;
if(pageNows<1)
{
pageNows=1;
}
if(pageNows>PageCount)
{
pageNows=PageCount;
}
List xiaoshuos=userService.executeQueryByPage("from Xiaoshuo where xiaoshuotype.id=? order by id desc", new Object[]{Integer.valueOf(id)}, pageNows, PagesSize);
List xiaoshuotypes=userService.getResult("from Xiaoshuotype", null);
request.setAttribute("xiaoshuotypes", xiaoshuotypes);
request.setAttribute("xiaoshuos", xiaoshuos);
request.setAttribute("pageNow", pageNows);
request.setAttribute("PageCount", PageCount);
request.setAttribute("allrows", allrows);
}
String id=request.getParameter("id");
Xiaoshuo xiaoshuo=(Xiaoshuo) userService.findById(Xiaoshuo.class, Integer.valueOf(id));
request.setAttribute("xiaoshuo", xiaoshuo);
String docu=xiaoshuo.getDocu();
StringBuffer sb=GetContent.uploadHead(request,docu);
Pattern p = Pattern.compile("第[一二三四五六七八九十百千]{5}章 ");
Matcher m = p.matcher(sb);
int count =0;
int count1=Integer.valueOf(request.getParameter("pageNow"));
while(m.find()){
count ++;
}
if(count1<1)
{
count1=1;
}
if(count1>count)
{
count1=count;
}
if(count1<=count)
{
//将阿拉伯数值转成中文数值
String result=ChinUtil.toChin(String.valueOf(count1));
String result2=ChinUtil.toChin(String.valueOf(count1+1));
//截取两章之间的内容
String sb1=sb.toString().substring(sb.indexOf("第"+result+"章"), sb.indexOf("第"+result2+"章"));
request.setAttribute("str", sb1);
request.setAttribute("page", count1);
}
request.setAttribute("count", count);
GetContent.java
public class GetContent {
public static StringBuffer uploadHead(HttpServletRequest request,String docu){
StringBuffer sb = new StringBuffer();
try{
//filePath就是当前这个web应用是绝对路径
String filepath=request.getSession().getServletContext().getRealPath("/");
File f2=new File(filepath+"\\Media\\txt\\"+docu);
BufferedReader bReader=new BufferedReader(new FileReader(f2));
while (true) {
String str = bReader.readLine();
if (str != null) {
sb.append(str + "
");
}
if (str == null) {
break;
}
}
} catch (Exception e) {
e.printStackTrace();
}
return sb;
}
}
ChinUtil.java
public class ChinUtil{
public static String toChin(String string) {
String nums[]={"0","1","2","3","4","5","6","7","8","9"};
String chines[]={"零","一","二","三","四","五","六","七","八","九"};
String level[]={"十","百","千","万","十","百","千","亿"};
//不算进制,直接将阿拉伯数值转中文数字
for (int i = 0; i < nums.length; i++) {
string=string.replaceAll(nums[i], chines[i]);
}
System.out.println(string);
StringBuffer stringBuffer=new StringBuffer(string);
//插入十进制单位
for (int i = 0; i < string.length()-1; i++) {
stringBuffer.insert(string.length()-1-i, level[i]);
}
System.out.println(stringBuffer.toString());
String temp = new String(stringBuffer.toString());
//处理零的情况
while((temp.indexOf("零万")!=-1)||(temp.indexOf("零千")!=-1)||(temp.indexOf("零百")!=-1)||(temp.indexOf("零十")!=-1)||(temp.indexOf("零零")!=-1)){
if(temp.indexOf("零千")!=-1){
temp = temp.replaceAll("零千","零");
}
if(temp.indexOf("零百")!=-1){
temp = temp.replaceAll("零百","零");
}
if(temp.indexOf("零十")!=-1){
temp = temp.replaceAll("零十","零");
}
if(temp.indexOf("零零")!=-1){
temp = temp.replaceAll("零零","零");
}
if((temp.indexOf("零万")!=-1)){
temp = temp.replaceAll("零万","万");
}
}
//处理个位为零的情况
if(temp.lastIndexOf("零")==temp.length()-1){
temp = temp.substring(0,temp.length()-1);
}
return temp;
}
}
其他相关文章
自制仿360首页支持拼音输入全模糊搜索和自动换肤
自制仿酷我音乐专辑模块源码实现
lucene对校园网资料的全文检索