小说网站的源码设计实现

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代码

[html] view plain copy
  1. <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>  
  2. <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>  
  3. <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>  
  4. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  5. <html xmlns="http://www.w3.org/1999/xhtml">  
  6. <head>  
  7. <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1" />  
  8. <meta name="renderer" content="webkit" />  
  9. <meta name="Keywords" content="个人主页、说说、相册、好友、日志、音乐、新闻、新鲜事" />  
  10. <meta name="Description"  
  11.     content="超酷的校园网、校园交友平台,创新的校园资源获取与分、专注打造最好的校园真实社交网络!" />  
  12. <title>校园小说页面_校园网</title>  
  13. </head>  
  14. <body>  
  15.     <div id="wrapper">  
  16.         <jsp:include page="../public/head.jsp" />  
  17.         <div id="page_main" class="clearfix">  
  18.             <div class="page-right">  
  19.                 <div class="site-nav">  
  20.                     <span>当前位置 : </span><a href="/schoolnet/login.do?flag=goIndexUI">首页</a>  
  21.                     >> <a href="/schoolnet/login.do?flag=goHomeUI" title="">个人主页</a>>>小说  
  22.                 </div>  
  23.                 <div class="page-news">  
  24.                     <div class="content">  
  25.                         <div class="mes_response" id="mes_response">  
  26.                             <table>  
  27.                                 <tr>  
  28.                                     <th class="news-time">小说</th>  
  29.                                 </tr>  
  30.                                 <tr>  
  31.                                     <td><p>按类型:</p>  
  32.                                         <div id="clearClass" class="pages" style="margin-top:-10px">  
  33.                                             <a class="current" href="javascript:void(0)"  
  34.                                                 onclick="setXiaoshuotype(this)" name="all" title="1">全部  
  35.                                             </a>  
  36.                                             <c:forEach var="xiaoshuotype" items="${xiaoshuotypes }">  
  37.                                                 <a href="javascript:void(0)" onclick="setXiaoshuotype(this)"  
  38.                                                     name="${xiaoshuotype.id }" title="1">${xiaoshuotype.name  
  39.                                                     }</a>  
  40.                                             </c:forEach>  
  41.                                         </div>  
  42.                                         <tr>  
  43.                                             <td><br />  
  44.                                                 <p>按更新:</p>  
  45.                                                 <div id="clearClass2" class="pages">  
  46.                                                     <a href="javascript:void(0)"  
  47.                                                         onclick="setXiaoshuotype3(this)" name="all" title="1"  
  48.                                                         class="current">全部</a> <a href="javascript:void(0)"  
  49.                                                         onclick="setXiaoshuotype3(this)" name="lianzai" title="1">  
  50.                                                         连载中</a> <a href="javascript:void(0)"  
  51.                                                         onclick="setXiaoshuotype3(this)" name="wanjie" title="1">  
  52.                                                         已完结</a>  
  53.                                                 </div></td>  
  54.                                         </tr>  
  55.                                         <tr>  
  56.                                             <td>  
  57.                                                 <div id="showxiaoshuos">  
  58.                                                     <div id="ajaxpage" class="pages" style="width:100%">  
  59.                                                         <a href="javascript:void(0)"  
  60.                                                             onclick="setXiaoshuotype2(this)" name="all" title="1"  
  61.                                                             class="current"> 首页 </a> <a href="javascript:void(0)"  
  62.                                                             onclick="setXiaoshuotype2(this)" name="all"  
  63.                                                             title="${pageNow-1 }" class="current"> 上一页 </a> <a  
  64.                                                             href="javascript:void(0)"  
  65.                                                             onclick="setXiaoshuotype2(this)" name="all"  
  66.                                                             title="${pageNow+1 }" class="current"> 下一页 </a> <a  
  67.                                                             href="javascript:void(0)"  
  68.                                                             onclick="setXiaoshuotype2(this)" name="all"  
  69.                                                             title="${PageCount }" class="current"> 尾页 </a> <a  
  70.                                                             class="current2">第${pageNow }页</a><a class="current2">共${PageCount  
  71.                                                             }页</a><a class="current2">${allrows }部小说</a>  
  72.                                                     </div>  
  73.                                                     </br>  
  74.                                                     <c:forEach var="xiaoshuo" items="${xiaoshuos }">  
  75.                                                         <div class="xiaoshuos">  
  76.                                                             <a  
  77.                                                                 href="/schoolnet/xiaoshuo.do?flag=goxiaoshuodescript&pageNow=1&id=${xiaoshuo.id }"  
  78.                                                                 title="${xiaoshuo.title }"> <img  
  79.                                                                 src="/schoolnet/Media/txt/photo/${xiaoshuo.photo }"  
  80.                                                                 width="104px" height="150px">  
  81.                                                             </a>  
  82.                                                             <p class="ellipsis">  
  83.                                                                 <a  
  84.                                                                     href="/schoolnet/xiaoshuo.do?flag=goxiaoshuodescript&pageNow=1&id=${xiaoshuo.id }"  
  85.                                                                     title="${xiaoshuo.title }">${xiaoshuo.title }</a>  
  86.                                                             </p>  
  87.                                                         </div>  
  88.                                                     </c:forEach>  
  89.                                                 </div></td>  
  90.                                         </tr>  
  91.                             </table>  
  92.                         </div>  
  93.                     </div>  
  94.                 </div>  
  95.             </div>  
  96.         </div>  
  97.         <jsp:include page="../public/foot.jsp" />  
  98.     </div>  
  99. </body>  
  100. </html>  
