JDBC Case _ paging _ conditional query

Source: Internet
Author: User
Tags dateformat locale

Customer information Adding and deleting and checking system


Software engineering Development process: 1, Waterfall Model 2, spiral model


RUP (Rational Unified processes, unified software development process) uses waterfall models: requirements---Requirements analysis---system design (summary, detailed design)----CODING---testing---implementation---maintenance
* Waterfall model defects before the end of the code, the customer can not see the final software products, if the requirements, design obvious errors, resulting in late software maintenance, there are significant defects
* Waterfall model for new software, the risk of uncertain software requirements


Agile Development Concept: Iterative development model, the system functions into several batches, for each part of the function to implement the waterfall model process, the system at any time to see the development results, there is always available software products
* Incremental development, find design errors halfway, easy to adjust


1, the need for customer information to delete and change
2. System Design
Database Design E-r Diagram


Create Database CustomerSystem;
* Each software will create a separate user for the database and authorize


Create User: Flower identified by ' flower ';
Authorization: Grant all on customersystem.* to flower;


Create a data table
CREATE TABLE Customer (
ID varchar (+) primary key NOT NULL,
Name varchar () unique NOT NULL,
Gender varchar (TEN) is not NULL,
Birthday date NOT NULL,
Cellphone varchar () NOT NULL,
Email varchar (max) unique NOT NULL,
Preference varchar (100),
Type varchar (40),
Description varchar (255)
);


----------------------------------------------------
Start Navicat Lite----Create connection (name write, fill in username, password)
Double-click to open Connection
Right-click on the connection on the new database---create CustomerSystem
Double-click Database development Database
Create a data table----the database/table right-click New Table Customer


Above the tool, click Manager Users---ADD user to create flower users
Click User to expand the specific database----Select All to grant CustomerSystem all permissions for user flower


----------------------------------------------------
system function Design
1) technology selection MySQL + Servlet + JSP + EL +jstl + beanutils + c3p0 + dbutils
2) Build the engineering environment
Create a Customermanager project and copy the jar package Web-inf/lib
Preparing the C3P0 configuration file
3) Create the package structure (Java EE three layer structure)
Cn.itcast.customer.web
Cn.itcast.customer.service
Cn.itcast.customer.dao
Cn.itcast.customer.domain
Cn.itcast.customer.utils


Use C3P0, dbutils----Need tool class
Entity class Customer


4) Release the Customer management system-----Virtual Hosting Mode
Configure Tomcat/conf/server.xml Add a virtual host www.customer.com----path to the project root directory
Modify the local Hosts file to add the domain name resolution----127.0.0.1 www.customer.com
The project is issued WebRoot configure the default virtual directory <context path= "" docbase= "WebRoot"/>


5) design Add, query, delete, modify four functions---UML Unified Modeling Language (UML) also known as Unified Modeling Language or standard modeling language
Many UML tools are drawn: Rantional Rose, Microsoft Visio, StarUML, Jude (Pure Java development)
* UML do software modeling (analysis Design): Use case diagram, Class diagram, time series diagram


-----------------------------------------------------------------------------------------
UML sequence diagram in Enterprise development: Describing system function flow in time order
Coding
1. Add Customer Information
Add.jsp (write customer Add form form JS form check)-----addcustomerservlet (Web layer encapsulates form data into JavaBean object; Pass JavaBean to Business layer processing)---- CustomerService (business layer)---customerdao (data-tier completion table insertion)----The web layer chooses the jump page based on the Business layer processing results


2. View (all) customer information
Index.jsp (Submit link)------Listcustomersservlet (Web layer, call the business layer directly for results)----customerservice (business layer)---customerdao (data tier Complete all customer information inquiries)---
The web layer chooses the jump page (list.jsp) based on the business layer results----list.jsp (Jstl+el display list results)


3. Deletion of Customer information
Single-line Delete (can provide delete button/link after each row of data)----Click the link to delete the row to display the data
list.jsp (delete link)------Submit customer number Delcustomerservlet (get number, pass number business layer)----customerservice (business layer pass Number data layer)---customerdao (delete )---The web layer decides the jump page (list.jsp all data before displaying list.jsp, jump Listcustomersservlet)
* Add confirmation action on delete function (JavaScript)
Scenario One: Block href default events
FF E.preventdefault ()
IE Window.event.returnValue = false;
Scenario Two: Link did not submit, in JS to determine the user to confirm the deletion, with JS submit link Event Location.href


