Struts + Hibernate + Oracle Patement

xiaoxiao2021-03-06  40

Mainly by: message.jspMessageFormMessageActionPlayer.hbm.xmlstruts-config.xmlMeisaiBean.java achieved: look at the database structure: CREATE TABLE player (PLAYER_ID VARCHAR (32) PRIMARY KEY, TEAM VARCHAR (3), displayName VARCHAR (100), LAST_NAME VARCHAR (100), middle_name varchar (100), Status Varchar (32), POS varchar (1), PPG Integer Default 25);

INSERT INTO Player (Player_ID, Team, DisplayName, Last_name, Middle_name, Status, POS) Values ​​('2113999', 'DAL', 'Dirk', NULL, ', NULL,' F '); Insert Into Player (Player_ID, Team, DisplayName, Last_name, Middle_name, Status, POS, Values ​​('30361', 'IND', 'RON', 'ARTEST', '', 'A', 'g'); Insert Into Player (Player_ID, Team, DisplayName, Last_name, Middle_Name, Status, POS) VALUES ('30273', 'orl', 'TRACY', 'MCGRADY', '', 'A', 'F'); INSERT INTO Player (Player_ID, Team, DisplayName, Last_name, middle_name, status, pos) Values ​​('30190', 'LAL', 'Kobe', 'Bryant', ',' A ',' g '); Insert Into Player (Player_ID, Team, DisplayName, Last_name, Middle_name, status, pos) Values ​​('30328', 'sea', 'rashard', 'Lewis', '', 'A', 'g'); Insert Into Player (Player_ID, Team, DisplayName, Last_name, Middle_name, Status, POS) VALUES ('30197', 'NJN', 'Kerry', 'Kittles', '', 'A', 'G'); Insert Into Player (Player_ID, Team, DisplayName, Last_name, Middle_Name, Status, POS) VALUES ('30341', 'Hou', 'Steve', 'Francis', '', 'A', 'G'); Insert Into Player (Player_ID, Team, DisplayName, Last_name, Middle_Name, Status, P OS) VALUES ('30146', 'Min', 'Kevin', 'Garnett', '', 'A', 'F'); Insert Into Player (Player_ID, Team, DisplayName, Last_name, Middle_Name, Status, POS) VALUES ('2113993', 'BOS', 'Paul', 'Pierce', '', 'A', 'g');