2、小说详情页面html代码
[html] view plain copy
  1. <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>  
  2. <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>  
  3. <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>  
  4. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  5. <html xmlns="http://www.w3.org/1999/xhtml">  
  6. <head>  
  7. <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1" />  
  8. <meta name="renderer" content="webkit" />  
  9. <meta name="Keywords" content="个人主页、说说、相册、好友、日志、音乐、新闻、新鲜事" />  
  10. <meta name="Description"  
  11.     content="超酷的校园网、校园交友平台,创新的校园资源获取与分、专注打造最好的校园真实社交网络!" />  
  12. <title>校园小说页面_校园网</title>  
  13. </head>  
  14. <body>  
  15.     <div id="wrapper">  
  16.         <jsp:include page="../public/head.jsp" />  
  17.         <div id="page_main" class="clearfix">  
  18.             <div class="page-right">  
  19.                 <div class="site-nav">  
  20.                     <span>当前位置 : </span><a href="/schoolnet/login.do?flag=goIndexUI">首页</a>  
  21.                     <a href="/schoolnet/login.do?flag=goHomeUI" title="">个人主页</a>小说  
  22.                 </div>  
  23.                 <div class="page-news">  
  24.                     <div class="content">  
  25.                         <div class="mes_response" id="mes_response">  
  26.                             <table>  
  27.                                 <tr>  
  28.                                     <th class="news-time">小说</th>  
  29.                                 </tr>  
  30.                                 <tr>  
  31.                                     <td>  
  32.                                         <div>  
  33.                                             <div style="float:left">  
  34.                                                 <a href="/schoolnet/xiaoshuo.do?flag=goxiaoshuodescript&pageNow=1&id=${xiaoshuo.id }"  
  35.                                                     title="${xiaoshuo.title }"> <img src="/schoolnet/Media/txt/photo/${xiaoshuo.photo }"  
  36.                                                     width="104px" height="150px"> <br />${xiaoshuo.title }</a>  
  37.                                             </div>  
  38.                                             <div style="float:left;padding-left:20px">  
  39.                                                 <div style="float:left;">  
  40.                                                     <p>类型 : ${xiaoshuo.xiaoshuotype.name }</p>  
  41.                                                     <p> 状态 :   
  42.                                                         <c:if test="${xiaoshuo.state==1 }">连载中</c:if>  
  43.                                                         <c:if test="${xiaoshuo.state==2 }">已完结</c:if>  
  44.                                                     </p>  
  45.                                                     <p>更新 : ${xiaoshuo.creTime }</p>  
  46.                                                     <p>  
  47.                                                         <span class="pages"> <a class="current" href="javascript:void(0)"  
  48.                                                             onclick="javascript:window.history.go(-1)">返回</a> </span>  
  49.                                                     </p>  
  50.                                                 </div>  
  51.                                                 <div style="float:left;padding-left:20px">  
  52.                                                     <p>点击次数 : ${xiaoshuo.click }</p>  
  53.                                                     <p>推荐率 : ${fn:length(userxiaoshuoreco) }</p>  
  54.                                                     <p>章数 : ${count }章</p>  
  55.                                                     <p>文档 : txt</p>  
  56.                                                 </div>  
  57.                                             </div>  
  58.                                         </div></td>  
  59.                                 </tr>  
  60.                                 <tr>  
  61.                                     <td><input id="xiaoshuoid" value="${xiaoshuo.id }"  
  62.                                         type="hidden"> <input id="userid"  
  63.                                             value="${loginuser.id }" type="hidden">  
  64.                                                 <div class="pages">  
  65.                                                     <a class="current" href="/schoolnet/xiaoshuo.do?flag=goxiaoshuodisplay&pageNow=1&id=${xiaoshuo.id }">点击阅读</a>  
  66.                                                     <a class="current" href="/schoolnet/xiaoshuo.do?flag=goxiaoshuoshowUI&pageNow=1&id=${xiaoshuo.id }"  
  67.                                                         title="${xiaoshuo.title }">查看目录</a>  
  68.                                                     <c:if test="${userxiaoshuo==null }">  
  69.                                                         <span id="setbooks"><a href="javascript:void(0);"  
  70.                                                             onclick="setBooks()" title="加入书架" class="current"  
  71.                                                             style="background:#1093d7;">加入书架</a>  
  72.                                                         </span>  
  73.                                                     </c:if>  
  74.                                                     <c:if test="${userxiaoshuo!=null }">  
  75.                                                         <a title="已在书架" class="current" style="background:#999;">已在书架</a>  
  76.                                                     </c:if>  
  77.                                                     <a href="/schoolnet/xiaoshuo.do?flag=gomyxiaoshuoUI&pageNow=1"  
  78.                                                         class="current">我的书架</a>  
  79.                                                     <c:if test="${userxiaoshuoreco==null }">  
  80.                                                         <span id="setreco"><a href="javascript:void(0);"  
  81.                                                             class="current" onclick="setreco()">投推荐票</a>  
  82.                                                         </span>  
  83.                                                     </c:if>  
  84.                                                     <c:if test="${userxiaoshuoreco!=null }">  
  85.                                                         <a title="已推荐" class="current" style="background:#999;">已推荐</a>  
  86.                                                     </c:if>  
  87.                                                 </div>  
  88.                                                 <p>描述:</p>  
  89.                                                 <p>${xiaoshuo.content }</p>  
  90.                                     </td>  
  91.                                 </tr>  
  92.                             </table>  
  93.                         </div>  
  94.                     </div>  
  95.                 </div>  
  96.             </div>  
  97.         </div>  
  98.         <jsp:include page="../public/foot.jsp" />  
  99.     </div>  
  100. </body>  
  101. </html>  