Bulk Delete (add a checkbox before each row of data)
* Full selection of JS operation, all selected, all canceled
* Bulk Delete Add confirmation onsubmit= "return Confirmbatchdel ()"
* In bulk Delete process, add transaction management


4, Customer information modification operation
Process one: Customer Information inquiry
list.jsp (add modify link after each row of data)----Showcustomerservlet (Receive number delivery number business layer)---customerservice---customerdao----The web layer will receive Returns the Customer object, passing the customer object to the JSP (update.jsp to echo the data in the form)


Process two: Modification of customer information
Update.jsp (contains all customer information for hidden IDs)----Updatecustomerservlet (encapsulating form data to JavaBean, passing javabean to the business layer)----customerservice--- Customerdao----Web tier Jump Customer Information list page (/listcustomers)


-----------------------------------------------------------------------
Why do I need to split pages? Too much data to be displayed on one page, pagination display
Paging technology implementation: two kinds of


Physical paging: Querying data----Dependent database SQL statements when executing queries in a database (implementing paged queries)
Logical paging: First querying all data to memory, and then capturing from memory requires data-------using the internal logic of the program


Physical paging: Mysql/sqlserver/oracle Each database is written in a different way
MySQL uses limit, SQL Server uses top, Oracle uses RowNum


Limit syntax: Select .... limit start record index, record number of bars
SELECT * FROM table limit 10, 20; Index starting from 0 10 for 11------from 11 query 30


Logical paging: Querying all data List, List.sublist intercept you need data
For example: Query 11-30 list.sublist (start index, end index); -----list.sublist (10,30) before taking it;


* * Performance: Physical paging is better than logical paging----use physical paging as much as possible


Pagination Page Effect:
First Prev 1 2 3 4 5 6 7 Next last jump XX page
* Homepage which page--1 last which page?
* Page number can not be displayed all (Google is the current page number of the center, front and back 10 pages)----to the left display the minimum page number (first page) display the maximum page number (last)
* Total Pages


Refactoring the Morning paging query: A paged query encapsulates the query result with a separate class Pagebean-----return data in the business layer return Pagebean object


--------------------------------------------------------------------------------------------------------------- ---
Conditional query: Single condition and compound condition
Single-condition query, provide a select box within the page, the user selects the Query field, enter the value
LIST.JSP----Submit the query condition Conditionqueryservlet (get the conditional delivery business layer)----customerservice---customerdao---the Web tier to get results, passing the results list.jsp display
* Because many fields are selected, all fields may be handled differently by name fuzzy query phone equivalent query, if judgment processing
* When fuzzy query, do not know the query condition like ' percent '; represent any string---query all data


---------------------------------------------------------------------


System functions:
1. Add Customer Information
2, the customer all information inquiry
3. Deletion of customer information (single-line deletion, bulk deletion)
4. Modification of Customer information
5. Add Paging Query

6. Single Condition select query


