java 翰子昂 新聞發(fā)布系統(tǒng) News System-part3_第1頁
java 翰子昂 新聞發(fā)布系統(tǒng) News System-part3_第2頁
java 翰子昂 新聞發(fā)布系統(tǒng) News System-part3_第3頁
java 翰子昂 新聞發(fā)布系統(tǒng) News System-part3_第4頁
java 翰子昂 新聞發(fā)布系統(tǒng) News System-part3_第5頁
已閱讀5頁,還剩22頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

瀚子昂新聞發(fā)布系統(tǒng)主要源碼part3制作人:許國杰&&易蘭河北師范大學分頁功能實現(xiàn)效果截圖主要代碼publicStringpagedQuery(HttpServletRequestrequest, HttpServletResponseresponse){ PagedNewspagedNews=newPagedNews(); PageInfopageInfo=null; /* *這有問題從前臺取到空引起異常 *pagedNews.setPagedNewsClassid(Integer.parseInt(request *.getParameter("queryClassid"))); *pagedNews.setPagedNewsPageNo(Integer. *parseInt(request.getParameter("queryPageNo"))); *pagedNews.setPagedNewsPageSize *(Integer.parseInt(request.getParameter("queryPageSize"))); */ PageNewsDaopageNewsDao=newPageNewsDao(); try{ pageInfo=pageNewsDao.pagedQuery(pagedNews.getPageNewsPageSql(), pagedNews.getPagedNewsPageNo(),pagedNews .getPagedNewsPageSize(),null); request.setAttribute("pageinfo",pageInfo); }catch(Exceptione){ System.out.println("分頁查詢新聞錯誤"+e.getMessage()); } return"/info_manager.jsp"; }新聞編輯頁面效果截圖新聞編輯頁面主要代碼后臺JAVA代碼publicStringupdata(HttpServletRequestrequest, HttpServletResponseresponse){ //創(chuàng)建新聞對象 NewNewsnews=newNewNews(); //獲取新聞信息 Stringnewsid2=request.getParameter("NewsId"); intnewsid=0; if(newsid2!=null){ newsid=Integer.parseInt(newsid2); } StringnewsTitle=request.getParameter("newsTitle"); intnewsClassId=Integer.parseInt(request.getParameter("newsClassId")); StringnewsKey=request.getParameter("newsKey"); StringnewsSource=request.getParameter("newsSource"); StringnewsContent=request.getParameter("newsContent"); StringuserName=request.getParameter("newsUserName").toString(); news.setNewsId(newsid); news.setNewsTitle(newsTitle); news.setNewsClassId(newsClassId); news.setNewsSource(newsSource); news.setNewsKey(newsKey); news.setUserName(userName); news.setNewsContent(newsContent); //創(chuàng)建DAO對象 NewsDaonewsDao=newNewsDao(); //執(zhí)行插入 try{ newsDao.update(news); }catch(Exceptione){ System.out.println("更新新聞出錯"+e.getMessage()); } //返回新聞管理頁面 return"/managenews.do"; }前臺jsp代碼<tdwidth="12%"height="23"align="center"class="td"> 信息屬性 </td>${news[0].newsClassId} <tdheight="23"colspan="3"valign="middle"class="td"> <selectname="newsClassId"id="newsClassId"> <optionvalue="${news[0].newsClassId}"selected="selected"> ${news[0].newsClassName} <!--<c:forEachitems="${classes}"var="classes"> <optionvalue=<c:outvalue="${classes.classId}"/>> <c:outvalue="${classes.className}"/> </c:forEach>--> </select> </td>數(shù)據連接代碼ConnectionFactory.javapackagecom.NewsSystem.model.connection;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.SQLException;/**數(shù)據連接對象的實現(xiàn)類*/publicclassDefaultConnectionFactoryimplementsConnectionFactory{ ConnectionPropertycp=newConnectionProperty().getInstance(); Connectionconn=null; /* *構造函數(shù)加載數(shù)據庫驅動 */ publicConnectiongetConnection(){ //TODOAuto-generatedmethodstub try{ Class.forName(cp.driverClassName); conn=DriverManager.getConnection(cp.url,cp.user,cp.passWord); }catch(ClassNotFoundExceptione){ System.out.println("找不到類"+cp.driverClassName); }catch(SQLExceptione){ System.out.println("DriverManager錯誤:"+e.getMessage()); } //返回數(shù)據庫對象 returnthis.conn; } //關閉數(shù)據庫連接 publicvoidconnectionClose(){ //TODOAuto-generatedmethodstub try{ conn.close(); }catch(SQLExceptione){ System.out.println("數(shù)據庫關閉失敗"+e.getMessage()); } }}ConnectionPropert.javapackagecom.NewsSystem.model.connection;importjava.io.File;importjava.sql.Connection;importjavax.xml.parsers.DocumentBuilder;importjavax.xml.parsers.DocumentBuilderFactory;importorg.w3c.dom.Document;importorg.w3c.dom.NodeList;publicclassConnectionProperty{ StringdriverClassName; Stringurl; Stringuser; StringpassWord; StringproviderType; StringjndiName; Stringdbms; publicConnectionProperty(){ //TODOAuto-generatedconstructorstub //從dbconfig.xml中獲取連接信息 try{ Filef=newFile("resources/dbconfig.xml"); DocumentBuilderFactoryfactory=DocumentBuilderFactory.newInstance(); DocumentBuilderbuilder=factory.newDocumentBuilder(); Documentdoc=builder.parse(f); NodeListnl=doc.getElementsByTagName("connection"); driverClassName=doc.getElementsByTagName("driver_class_name").item(0).getFirstChild().getNodeValue().toString(); url=doc.getElementsByTagName("url").item(0).getFirstChild().getNodeValue().toString(); user=doc.getElementsByTagName("user").item(0).getFirstChild().getNodeValue().toString(); passWord=doc.getElementsByTagName("password").item(0).getFirstChild().getNodeValue().toString(); }catch(Exceptione){ System.out.println("從dbconfig.xml中獲取連接信息失敗"); } } publicConnectionPropertygetInstance(){ ConnectionPropertyconnectionProperty=newConnectionProperty(); returnconnectionProperty; } publicvoidreport(){ //打印數(shù)據庫連接信息 } publicStringvalue(){ returnnull; } }Dbconfig.xml文件<?xmlversion="1.0"encoding="UTF-8"?><connectiontype="default"jndi=""dbms="SQLServer"> <driver_class_name>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver_class_name> <url>jdbc:sqlserver://localhost:1433;DatabaseName=NewSys</url> <user>xuguojie</user> <password>xuguojie</password></connection> 過濾器代碼EncodingFilter.javapackagecom.NewsSystem.controller.listener;importjava.io.IOException;importjavax.servlet.Filter;importjavax.servlet.FilterChain;importjavax.servlet.FilterConfig;importjavax.servlet.ServletException;importjavax.servlet.ServletRequest;importjavax.servlet.ServletResponse;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;publicclassEncodingFilterimplementsFilter{ privateStringencoding="GB2312"; publicvoiddestroy(){ //TODOAuto-generatedmethodstub } publicvoiddoFilter(ServletRequestrequest,ServletResponseresponse, FilterChainchain)throwsIOException,ServletException{ //TODOAuto-generatedmethodstub HttpServletRequesthttpRequest=(HttpServletRequest)request; HttpServletResponsehttpResponse=(HttpServletResponse)response; httpRequest.setCharacterEncoding(encoding); httpResponse.setCharacterEncoding(encoding); chain.doFilter(httpRequest,httpResponse); } publicvoidinit(FilterConfigfilterConfig)throwsServletException{ //TODOAuto-generatedmethodstub encoding=filterConfig.getInitParameter("encoding"); } }LoginFilter.javapackagecom.NewsSystem.controller.listener;importjava.io.IOException;importjavax.servlet.Filter;importjavax.servlet.FilterChain;importjavax.servlet.FilterConfig;importjavax.servlet.ServletException;importjavax.servlet.ServletRequest;importjavax.servlet.ServletResponse;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;importjavax.servlet.http.HttpSession;publicclassLoginFilterimplementsFilter{ publicvoiddestroy(){ //TODOAuto-generatedmethodstub } publicvoiddoFilter(ServletRequestrequest,ServletResponseresponse, FilterChainchain)throwsIOException,ServletException{ //TODOAuto-generatedmethodstub HttpServletRequesthttpRequest=(HttpServletRequest)request; HttpServletResponsehttpResponse=(HttpServletResponse)response; Stringurl=httpRequest.getRequestURI(); if(url.contains("login")){ chain.doFilter(httpRequest,httpResponse); } else{ HttpSessionsession=httpRequest.getSession(); if(session.getAttribute("user")==null){ request.getRequestDispatcher("/login.jsp").forward(request,response); return; } chain.doFilter(httpRequest,httpResponse); } } publicvoidinit(FilterConfigfilterConfig)throwsServletException{ //TODOAuto-generatedmethodstub }}DAO類BaseDao.javapackagecom.NewsSystem.model.service.dao;importjava.sql.Connection;importjava.sql.ResultSet;importjava.sql.ResultSetMetaData;importjava.sql.SQLException;importjava.util.ArrayList;importjava.util.HashMap;importjava.util.List;importjava.util.Map;importcom.NewsSystem.model.connection.ConnectionFactory;importcom.NewsSystem.model.connection.DefaultConnectionFactory;publicabstractclassBaseDaoimplementsDAOObject{ Connectionconn=null; @SuppressWarnings({"unchecked","unused"}) //把ResultSet轉換為List publicstaticListconvertList(ResultSetrs)throwsSQLException{ Listlist=newArrayList(); ResultSetMetaDatamd=rs.getMetaData(); intcolumnCount=md.getColumnCount();//MaprowData; while(rs.next()){//rowData=newHashMap(columnCount); MaprowData=newHashMap(); for(inti=1;i<=columnCount;i++) {rowData.put(md.getColumnName(i),rs.getObject(i)); } list.add(rowData); } returnlist; }}ClassesDao.javapackagecom.NewsSystem.model.service.dao;importjava.sql.ResultSet;importjava.sql.SQLException;importjava.util.ArrayList;importjava.util.List;importcom.NewsSystem.controller.servlet.Classes;importcom.NewsSystem.controller.servlet.NewsUser;importcom.NewsSystem.model.connection.DefaultConnectionFactory;importcom.NewsSystem.model.service.dao.page.PageInfo;publicclassClassesDaoextendsBaseDao{ publicbooleancreate(ObjectentityObject){ booleanb=false; Classesclasses=(Classes)entityObject; conn=newDefaultConnectionFactory().getConnection(); Stringsql="insertintoCLASSES(classname,classdesc,classorder,itemid)values('" +classes.getClassName() +"','" +classes.getClassDesc() +"'," +"'" +classes.getClassOrder() +"','" +classes.getItemId()+"')"; try{ conn.prepareStatement(sql).executeUpdate(); b=true; }catch(SQLExceptione){ e.printStackTrace(); }finally{ if(conn!=null){ try{ conn.close(); conn=null; }catch(SQLExceptione){ //TODOAuto-generatedcatchblock e.printStackTrace(); } } } returnb; }//TODOAuto-generatedmethodstub publicObjectget(ObjectentityObject){ //TODOAuto-generatedmethodstub returnnull; } publicList<Classes>list(){ List<Classes>list=newArrayList<Classes>(); conn=newDefaultConnectionFactory().getConnection(); Stringsql="selectclassid,classname,classdesc,classorder,dbo.GetItemName(itemid)AS'ItemName'fromCLASSES"; conn=newDefaultConnectionFactory().getConnection(); try{ ResultSetrs=conn.prepareStatement(sql).executeQuery(); while(rs.next()){ Classesclasses=newClasses(); classes.setClassId(rs.getInt("classid")); classes.setClassName(rs.getString("classname")); classes.setClassDesc(rs.getString("classdesc")); classes.setClassOrder(rs.getInt("classorder")); classes.setItemName(rs.getString("ItemName")); list.add(classes); } }catch(SQLExceptione){ e.printStackTrace(); }finally{ if(conn!=null){ try{ conn.close(); conn=null; }catch(SQLExceptione){ //TODOAuto-generatedcatchblock e.printStackTrace(); } } } returnlist; } publicPageInfopagedQuery(Stringquery,intpageNo,intpageSize, Object...objects){ //TODOAuto-generatedmethodstub returnnull; } publicList<Classes>query(Object...objects)throwsSQLException{ Classesclasses=(Classes)objects[0]; List<Classes>rs=newArrayList<Classes>(); conn=newDefaultConnectionFactory().getConnection(); Stringsql="select*fromCLASSESwhereclassname='" +classes.getClassName()+"'anditemid='" +classes.getItemId()+"'"; try{ rs=convertList(conn.prepareStatement(sql).executeQuery()); }catch(SQLExceptione){ //TODOAuto-generatedcatchblock e.printStackTrace(); }finally{ if(conn!=null){ try{ conn.close(); conn=null; }catch(SQLExceptione){ //TODOAuto-generatedcatchblock e.printStackTrace(); } } } returnrs; } publicvoidremove(ObjectentityObject){ Classesclasses=(Classes)entityObject; conn=newDefaultConnectionFactory().getConnection(); Stringsql="DELETEFROMCLASSESWHEREclassid='" +classes.getClassId()+"'"; try{ conn.prepareStatement(sql).executeUpdate(); }catch(SQLExceptione){ e.printStackTrace(); }finally{ if(conn!=null){ try{ conn.close(); conn=null; }catch(SQLExceptione){ //TODOAuto-generatedcatchblock e.printStackTrace(); } } } } publicvoidupdate(ObjectentityObject){ Classesclasses=(Classes)entityObject; Stringsql="UPDATECLASSESSETclassname='" +classes.getClassName()+"',classdesc='" +classes.getClassDesc()+"',classorder='" +classes.getClassOrder()+"'whereclassid='" +classes.getClassId()+"'"; conn=newDefaultConnectionFactory().getConnection(); try{ conn.prepareStatement(sql).executeUpdate(); }catch(SQLExceptione){ System.out.println("更新失敗"+e.getStackTrace()); }finally{ if(conn!=null){ try{ conn.close(); conn=null; }catch(SQLExceptione){ //TODOAuto-generatedcatchblock e.printStackTrace(); } } } }}ItemsDao.javapackagecom.NewsSystem.model.service.dao;importjava.sql.ResultSet;importjava.sql.SQLException;importjava.util.ArrayList;importjava.util.List;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;importcom.NewsSystem.controller.servlet.Classes;importcom.NewsSystem.controller.servlet.Items;importcom.NewsSystem.controller.servlet.NewsUser;importcom.NewsSystem.model.connection.DefaultConnectionFactory;importcom.NewsSystem.model.service.dao.page.PageInfo;publicclassItemsDaoextendsBaseDao{ publicbooleancreate(ObjectentityObject){ booleanb=false; Itemsitem=(Items)entityObject; conn=newDefaultConnectionFactory().getConnection(); Stringsql="insertintoITEMS(itemname,itemdesc,itemorder)values('" +item.getItemName()+"','"+item.getItemDesc()+"','" +item.getItemOrder()+"')"; try{ conn.prepareStatement(sql).executeUpdate(); b=true; }catch(SQLExceptione){ e.printStackTrace(); }finally{ if(conn!=null){ try{ conn.close(); conn=null; }catch(SQLExceptione){ //TODOAuto-generatedcatchblock e.printStackTrace(); } } } returnb; } //基于條件查詢某條記錄 publicObjectget(ObjectentityObject){ returnnull; } //查詢所有記錄 publicList<Items>list(){ List<Items>list=newArrayList<Items>(); conn=newDefaultConnectionFactory().getConnection(); Stringsql="selectitemid,itemname,itemdesc,itemorderfromITEMS"; conn=newDefaultConnectionFactory().getConnection(); try{ ResultSetrs=conn.prepareStatement(sql).executeQuery(); while(rs.next()){ Itemsitem=newItems(); item.setItemId(rs.getInt("itemid")); item.setItemName(rs.getString("itemname")); item.setItemDesc(rs.getString("itemdesc")); item.setItemOrder(rs.getInt("itemorder")); list.add(item); } }catch(SQLExceptione){ e.printStackTrace(); } finally{ if(conn!=null){ try{ conn.close(); conn=null; }catch(SQLExceptione){ //TODOAuto-generatedcatchblock e.printStackTrace(); } } } returnlist; } //基于條件返回所有記錄 publicList<Items>query(Object...objects)throwsSQLException{ Itemsitem=(Items)objects[0]; List<Items>rs=null; conn=newDefaultConnectionFactory().getConnection(); Stringsql="select*fromITEMSwhereitemname='" +item.getItemName()+"'"; try{ rs=convertList(conn.prepareStatement(sql).executeQuery()); }catch(SQLExceptione){ //TODOAuto-generatedcatchblock e.printStackTrace(); }finally{ if(conn!=null){ try{ conn.close(); conn=null; }catch(SQLExceptione){ //TODOAuto-generatedcatchblock e.printStackTrace(); } } } returnrs; } //根據SQL語句,當前頁數(shù),每頁數(shù)量進行分頁查詢 publicPageInfopagedQuery(Stringquery,intpageNo,intpageSize, Object...objects){ returnnull; } //刪除某條記錄 publicvoidremove(ObjectentityObject){ Itemsitem=(Items)entityObject; conn=newDefaultConnectionFactory().getConnection(); Stringsql="DELETEFROMITEMSWHEREitemid='"+item.getItemId()+"'"; try{ conn.prepareStatement(sql).executeUpdate(); }catch(SQLExceptione){ e.printStackTrace(); }finally{ if(conn!=null){ try{ conn.close(); conn=null; }catch(SQLExceptione){ //TODOAuto-generatedcatchblock e.printStackTrace(); } } } }publicvoidupdate(ObjectentityObject){ Itemsitem=(Items)entityObject; Stringsql="UPDATEITEMSSETitemname='"+item.getItemName()+"',itemdesc='"+item.getItemDesc()+"',itemorder='" +item.getItemOrder()+"'whereitemid='"+item.getItemId()+"'"; conn=newDefaultConnectionFactory().getConnection(); try{ conn.prepareStatement(sql).executeUpdate(); }catch(SQLExceptione){ System.out.println("更新失敗"+e.getStackTrace()); }finally{ if(conn!=null){ try{ conn.close(); conn=null; }catch(SQLExceptione){ //TODOAuto-generatedcatchblock e.printStackTrace(); } } } }}NewsDao.javapackagecom.NewsSystem.model.service.dao;importjava.sql.ResultSet;importjava.sql.SQLException;importjava.util.ArrayList;importjava.util.List;importcom.NewsSystem.controller.servlet.NewNews;importcom.NewsSystem.model.connection.DefaultConnectionFactory;importcom.NewsSystem.model.service.dao.page.PageInfo;publicclassNewsDaoextendsBaseDao{ publicbooleancreate(ObjectentityObject){ booleanb=false; NewNewsnews=(NewNews)entityObject; conn=newDefaultConnectionFactory().getConnection(); Stringsql="insertintoNEWS(newstitle,classid,newsdate,newskey,newscontent,username,newsource)values('" +news.getNewsTitle() +"','" +news.getNewsClassId() +"'," +"'" +news.getNewsDate() +"','" +news.getNewsKey() +"','" +news.getNewsContent() +"','" +news.getNewsUserName() +"','"+news.getNewsSource()+"')"; try{ conn.prepareStatement(sql).executeUpdate(); b=true; }catch(SQLExceptione){ e.printStackTrace(); }finally{ if(conn!=null){ try{ conn.close(); conn=null; }catch(SQLExceptione){ //TODOAuto-generatedcatchblock e.printStackTrace(); } } } returnb; } publicObjectget(ObjectentityObject){ //TODOAuto-generatedmethodstub returnnull; } publicList<NewNews>list(){ //TODOAuto-generatedmethodstub returnnull; } publicList<NewNews>query(Object...objects){ NewNewsnews=(NewNews)objects[0]; List<NewNews>list=newArrayList<NewNews>(); conn=newDefaultConnectionFactory().getConnection(); Stringsql="selectnewstitle,classid,dbo.GETCLASSNAME(classid)AS" +"classname,newsdate,newskey,username,newsource," +"newscontentfromNEWSwherenewsid='"+news.getNewsId()+"'"; try{ ResultSetrs=conn.prepareStatement(sql).executeQuery(); while(rs.next()){ NewNewsnewNews=newNewNews(); newNews.setNewsClassId(Integer.parseInt(rs.getString("classid"))); newNews.setNewsTitle(rs.getString("newstitle")); newNews.setnewsClassName(rs.getString("classname")); newNews.setNewsDate(rs.getString("newsdate")); newNews.setNewsKey(rs.getString("newskey")); newNews.setUserName(rs.getString("username")); newNews.setNewsSource(rs.getString("newsource")); newNews.setNewsContent(rs.getString("newscontent")); newNews.setNewsId(news.getNewsId()); list.add(newNews); } }catch(SQLExceptione){ e.printStackTrace(); }finally{ if(conn!=null){ try{ conn.close(); conn=null; }catch(SQLExceptione){ //TODOAuto-generatedcatchblock e.printStackTrace(); } } } returnlist; } publicvoidremove(ObjectentityObject){ NewNewsnews=(NewNews)entityObject; conn=newDefaultConnectionFactory().getConnection(); Stringsql="DELETEFROMNEWSWHEREnewsid='"+news.getNewsId() +"'"; try{ conn.prepareStatement(sql).executeUpdate(); }catch(SQLExceptione){ e.printStackTrace(); }finally{ if(conn!=null){ try{ conn.close(); conn=null; }catch(SQLExceptione){ //TODOAuto-generatedcatchblock e.printStackTrace(); } } } }//TODOAuto-generatedmethodstub publicvoidupdate(ObjectentityObject){ NewNewsnews=(NewNews)entityObject; conn=newDefaultConnectionFactory().getConnection(); Stringsql="updateNEWSsetnewstitle='"+news.getNewsTitle()+"',classid='"+news.getNewsClassId()+"',"+ "newsdate='"+news.getNewsDate()+"',newskey='"+news.getNewsKey()+"',newscontent='"+news.getNewsContent()+"',"+ "username='"+news.getNewsUserName()+"',newsource='"+news.getNewsSource()+"'wherenewsid='"+news.getNewsId()+"'"; try{ conn.prepareStatement(sql).executeUpdate(); }catch(SQLExceptione){ e.printStackTrace(); }finally{ if(conn!=null){ try{ conn.close(); conn=null; }catch(SQLExceptione){ //TODOAuto-generatedcatchblock e.printStackTrace(); } } } } publicPageInfopagedQuery(Stringquery,intpageNo,intpageSize, Object...objects){ //TODOAuto-generatedmethodstub returnnull; }}PageNewsDao.javapackagecom.NewsSystem.model.service.dao;importjava.sql.SQLException;importjava.util.ArrayList;importjava.util.List;importjavax.sql.RowSet;importcom.NewsSystem.controller.servlet.NewNews;importcom.NewsSystem.model.connection.ConnectionFactory;importcom.NewsSystem.model.connection.DefaultConnectionFactory;importcom.NewsSystem.model.service.dao.BaseDao;importcom.NewsSystem.model.service.dao.page.PageInfo;importcom.NewsSystem.model.service.dao.page.PageStatementFactory;importcom.NewsSystem.model.service.dao.page.PagedStatement;publicclassPageNewsDaoextendsBaseDao{ /* *是第一次顯示分頁結果 *為PagedNewsDao添加newsPageInfo并在get方法中調用pagedQuery方法 */ /*privatePageInfonewsPageInfo; *//** *returnthenewsPageInfo *//* publicPageInfogetNewsPageInfo(){ returnthis.pagedQuery("selectuserid,newstitle,dbo.GetClassName(2)as'ClassName',newsdate,newsource,hitsFORMNEWS",1,10,null); }*/ publicbooleancreate(ObjectentityObject){ //TODOAuto-generatedmethodstub returnfalse; } publicObjectget(ObjectentityObject){ //TODOAuto-generatedmethodstub returnnull; } publicListlist(){ //TODOAuto-generatedmethodstub returnnull; } publicPageInfopagedQuery(Stringquery,intpageNo,intpageSize, Object...objects){ //獲得SQLServer的分頁實現(xiàn) PagedStatementpstmt=PageStatementFactory.newSqlServerInstance(); //設置連接工廠?????????????????????? pstmt.setConnProvider(newDefaultConnectionFactory()); //初始花頁面 pstmt.initStatement(query,pageNo,pageSize); PageInfopageInfo=null; List<NewNews>list=newArrayList<NewNews>(); try{ //查詢當前數(shù)據 RowSetrs=pstmt.executeQuery(); while(rs.next()){ NewNewsnews=newNewNews(); news.setNewsId(rs.getInt(1)); news.setNewsTitle(rs.getString(2)); news.setnewsClassName(rs.getString(3)); //news.setNewsClassId(rs.getInt(3)); news.setNewsDate(rs.getString(4)); news.setNewsSource(rs.getString(5)); news.setHits(rs.getInt(6)); list.add(news);//把新聞信息放到List里 } //返回分頁信息 pageInfo=pstmt.getPageInfo();//pstmt.getPageInfo()沒有定義 //為分頁信息對象設置當前頁數(shù)據結果集??? pageInfo.setPageContent(list); }catch(SQLExceptione){ e.printStackTrace(); } returnpageInfo; } publicListquery(Object...objects){ //TODOAuto-generatedmethodstub returnnull; } publicvoidremove(ObjectentityObject){ //TODOAuto-generatedmethodstub } publicvoidupdate(ObjectentityObject){ //TODOAuto-generatedmethodstub }}UserDao.javapackagecom.NewsSystem.model.service.dao;importjava.sql.Connection;importjava.sql.ResultSet;importjava.sql.ResultSetMetaData;importjava.sql.SQLException;importjava.util.ArrayList;importjava.util.HashMap;importjava.util.List;importjava.util.Map;importcom.NewsSystem.controller.servlet.NewsUser;importcom.NewsSystem.model.connection.DefaultConnectionFactory;importcom.NewsSystem.model.service.dao.page.PageInfo;publicclassUserDaoextendsBaseDao{ publicbooleancreate(ObjectentityObject){ booleanb=false; NewsUseruser=(NewsUser)entityObject; conn=newDefaultConnectionFactory().getConnection(); Stringsql="insertintoNEWS_USER(username,userpassword)values('"+user.getUserName()+"','"+user.getUserPassWord()+"')"; tr

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論