3、小说章数目录页面
[html] view plain copy
  1. <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>  
  2. <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>  
  3. <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>  
  4. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  5. <html xmlns="http://www.w3.org/1999/xhtml">  
  6. <head>  
  7. <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1" />  
  8. <meta name="renderer" content="webkit" />  
  9. <meta name="Keywords" content="个人主页、说说、相册、好友、日志、音乐、新闻、新鲜事" />  
  10. <meta name="Description"  
  11.     content="超酷的校园网、校园交友平台,创新的校园资源获取与分、专注打造最好的校园真实社交网络!" />  
  12. <title>校园小说页面_校园网</title>  
  13. </head>  
  14. <body>  
  15.     <div id="wrapper">  
  16.         <jsp:include page="../public/head.jsp" />  
  17.         <div id="page_main" class="clearfix">  
  18.             <div class="page-right">  
  19.                 <div class="site-nav">  
  20.                     <span>当前位置 : </span><a href="/schoolnet/login.do?flag=goIndexUI">首页</a>  
  21.                     <a href="/schoolnet/login.do?flag=goHomeUI" title="">个人主页</a>小说  
  22.                 </div>  
  23.                 <div class="page-news">  
  24.                     <div class="content">  
  25.                         <div class="mes_response" id="mes_response">  
  26.                             <table>  
  27.                                 <tr><th class="news-time">小说</th> </tr>  
  28.                                 <tr>  
  29.                                     <td><span class="pages"> <a class="current"  
  30.                                             href="javascript:void(0)"  
  31.                                             onclick="javascript:window.history.go(-1)">返回</a> </span> <span  
  32.                                         style="margin-left:220px">${xiaoshuo.title }</span></td>  
  33.                                 </tr>  
  34.                                 <tr>  
  35.                                     <td class="pages"><c:forEach var="i" begin="1"  
  36.                                             end="${count}">  
  37.                                             <a class="pagesa" href="/schoolnet/xiaoshuo.do?flag=goxiaoshuodisplay&pageNow=${i }&id=${xiaoshuo.id}">第${i}章</a>  
  38.                                         </c:forEach></td>  
  39.                                 </tr>  
  40.                             </table>  
  41.                         </div>  
  42.                     </div>  
  43.                 </div>  
  44.             </div>  
  45.         </div>  
  46.         <jsp:include page="../public/foot.jsp" />  
  47.     </div>  
  48. </body>  
  49. </html>  
