# Many-to-many (student and teacher table structure) 0. C3P0 Tool Class 1. Building domain class and corresponding table structure Student information table Studentprivate int id;private string Name;private string Grade;private list<teacher> Teachers = new arraylist<teacher> (); Teacher Information table private int id;//integerprivate String name;private float money;private L ist<student> students = new arraylist<student> (); 2. Teacherdaoimpl class void Addteacher (Teacher T1)//judge whether the student exists, why should judge, because if not to judge, when added to the second teacher, the student union again added to the table, the primary key has also bound Teacher Findteacherbyid (int i) 3. Test class Addtest () Teacher t1= new Teacher (); T1.setid (1); T1.setname ("QB"); T1.setmoney (10000); Teacher t2= New Teacher () T2.setid (2); T2.setname ("WYJ"); T2.setmoney (10000); Student S1 = new Student () S1.setid (1); S1.setname ("DDD"); S1.setgrade ("A"); Student s2 = new Student () S2.setid (2); S2.setname ("DJJ"); S2.setgrade ("A"); Testquery ()
Paging Technology
1. To establish the corresponding table structure of the domain class CREATE TABLE account (ID int primary key, name varchar (sum), money float); Insert to account V Alues (1, ' aaa ', + +); INSERT into account values (2, ' BBB ', 1300); Insert to account values (3, ' CCC ', 1100); INSERT INTO Account VALUES (4, ' DDD ', 1400), insert into account values (5, ' Eee ', 13300), insert into account values (6, ' FFF ', 1100); Insert into account values (7, ' Zhang San ', 22100), insert to account values (8, ' Xiao Chen ', 13300); INSERT into account values (9, ' Gillian ', Insert into account values (10, ' 5500 ', "+"), insert into account values (11, ' brother Li ', +); INSERT into account values (12, ' GGG ', (); INSERT into account values ("HHH", +);------------------------------------------ Or use circular statements to insert data in bulk Accountdaoimpl DAO = new Accountdaoimpl (); Account A = new account (); Random r = new Random (); String base = Unicode.getunicode (), for (int i=1; i<100; i++) {A.setid (i); A.setname (Base.charat (R.nextint ( Base.length ())) + "" "+base.charat (R.nextint (Base.length ())) +" "+base.charat (R.nextint (Base.length ())) +" "); A.setmoney (10000.00F+I*20);d Ao.updateaccount (a);} ------------------------------------------Java class accountprivate int id;private String name;private float money;2. The data access Layer Accountdaoimpl class int getcount ()//Gets the total record list<account> getaccountbypage (int startIndex, int size)//Gets each page of content, Used as a paging query 3. Establish Pagebean class private int prep;//Previous page Getprep if the current page is less than 1, the previous page equals 1;prep = 1; otherwise the previous page equals = = Current Page -1;prep = pageno-1;private int nextp;// Next GETNEXTP If the next page is greater than the total number of pages, the next page equals the total number of pages nextp = This.gettotalpage (); otherwise the next page equals the current page +1 nexp = pageno+1;private int totalpage;// Total Pages-->gettotalpage If the total number of records to be displayed per page shows the number of records equals 0 totalpage=totalrecordes/pagesize otherwise totalpage=totalrecordes/pagesize+1; private int startindex;//Index of the first record of the current page (current page-1) *pagesize--->getstartindex//in order to join the scrolling number private int endpageno;private int beginpageno;1. If the current page is less than 9, the start page is 1 and the end page is the total number of pages 2. Otherwise start Page-4, end page corresponding +4 if the start page is less than 0beginpage=1, if the end page is greater than the total number of pages endpageno=this.gettotalpage ();p rivate int pageno=1;//the current page private int pagesize=3;//number of records displayed per page private int totalrecordes;//total records private list recordes;//the current page records private String url;4. Business Layer ACCountserviceimpl class void Findaccountbypage (Pagebean pb)//Paging query sets the total number of records and the current page record 5. ControllerServlet1. Garbled problem/Generate a paging component/get new current page/2. If the current page is not empty and is not equal to NULL, set the current page to 3 in the paging component. Call the business method to implement paging query 4. Sets the URL5 in the paging component. Set the paging Component object to 6 in the request domain. Forward to page in page design 1. Index.jsp<jsp:forward> forwarded to servlet 2. List.jsp the data in the database is displayed in the table statically contains PAGE.JSP3. Page.jsp1. The current page/Total page shows the previous page 2. Scrolling numbers traverse each page begin/end3. Next page 4. Select page (Change event onchange=changepage (this)) traverse each page changepage (objopt) {Address bar Information submit page go to option value}
Listener 1. Custom Listener
1. Loginservlet class 1.1 Solve garbled problem 1.2 get login parameter 1.3 Call business logic, determine whether the user login is successful ... 1.4 Create a User object, encapsulate the login parameters 1.5 set user to session field 1.6 Redirect to Main Page 2. Listen to the data in the domain using the listener, if you have added a value to the Session field, you can use the listener class to hear it, so create a new Userlistener class, implement the Httpsessionattributelistener class, Implement the method configuration web.xml2.1 first obtained by Httpsessionbindingevent to session object 2.2 Gets the user object in session 2.3 if the object is empty directly return 2.4 Create user Object 2.5 Determines whether the object in the session is the user class, if the object is assigned to user2.6 directly if the user object is not equal to null through the session object gets the ServletContext classic code implementation to set the map to the context domain (note map to synchronize ) to add the session object to the Map collection in 3. Kick out Kickservlet Class 3.1 get username parameter 3.2 will username handle garbled, encode decode 3.3 get ServletContext3.4 get map3.5 in the context domain to get map session3.6 If the session is not equal to NULL, remove the user3.7 from the session by username remove the user 3.8 Redirect to the home page design 1 from the collection. LOGIN.JSP provides a login page, submitted to the login LoginServlet2. INDEX.JSP Home page, if the user in session is not empty, display the online list of users because the user needs to be displayed globally, so there needs to be a list of users in the map, and then iterate through the collection using <c:url > tags to encapsulate the address bar information, Request parameter username, value, traverse key to add kick Man feature link to URL