Upload
steve-ng
View
298
Download
2
Tags:
Embed Size (px)
DESCRIPTION
Dependency injection and Basic Introduction to Spring
Citation preview
package com.habuma.ejb.session; import javax.ejb.SessionBean; import javax.ejb.SessionContext; public class HelloWorldBean implements SessionBean{ public void ejbActivate(){} public void ejbPassivate(){} public void ejbRemove(){} public void setSessionContext(SessionContextctx){} public void ejbCreate(){} public String sayHello(){ return"HelloWorld"; } }
package com.habuma.spring; public class HelloWorldBean{ public String sayHello(){ return"HelloWorld"; } }
package session.stateless; import javax.ejb.Stateless; import javax.ejb.LocalBean; @Stateless @LocalBean public class ForDemo { public String sayHello() { return "HelloWorld"; } }
http://www.youtube.com/watch?v=CkjRvBMwzo4
1. Spring Aspect-oriented programing(AOP) framework
2. Boilerplate reduction through templates
3. Spring Inverse Of Control (IOC) container
1. Spring Aspect-oriented programing(AOP) framework
2. Boilerplate reduction through templates
3. Spring Inverse Of Control (IOC) container
public EmployeegetEmployeeById(longid){ Connectionconn=null; PreparedStatementstmt=null; ResultSetrs=null; try {
conn =dataSource.getConnection();
stmt =conn.prepareStatement( "select id,firstname,lastname,salaryfrom"+ "employee whereid=?"); stmt.setLong(1,id);
rs =stmt.executeQuery(); Employeeemployee=null;
if (rs.next()){
employee=newEmployee(); employee.setId(rs.getLong("id")); employee.setFirstName(rs.getString("firstname")); employee.setLastName(rs.getString("lastname")); employee.setSalary(rs.getBigDecimal("salary"));
}
return employee;
} catch(SQLExceptione){ } finally{
if(rs!=null){ try {
rs.close(); } catch(SQLExceptione){}
} if(stmt!=null){
try { stmt.close();
} catch(SQLExceptione){} } if(conn!=null){
try { conn.close();
} catch(SQLExceptione){} }
} return null;
}
public EmployeegetEmployeeById(longid) {
return jdbcTemplate.queryForObject( "select id,firstname,lastname,salary"+ "from employeewhereid=?",
new RowMapper<Employee>(){
public EmployeemapRow(ResultSetrs, int rowNum)throwsSQLException{
Employee employee=newEmployee(); employee.setId(rs.getLong("id")); employee.setFirstName(rs.getString("firstname")); employee.setLastName(rs.getString("lastname")); employee.setSalary(rs.getBigDecimal("salary")); return employee;
} }
,id); }
http://www.springsource.org/ - Home page of Spring framework. Contains documentation of how to use Spring