4、小说内容阅读页面
[html] view plain copy
  1. <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>  
  2. <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>  
  3. <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>  
  4. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  5. <html xmlns="http://www.w3.org/1999/xhtml">  
  6. <head>  
  7. <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1" />  
  8. <meta name="renderer" content="webkit" />  
  9. <meta name="Keywords" content="个人主页、说说、相册、好友、日志、音乐、新闻、新鲜事" />  
  10. <meta name="Description" content="超酷的校园网、校园交友平台,创新的校园资源获取与分、专注打造最好的校园真实社交网络!" />  
  11. <title>校园新小说页面_校园网</title>  
  12. </head>  
  13. <body>  
  14.     <div id="wrapper">  
  15.         <jsp:include page="../public/head.jsp" />  
  16.         <div id="page_main" class="clearfix">  
  17.             <div class="page-right">  
  18.                 <div class="site-nav">  
  19.                     <span>当前位置 : </span><a href="/schoolnet/login.do?flag=goIndexUI">首页</a>  
  20.                       <a href="/schoolnet/login.do?flag=goHomeUI" title="">个人主页</a>小说  
  21.                 </div>  
  22.                 <div class="page-news">  
  23.                     <div class="content">  
  24.                         <div class="mes_response" id="mes_response">  
  25.                             <table>  
  26.                                 <tr><th class="news-time">小说 </th></tr>  
  27.                                 <div class="pages" style="margin-left:200px;">          
  28.                                 </div>  
  29.                                 <tr> <td align="center"><span>${xiaoshuo.title }</span> </td> </tr>  
  30.                                 <tr>  
  31.                                 <td>${str }  
  32.                                 </td> </tr>  
  33.                             </table>  
  34.                         </div>  
  35.                      <div class="pages" style="margin-left:200px;">  
  36.                         <a href="/schoolnet/xiaoshuo.do?flag=goxiaoshuodisplay&pageNow=${page-1 }&id=${xiaoshuo.id}"  
  37.                            class="current"> 上一章 </a>   
  38.                         <a href="/schoolnet/xiaoshuo.do?flag=goxiaoshuoshowUI&pageNow=${page }&id=${xiaoshuo.id}"  
  39.                            class="current"> 目录</a>   
  40.                         <a href="/schoolnet/xiaoshuo.do?flag=goxiaoshuodisplay&pageNow=${page+1 }&id=${xiaoshuo.id}"  
  41.                            class="current"> 下一章</a>   
  42.                       </div>  
  43.                     </div>  
  44.                 </div>  
  45.             </div>  
  46.         </div>  
  47.         <jsp:include page="../public/foot.jsp" />  
  48.     </div>  
  49. </body>  
  50. </html>  