Insert Into Player (Player_ID, Team, DisplayName, Last_name, Middle_Name, Status, POS) Values ​​('30050', 'NJN', 'Jason ",' KIDD ',' ',' A ',' G '); Insert Into Player (Player_ID, Team, DisplayName, Last_name, Middle_Name, Status, POS) VALUES ('30215', 'ATL', 'Shareef', 'Abdur-Rahim', '', 'I', 'F'); Insert Into Player (Player_ID, Team, DisplayName, Last_Name, Middle_Name, Status, POS) Values ​​('1861922', 'orl', 'Mike', 'Miller', '', 'I', 'F'); Insert Into Player Player_ID, Team, DisplayName, Last_name, Middle_name, Status, POS) Values ​​('30144', 'ATL', 'Glenn', 'Robinson', ',' A ',' F '); Insert Into Player (Player_ID, Team, DisplayName, Last_name, Middle_Name, Status, POS, Values ​​('2019703', 'GSW', 'Gilbert', 'Arenas', '', 'A', 'G'); Insert Into Player (Player_ID, Team, DisplayName, Last_name, Middle_Name, Status, POS, VALUES ('2028505', 'uth', 'andrei', 'Kirilenko', '', 'I', 'F'); Insert Into Player (Player_ID, Team, DisplayName, Last_name, middle_name, status, pos) Values ​​('30382', 'pho', 'Shawn', 'Marion', '', 'A', 'F'); Insert Into Player (Player_ID, Team, DisplayName, Last_name, M IDDLE_NAME, STATUS, POS VALUES ('29941', 'Sea', 'Brent', 'Barry', '', 'A', 'G'); Insert Into Player (Player_ID, Team, DisplayName, Last_name, Middle_name, Status, POS) VALUES ('2114000', 'DAL', 'Michael', 'Finley', '', 'A', 'G');

INSERT INTO Player (Player_ID, Team, DisplayName, Last_name, Middle_Name, Status, POS) Values ​​('30187', 'Bos',' Antoine ',' Walker ',', 'A', 'F'); Insert Into Player (Player_ID, Team, DisplayName, Last_name, Middle_Name, Status, POS) Values ​​('30234', 'Sac', 'Bobby', 'Jackson', ',' A ',' G '); Insert Into Player Player_ID, Team, DisplayName, Last_name, Middle_name, Status, POS, ',' Jerry ',' Stackhouse ',' ',' A ',' G '); Insert Into Player (Player_ID, Team, DisplayName, Last_name, Middle_name, Status, POS, Values ​​('29944', 'Sac', 'Doug', 'Christie', '', 'I', 'G'); Insert Into Player (Player_ID, Team, DisplayName, Last_name, Middle_Name, Status, POS) Values ​​('30095', 'Chi', 'Donyll', 'Marshall', '', 'A', 'F'); Insert Into Player (Player_ID, Team, DisplayName, Last_name, middle_name, status, pos) Values ​​('2028865', 'ATL', 'Ira', 'Newble', '', 'A', 'F'); INSERT INTO Player (Player_ID, Team, DisplayName, Last_name, Middle_name, status, pos) VALUES ('30029,' Sea ',' Gary ',' Payton ',', 'A', 'g'); Insert Into Player (Player_ID, Team, DisplayName, Last_name, Middle_n AME, STATUS, POS) VALUES ('30141', 'Tor', 'Voshon', 'LENARD', '', 'A', 'G'); INSERT INTO Player (Player_ID, Team, DisplayName, Last_name, Middle_Name, Status, POS) VALUES ('30020', 'Mil', 'Toni', 'Kukoc', '', 'A', 'F');

INSERT INTO Player (Player_ID, Team, DisplayName, Last_name, Middle_Name, Status, POS) Values ​​('30154', 'Nor', 'Pj', 'Brown', '', 'A', 'F'); Insert Into Player (Player_ID, Team, DisplayName, Last_name, Middle_name, Status, POS) Values ​​('30125', 'MIA', 'EDDIE', 'Jones', '', 'A', 'G'); Insert Into Player Player_ID, Team, DisplayName, Last_name, Middle_Name, Status, POS, 'Jason,' Terry ',' ',' A ',' g '); Insert Into Player (Player_ID, Team, DisplayName, Last_name, Middle_Name, Status, POS, Values ​​('30291', 'uth', 'Matt', 'Harpring', ',' A ',' F '); Insert Into Player (Player_ID, Team, DisplayName, Last_name, Middle_Name, Status, POS) Values ​​('30228', 'Mil', 'Ray', 'Allen', '', 'A', 'g'); Insert Into Player (Player_ID, Team, DisplayName, Last_name, middle_name, status, pos) Values ​​('2028503', 'SEA', 'VLADIMIR', 'RADMANOVIC', '', 'A', 'F'); the corresponding Player.hbm.xml is as follows:

now look at Meisaibean. JavaPackage com.ecc.util; import java.io.serializable;

Public Class Meisaibean Implements Serializable {

Public Meisaibean () {}

Public string label_1 = "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "

Public string getLabel_1 () {return this.label_1;}

Public String Label_2 = "" "; PUBLIC VOID SETLABEL_2 (String Str) {this.label_2 = Str;}

Public string getlabel_2 () {return this.label_2;}

Public String Label_3 = "" "" "" "PUBLIC VOID SETLABEL_3 (String Str) {this.label_3 = Str;} public string getLabel_3 () {return this.label_3;}

Public String Label_4 = "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "

Public String getLabel_4 () {Return this.Label_4;}

Public string label_5 = "" "" "; String Str) {this.label_5 = Str;}

Public String getLabel_5 () {return this.label_5;}

Public String Label_6 = "" "; PUBLIC VOID SetLabel_6 (String Str) {this.label_6 = Str;}

Public String getLabel_6 () {return this.label_6;}

Public String Label_7 = ""; PUBLIC VOID SetLabel_7 (String Str) {this.label_7 = Str;}

Public string getLabel_7 () {return this.label_7;}

Public string label_8 = "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "

Public string getlabel_8 () {return this.Label_8;}

Public string label_9 = "" ", public void setlabel_9 (string str) {this.label_9 = Str;}

Public string getlabel_9 () {return this.label_9;}

Public String Label_10 = ""; PUBLIC VOID SetLabel_10 (String Str) {this.label_10 = Str;}

Public String getLabel_10 () {Return this.label_10;}

Public string label_11 = ""; public void setlabel_11 (string str) {this.label_11 = Str;}

Public string getlabel_11 () {return this.Label_11;}

Public String Label_12 = ""; PUBLIC VOID SETLABEL_12 (String Str) {this.label_12 = Str;}

Public String getLabel_12 () {Return this.label_12;}

Public String Label_13 = "" "" "" "" "PUBLIC STR) {this.Label_13 = Str;} public string getLabel_13 () {return this.label_13;}

Public String Label_14 = ""; public void setLabel_14 (string str) {this.label_14 = str;}

Public String getLabel_14 () {return this.label_14;}

Public string label_15 = ""; public void setlabel_15 (string str) {this.label_15 = Str;}

Public String getLabel_15 () {Return this.Label_15;}

Public string label_16 = ""; public void setlabel_16 (string str) {this.label_16 = Str;}

Public String getLabel_16 () {return this.label_16;}

Public string label_17 = ""; public void setlabel_17 (string str) {this.label_17 = Str;}

Public string getlabel_17 () {return this.Label_17;}

Public string label_18 = ""; public void setlabel_18 (string str) {this.label_18 = Str;}

Public string getlabel_18 () {return this.Label_18;

Public string label_19 = ""; public void setlabel_19 (string str) {this.label_19 = Str;}

Public String getLabel_19 () {return this.label_19;}

Public String Label_20 = "" "; public void setlabel_20 (string str) {this.label_20 = Str;}

Public String getLabel_20 () {Return this.label_20;}

Public string label_21 = ""; public void setLabel_21 (string str) {this.label_21 = str;}

Public String getLabel_21 () {return this.label_21;}} messageform.java:

// Created by myeclipse struts // xsl source (default): platform: /plugin/com.genuitec.eclipse.cross.easystruts.eclipse_3.8.2/xslt/javaclass.xsl

package com.ecc.struts.message.formbean; import org.apache.struts.action.ActionForm; import javax.servlet.http.HttpServletRequest; import org.apache.struts.action.ActionErrors; import org.apache.struts.action .ActionForm; import org.apache.struts.action.ActionMapping; import java.util *; / ** * MyEclipse Struts * Creation date:. 01-06-2005 * * XDoclet definition: * @struts: form name = "testRegistForm "* / Public class messageform extends an actionform {public messageform ()} private string label1 =" "

/ ** * @Return * / public string getlabel1 () {return label1;}

/ ** * @param string * / public void setLabel1 (String string) {label1 = string;} private Vector meisai = new Vector (); public void setMeisai (Vector meisai) {this.meisai = meisai;} public Vector getMeisai ( ) {return meisai;} private int currentpage = 0; / ** * @Return * / public int getCurrentPage () {Return CurrentPage;}

/ ** * @Param i * / public void setCurrentPage (INT i) {currentpage = i;} private int totalpage = 0; / ** * @return * / public int gettotalpage () {Return Totalpage;}

/ ** * @Param i * / public void settotalpage (INT i) {totalpage = i;}

} MessageAction.java: //created by myeclipse struts // xsl source (default): platform: /plugin/com.genuitec.eclipse.cross.Easystruts.eclipse_3.8.2/xslt/javaclass.xsl

package com.ecc.struts.message.action; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.Action; import org. apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.apache.struts.action.SessionActionMapping; import org.apache.struts.action. ActionError; import org.Apache.struts.action.actionerroters; import com.ecc.struts.MPort com.ecc.util. *; Import java.security. *; Import com.ecc.util.security .pausword. *; import com.ecc.exception.regist. *; import com.ecc.hibernate.db. *; import net.sf.hibernate. *; import net.sf.hibernate.cfg. *; import COM. Ecc.hibernate. *; import com.ecc.hibernate.hbm. *; import java.util. *; public class message --------------------------------------- Instance Variables

/ / -------------------------------------------------------------------------------------------- --------- Methods

/ ** * Method execute * @param mapping * @param form * @param request * @param response * @return ActionForward * / private void setPage (ActionForm form, int currentPage) {Transaction tx = null; Session session = null; int totalCount = 0; String playerid = ""; String team = ""; String displayname = ""; int firstIndex = 0; int itemsInPerPage = 10; try {MessageForm messageForm = (MessageForm) form; session = HbUnit.getSession (); tx = session.beginTransaction (); currentPage = messageForm.getCurrentPage (); if (currentPage <= 0) {messageForm.setCurrentPage (1); firstIndex = 0;} else {firstIndex = currentPage * itemsInPerPage-itemsInPerPage;} String sql = "select player from Player as player"; Query query = session.createQuery (sql); query.setFirstResult (firstIndex); query.setMaxResults (itemsInPerPage); Iterator it = query.iterate (); Vector meisaiList = new Vector (); while (it.hasNext ()) {Player player = (Player) it.next (); playerid = StrHandle.replaNull (player.getPlayerId ()); team = StrHandle.replaNull (player.getTeam ()); displayname = StrHandle .replanull (Player.getd) ISPLAYNAME ()); Meisaibean Meisai = new meisaibean ();

meisai.setLabel_1 (playerid); meisai.setLabel_2 (team); meisai.setLabel_3 (displayname); meisaiList.add (meisai);} messageForm.setMeisai (meisaiList); tx.commit ();} catch (Exception ex) {try {tx.rollback ();} catch (exception eex) {} system.out.println (ex); ex.printstacktrace ();} finally {{hbunit.closesis ();} catch (exception ex) {}} } private int getRecordsize () {Transaction tx = null; session session = null; int totalcount = 0; try {session = hbUnit.getations (); tx = session.begintransaction (); totalcount = ((integer) session.Itemate "Select count (*) from player"). next ()) .intValue (); tx.commit (); return totalcount;} catCh (Exception EX) {TRY {TX.ROLLBACK ();} catch (Exception EEX) {} System.out.println (ex); ex.printStackTrace (); return -1;} finally {try {HbUnit.closeSession ();} catch (Exception ex) {}}} public ActionForward execute (ActionMapping mapping, ActionForm Form, httpservletRequest request, httpservletResponse response) {messageform messageform = (messageform) form;

String target = ""; int size = 0; int perItemsPage = 10; int modItems = 0; int totalPages = 0; int currentPage = 0; try {currentPage = messageForm.getCurrentPage (); size = getRecordSize (); if (size <= 0) {target = "noitemfound";} else {Totalpages = size / peritems = size% peritemspage; if (MODITEMS> 0) Totalpages = 1; System.out.Println ("Record Size:" size) System.out.println ("Total Page: Totalpages); MessageForm.SettotalPage (Totalpages); SESTEM.OT.Println (" Total Page: Totalpages); target = "success" ;}}}} catch (exception ex) {system.out.println (ex.printstacktrace ();} return (maping.findforward (target));}} message.jsp as follows: <% @ page language = "Java "%> <% @ page contenttype =" text / html; charset = GB2312 "%> <% @ taglib URI =" / Web-inf / struts-html.tld "prefix =" html "%> <% @ Taglib URI = "/ Web-inf / struts-bean.tld" prefix = "bean"%> <% @ Taglib URI = "/ Web-inf / struts-logic.tld" prefix = "logic"%> JSP for testregistform form </ title> <style type = text / css> font-size: 9pt {} a {color: # 000000; Text-Decoration: None} a: hover {text-decoration: underline} .bt {border-top-width: 0px; font-limited: 9pt; border-bottom-width: 0px; width: 50px; cursor : Hand; Height: 16px; Background-Color: # 808080; border-right-width: 0px} .tx1 {border-right: black 1px ridge; border-top: black 1px ridge; font-size: 9pt; border-left : Black 1PX Ridge; Width: 60pt; Color: # 000000; Border-Bottom: # 000000 1px Ridge; Height: 20px} </ stop> <</p> <p>/ Head> <Script Language = "JavaScript"> function gotoNext () {var currentPage = parseInt (MessageForm.currentPage.value); var totalPage = parseInt (MessageForm.totalPage.value); currentPage = currentPage 1; if (currentPage> totalPage) {currentPage = totalPage;} var url = "message.do?currentPage =" currentPage; alert (url); document.location = url;} function gotoPrev () {var currentPage = parseInt (MessageForm.currentPage.value) ; var totalPage = parseInt (MessageForm.totalPage.value); if (currentPage <= 0) {currentPage = 0;} else {currentPage = currentPage-1;} var url = "message.do?currentPage =" currentPage; alert (URL); Document.Location = URL;} Function Gototop () {</p> <p>VAR URL = "message.do?currentpage=1"; Alert (URL); Document.Location = URL;} Function Gotolast () {var TotalPage = PARSEINT (MessageForm.Totalpage.Value); var URL = "message.do? CurrentPage = " Totalpage; Alert (URL); Document.Location = URL;} </ script> <body> <html: form name =" messageform "action =" / message.do "type =" com.ecc.struts .Message.form ".Messageform "Scope =" request "> <html: text protety =" currentpage "/> </br> <html: text protety =" totalpage "/> </br> </ html: form> < Table> <tr> <TD> <input value = "TOP" type = "button" οnclick = "gototop ();"> <td> <input value = "prev" type = "button" οnclick = "gotoprev () "> <TD> <input value =" οnclick = "button" οnclick = "gotonext ();"> <TD> <input value = "type =" button "οnclick =" gotolast (); " > </ tr> </ table> <table border = '1'> <logic: present name = "messageform" scope = "request"> <logic: orthrate id = "meisailist" name = "messageform" Property = "Meisai "scope =" request "> <tr> <td> <bean: write name =" meisailist "proty =" label_1 "/> </ td> <td> <bean: write name =" meisailist "property =" label_2 " /> </ Td > <TD> <bean: write name = "meisailist" property = "label_3" /> </ td> </ tr> </ logic: Itereate> <</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-68161.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="68161" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.059</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'OquHiPEVGGxbl1A7orVma0RzJhoIlRy7AWS0RDVe2aaPbq74JQAGig9umAwztfGD0fHp4J8RiUC8GcDdZSDGaw_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>