Import Java.text.dateformat;import java.text.simpledateformat;import Java.util.date;import Java.util.Locale;import Org.junit.test;public class Dateformattest {@Testpublic void Demo3 () {//set Localelocale locale = new locale ("Ja", "JP", "J P ");D ate date = new Date ();D Ateformat DateFormat = dateformat.getdatetimeinstance (Dateformat.full,dateformat.full, locale); System.out.println (Dateformat.format (date));}  @Testpublic void Demo2 () {//format date with a self-styled style//1 only dates Date date = new Date ();//four display modes full, LONG, MEDIUM, Shortdateformat df1 = Dateformat.getdateinstance (Dateformat.short); System.out.println (Df1.format (date));//2 only time DateFormat DF2 = dateformat.gettimeinstance (dateformat.full); System.out.println (Df2.format (date));//3rd and time DateFormat df3 = dateformat.getdatetimeinstance (Dateformat.full, Dateformat.full); System.out.println (Df3.format (date));} @Testpublic void Demo1 () {//format custom format for dates Date date = new Date ();D ateformat dateformat = new SimpleDateFormat ("YYYY year mm month DD Day hh mm minutes ss seconds "); System.out.priNtln (Dateformat.format (date));}} 
import java.text.messageformat;import java.util.calendar;import java.util.Date; Import Java.util.locale;import Org.junit.test;public class Messageformattest {@Testpublic void Demo2 () {//Date time internationalization, Currency digital Internationalization String msg = "at {0,time,short} on {0,date,medium}, a hurricance destroyed {1} houses and caused {2,number,currency } of damage "; Calendar calendar = Calendar.getinstance (); Calendar.set (1998, 6, 3, N, 0);D ate Date = Calendar.gettime (); object[] Arg s = {date, 99, 1000000};//default country localestring result = Messageformat.format (msg, args); SYSTEM.OUT.PRINTLN (result);//Set Localemessageformat format = new Messageformat (msg, locale.us); String result2 = Format.format (args); System.out.println (RESULT2);} @Testpublic void Demo1 () {///dynamic text message internationalization, content with {number} placeholder string msg = "at {0} on {1}, a hurricance destroyed {2} houses and CA Used {3} of damage "; object[] args = {" 12:30pm pm "," Jul 3,1998 ", 99," $1000000 "}; System.out.println (Messageformat.format (msg, args));}} 


Import Java.text.dateformat;import java.text.numberformat;import java.text.parseexception;import java.util.Date; Import Java.util.locale;import Org.junit.test;public class Numberformattest {@Testpublic void exec () throws ParseException {///Create a Date object, and put the time value representing the date part in Date object, as well as the time value representing the time part, formatted output in short, long, respectively (country set to China). Date date = new Date ();D Ateformat DateFormat = dateformat.getdatetimeinstance (Dateformat.short, Dateformat.long, Locale.china); System.out.println (Dateformat.format (date));//09-11-28 10:25 A.M. 39 sec CST Restore Date----DateFormat parsestring s = "09-11-28 10:25 A.M. 39 sec CST ";D ate date2 = Dateformat.parse (s); When parsing, confirm that the original string display mode System.out.println (DATE2);//Please convert the integer 198, output to currency form: $198, and parse $198 backwards into integer 198. int n = 198; String m = "$198"; NumberFormat format = numberformat.getcurrencyinstance (locale.us); format.setmaximumfractiondigits (0); System.out.println (Format.format (n)); System.out.println (Format.parse (m));///Please set 0.78654321, output percent format, retain two decimal places double d = 0.78654321; NumberFormat format2 = Numberformat.getnumbeRinstance (); format2.setmaximumfractiondigits (2); format2.setminimumfractiondigits (2); System.out.println (Format2.format (d)); @Testpublic void Demo3 () {//display percent double d = 0.78123; NumberFormat format = numberformat.getpercentinstance ();//Displays two decimal places format.setmaximumfractiondigits (2); Format.setminimumfractiondigits (2); System.out.println (Format.format (d)); @Testpublic void Demo2 () {//currency formatted int d = 100;//displays USD numberformat format = numberformat.getcurrencyinstance (locale.us); System.out.println (Format.format (d)); @Testpublic void Demo1 () {//reserved decimal number of significant digits double d = 1.235456674567546;//reserved Two decimal places NumberFormat format = Numberformat.getnumberin Stance ();//maximum two decimal places format.setmaximumfractiondigits (2);//Minimum two decimal places format.setminimumfractiondigits (2); System.out.println (Format.format (d));}}

Import Java.util.locale;import Java.util.resourcebundle;import Org.junit.test;public class ResourceBundleTest {@ testpublic void Demo2 () {///read file, set my country locale locale = new locale ("en", "US"); ResourceBundle bundle = Resourcebundle.getbundle ("myproperties", locale);//Read EN_USSYSTEM.OUT.PRINTLN ( Bundle.getstring ("name"));} @Testpublic void Demo1 () {//Use ResourceBundle to read the configuration file, do not set the country resourcebundle bundle = Resourcebundle.getbundle (" Myproperties ");//Which file is selected by default? UK-default, China---zh_cn//system country Priority > Default SYSTEM.OUT.PRINTLN (bundle.getstring ("name"));}}





















































































































Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.