In the afternoon, I couldn't help looking at seek and searching for Java. I found a lot of work that made people drool. But I told me to hold on to it. I don't need to submit my resume for a while. I still have 40 days of training. After training, I started to invest.
After training for a few days, I felt that I had made a lot of improvement in my skills. Many of the positions I didn't invest in before now seem confident.
We hope to lock a globle company in time.
Continue with today's learning. After reading the basics of JPA, switch back to struts. In this way, you can continue Struts-> hibernate-> spring and start the project.
This is the simplest Struts framework, and the program is a small module for managing users (actually far from that simple, this is just a framework ). The database uses the simplest prototype of the user module of the sxt DRP project.
In the past, companies would not use such a simple framework, but it is suitable to describe struts applications.
The most basic DAO design
From the code point of view, it is mainly used as follows:
First, look for all users in JSP,
In struts:
Public class listuseraction extends action {
Public actionforward execute (actionmapping mapping, actionform form, httpservletrequest request, httpservletresponse response) throws exception {
// Call the business logic operation
List userlist =Usermanager. getinstance (). findalluserlist ();
Request.Setattribute ("userlist", userlist);
Return Mapping. findforward ("success ");
}
}
Usermanager:
Public list findalluserlist (){
List userlist = new arraylist ();
Try {
Userlist =Userdao. findalluserlist ();
} Catch (exception e ){
E. printstacktrace ();
}
Return userlist;
}
In the key implementation class
Public list findalluserlist (){
StringSQL = "select * From t_user where user_id <> 'root' order by user_id ";
System. Out. println ("userdao4mysqlimpl => findalluserlist => SQL =" + SQL );
Connection conn = NULL;
Statement stmt = NULL;
Resultset rs = NULL;
List userlist = new arraylist ();
Try {
Conn = dB. getconn ();
Stmt = conn. createstatement ();
Rs = stmt.exe cutequery (SQL );
While (Rs. Next ()){
User user = new user ();
User. setuserid (Rs. getstring ("user_id "));
User. setusername (Rs. getstring ("user_name "));
User. setpassword (Rs. getstring ("password "));
User. setcontacttel (Rs. getstring ("contact_tel "));
User. setemail (Rs. getstring ("email "));
User. setcreatedate (Rs. gettimestamp ("create_date "));
Userlist. Add (User );
}
} Catch (sqlexception e ){
E. printstacktrace ();
} Finally {
DB. closers (RS );
DB. closestmt (stmt );
DB. closeconn (conn );
}
Return userlist;
}
Later, we can use struts and other ORM technologies to greatly simplify the process. The above method should be rarely used at present.