相关java代码
[html] view plain copy
  1.     int PagesSize=10;  
  2.     String pageNow=request.getParameter("pageNow");  
  3.     String id=request.getParameter("id");  
  4.   
  5.     //选择小说类型为全部  
  6.     if("all".equals(id)){  
  7.   
  8.     //分页查询  
  9.         int pageNows=Integer.valueOf(pageNow);  
  10.         int allrows=userService.queryallrows("from Xiaoshuo", null);  
  11.         int PageCount=(allrows-1)/PagesSize+1;  
  12.         if(pageNows<1)  
  13.         {  
  14.             pageNows=1;  
  15.         }  
  16.         if(pageNows>PageCount)  
  17.         {  
  18.             pageNows=PageCount;  
  19.         }  
  20.   
  21.         //获取小说  
  22.         List<Xiaoshuo> xiaoshuos=userService.executeQueryByPage("from Xiaoshuo order by id desc", null, pageNows, PagesSize);  
  23.           
  24.         //获取小说分类              
  25.         List<Xiaoshuotype> xiaoshuotypes=userService.getResult("from Xiaoshuotype", null);  
  26.         request.setAttribute("xiaoshuotypes", xiaoshuotypes);  
  27.         request.setAttribute("xiaoshuos", xiaoshuos);  
  28.         request.setAttribute("pageNow", pageNows);  
  29.         request.setAttribute("PageCount", PageCount);  
  30.         request.setAttribute("allrows", allrows);  
  31.     }  
  32.   
  33.     //获取连载中的小说  
  34.     else if("lianzai".equals(xiaoshuotypeid)){  
  35.         List<Xiaoshuo> xiaoshuos=universityService.executeQueryByPage("from Xiaoshuo where state=1 order by id desc", null, pageNow, pageSize);  
  36.     }  
  37.     //获取已完结的小说  
  38.     else if("wanjie".equals(xiaoshuotypeid)){  
  39.         List<Xiaoshuo> xiaoshuos=universityService.executeQueryByPage("from Xiaoshuo where state=2 order by id desc", null, pageNow, pageSize);  
  40.     }  
  41.     //选择小说类型为单类  
  42.     else {  
  43.         int pageNows=Integer.valueOf(pageNow);  
  44.         int allrows=userService.queryallrows("from Xiaoshuo where xiaoshuotype.id=?", new Object[]{Integer.valueOf(id)});  
  45.         int PageCount=(allrows-1)/PagesSize+1;  
  46.         if(pageNows<1)  
  47.         {  
  48.             pageNows=1;  
  49.         }  
  50.         if(pageNows>PageCount)  
  51.         {  
  52.             pageNows=PageCount;  
  53.         }  
  54.         List<Xiaoshuo> xiaoshuos=userService.executeQueryByPage("from Xiaoshuo where xiaoshuotype.id=? order by id desc", new Object[]{Integer.valueOf(id)}, pageNows, PagesSize);  
  55.         List<Xiaoshuotype> xiaoshuotypes=userService.getResult("from Xiaoshuotype", null);  
  56.         request.setAttribute("xiaoshuotypes", xiaoshuotypes);  
  57.         request.setAttribute("xiaoshuos", xiaoshuos);  
  58.         request.setAttribute("pageNow", pageNows);  
  59.         request.setAttribute("PageCount", PageCount);  
  60.         request.setAttribute("allrows", allrows);  
  61.     }  
  62.   
  63.     String id=request.getParameter("id");  
  64.     Xiaoshuo xiaoshuo=(Xiaoshuo) userService.findById(Xiaoshuo.class, Integer.valueOf(id));  
  65.     request.setAttribute("xiaoshuo", xiaoshuo);  
  66.     String docu=xiaoshuo.getDocu();  
  67.     StringBuffer sb=GetContent.uploadHead(request,docu);  
  68.     Pattern p = Pattern.compile("第[一二三四五六七八九十百千]{5}章 ");  
  69.     Matcher m = p.matcher(sb);  
  70.     int count =0;  
  71.     int count1=Integer.valueOf(request.getParameter("pageNow"));  
  72.     while(m.find()){  
  73.           count ++;  
  74.     }  
  75.     if(count1<1)  
  76. {  
  77.         count1=1;  
  78. }  
  79. if(count1>count)  
  80. {  
  81.     count1=count;  
  82. }  
  83.     if(count1<=count)  
  84.     {  
  85.  //将阿拉伯数值转成中文数值  
  86.      String result=ChinUtil.toChin(String.valueOf(count1));  
  87.      String result2=ChinUtil.toChin(String.valueOf(count1+1));  
  88.  //截取两章之间的内容  
  89.         String sb1=sb.toString().substring(sb.indexOf("第"+result+"章"), sb.indexOf("第"+result2+"章"));  
  90.         request.setAttribute("str", sb1);  
  91.         request.setAttribute("page", count1);  
  92.     }  
  93.     request.setAttribute("count", count);  

GetContent.java

[html] view plain copy
  1. public class GetContent {  
  2.     public static StringBuffer uploadHead(HttpServletRequest request,String docu){  
  3.         StringBuffer sb = new StringBuffer();  
  4.          try{  
  5.             //filePath就是当前这个web应用是绝对路径   
  6.              String filepath=request.getSession().getServletContext().getRealPath("/");  
  7.             File f2=new File(filepath+"\\Media\\txt\\"+docu);  
  8.             BufferedReader bReader=new BufferedReader(new FileReader(f2));  
  9.             while (true) {  
  10.                 String str = bReader.readLine();  
  11.                 if (str != null) {  
  12.                         sb.append(str + "<br/>");  
  13.                 }  
  14.                 if (str == null) {  
  15.                     break;  
  16.                 }  
  17.             }  
  18.         } catch (Exception e) {  
  19.             e.printStackTrace();  
  20.         }  
  21.          return sb;  
  22.         }  
  23. }  
ChinUtil.java
[html] view plain copy
  1. public class ChinUtil{  
  2.         public static String toChin(String string) {  
  3.             String nums[]={"0","1","2","3","4","5","6","7","8","9"};  
  4.             String chines[]={"零","一","二","三","四","五","六","七","八","九"};  
  5.             String level[]={"十","百","千","万","十","百","千","亿"};  
  6.             //不算进制,直接将阿拉伯数值转中文数字  
  7.             for (int i = 0; i < nums.length; i++) {  
  8.                 string=string.replaceAll(nums[i], chines[i]);  
  9.             }  
  10.             System.out.println(string);  
  11.             StringBuffer stringBuffer=new StringBuffer(string);  
  12.             //插入十进制单位  
  13.             for (int i = 0; i < string.length()-1; i++) {  
  14.                 stringBuffer.insert(string.length()-1-i, level[i]);  
  15.             }  
  16.             System.out.println(stringBuffer.toString());  
  17.             String temp = new String(stringBuffer.toString());  
  18.             //处理零的情况  
  19.             while((temp.indexOf("零万")!=-1)||(temp.indexOf("零千")!=-1)||(temp.indexOf("零百")!=-1)||(temp.indexOf("零十")!=-1)||(temp.indexOf("零零")!=-1)){  
  20.                if(temp.indexOf("零千")!=-1){  
  21.                temp = temp.replaceAll("零千","零");  
  22.                }  
  23.                if(temp.indexOf("零百")!=-1){  
  24.                temp = temp.replaceAll("零百","零");  
  25.                }  
  26.                if(temp.indexOf("零十")!=-1){  
  27.                temp = temp.replaceAll("零十","零");  
  28.                }  
  29.                if(temp.indexOf("零零")!=-1){  
  30.                temp = temp.replaceAll("零零","零");  
  31.                }  
  32.                 
  33.               if((temp.indexOf("零万")!=-1)){  
  34.                temp = temp.replaceAll("零万","万");  
  35.               }  
  36.                  }  
  37.               //处理个位为零的情况  
  38.               if(temp.lastIndexOf("零")==temp.length()-1){  
  39.                temp = temp.substring(0,temp.length()-1);  
  40.               }  
  41.              return temp;  
  42.      }  

猜你喜欢

转载自blog.csdn.net/u010664947/article/details/80242911