- 浏览: 39341 次
- 性别:
- 来自: 北京
最新评论
-
on-the-way:
很精辟啊
最近仔细研究了一下Java的NIO以及线程并发,搞清了点思路,特作笔记如下(NIO篇) -
wdlfellow:
现在需要在项目中做单元测试了,学习mock中。。。
junit 中的mock 使用摘记
1,doman
package com.baobaotao.domain;
import java.io.Serializable;
import java.util.Date;
public class LoginLog implements Serializable {
private int loginLogId;
private int userId;
private String ip;
private Date loginDate;
....省略getter ,setter 方法
}
package com.baobaotao.domain;
import java.io.Serializable;
import java.util.Date;
public class User implements Serializable {
private int userId;
private String userName;
private String password;
private int credits;
private String lastIp;
private Date lastVisit;
.....省略getter,setter方法
}
2.dao
package com.baobaotao.dao;
import com.baobaotao.domain.LoginLog;
//
public interface LoginLogDao {
public void insertLoginLog(LoginLog loginLog);
}
package com.baobaotao.dao;
import com.baobaotao.domain.User;
public interface UserDao {
public int getMatchCount(String userName,String password);
public User findUserByUserName(String userName);
public void updateLoginInfo(User user);
}
package com.baobaotao.dao.jdbc;
import org.springframework.jdbc.core.JdbcTemplate;
import com.baobaotao.dao.LoginLogDao;
import com.baobaotao.domain.LoginLog;
public class LogonLogDaoImpl implements LoginLogDao {
private JdbcTemplate jdbcTemplate;
public void setJdbcTemplate(JdbcTemplate jdbcTemplate){
this.jdbcTemplate=jdbcTemplate;
}
public void insertLoginLog(LoginLog loginLog) {
String sqlStr=" insert into t_login_log(user_id,ip,login_datetime) "
+" values(?,?,?) ";
Object[] args={loginLog.getUserId(),loginLog.getIp(),loginLog.getLoginDate()};
jdbcTemplate.update(sqlStr,args);
}
}
package com.baobaotao.dao.jdbc;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowCallbackHandler;
import com.baobaotao.dao.UserDao;
import com.baobaotao.domain.User;
public class UserDaoImpl implements UserDao {
private JdbcTemplate jdbcTemplate;
public void setJdbcTemplate(JdbcTemplate jdbcTemplate){
this.jdbcTemplate=jdbcTemplate;
}
public User findUserByUserName(final String userName) {
String sqlStr=" select user_id,user_name,credits "+
" from t_user where user_name=? ";
final User user=new User();
jdbcTemplate.query(sqlStr, new Object[]{userName},new RowCallbackHandler(){
public void processRow(ResultSet rs)throws SQLException{
user.setUserId(rs.getInt("user_id"));
user.setUserName(userName);
user.setCredits(rs.getInt("credits"));
}
});
return user;
}
public int getMatchCount(String userName, String password) {
String sqlStr=" select count(*) from t_user "+
" where user_name=? and password=? ";
return jdbcTemplate.queryForInt(sqlStr, new Object[]{userName,password});
}
public void updateLoginInfo(User user) {
String sqlStr=" update t_user set last_visit=?,last_ip=?,credits=? "
+" where user_id=? ";
jdbcTemplate.update(sqlStr,new Object[]{user.getLastVisit(),user.getLastIp(),user.getCredits(),user.getUserId()});
}
}
3,service
package com.baobaotao.service;
import com.baobaotao.dao.LoginLogDao;
import com.baobaotao.dao.UserDao;
import com.baobaotao.domain.User;
public interface UserService {
//����û���/�������ȷ��
public boolean hasMatchUser(String userName,String password);
//���û���Ϊ�������User����
public User findUserByUserName(String userName);
//�����û�����½ʱ���IP��Ϣ,ͬʱ��¼�û���¼��־
public void loginSuccess(User user);
}
package com.baobaotao.service;
import com.baobaotao.dao.LoginLogDao;
import com.baobaotao.dao.UserDao;
import com.baobaotao.domain.LoginLog;
import com.baobaotao.domain.User;
public class UserServiceImpl implements UserService {
private UserDao userDao;
private LoginLogDao loginLogDao;
public void setUserDao(UserDao userDao){
this.userDao=userDao;
}
public void setLoginLogDao(LoginLogDao loginLogDao){
this.loginLogDao=loginLogDao;
}
public User findUserByUserName(String userName) {
// TODO Auto-generated method stub
return userDao.findUserByUserName(userName);
}
public boolean hasMatchUser(String userName, String password) {
// TODO Auto-generated method stub
int matchCount=userDao.getMatchCount(userName, password);
return matchCount>0;
}
public void loginSuccess(User user) {
user.setCredits(5+user.getCredits());
LoginLog loginLog=new LoginLog();
loginLog.setUserId(user.getUserId());
loginLog.setIp(user.getLastIp());
loginLog.setLoginDate(user.getLastVisit());
userDao.updateLoginInfo(user);
loginLogDao.insertLoginLog(loginLog);
}
}
4,web
package com.baobaotao.web;
public class LoginCommand {
private String userName;
private String password;
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
}
package com.baobaotao.web;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractCommandController;
import com.baobaotao.domain.User;
import com.baobaotao.service.UserService;
public class LoginController extends AbstractCommandController {
private UserService userService;
public LoginController() {
setCommandClass(LoginCommand.class);
}
public void setUserService(UserService userService) {
this.userService = userService;
}
@Override
protected ModelAndView handle(HttpServletRequest request,
HttpServletResponse response, Object command, BindException errors)
throws Exception {
LoginCommand loginCommand = (LoginCommand) command;
boolean isValidUser = userService.hasMatchUser(loginCommand
.getUserName(), loginCommand.getPassword());
if (!isValidUser) {
return new ModelAndView("login", "error", "用户名或密码错误。");
} else {
User user = userService.findUserByUserName(loginCommand
.getUserName());
user.setLastIp(request.getLocalAddr());
user.setLastVisit(new Date());
userService.loginSuccess(user);
request.getSession().setAttribute("user", user);
return new ModelAndView("main");
}
}
}
package com.baobaotao.web;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;
public class LoginPage extends AbstractController {
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request,
HttpServletResponse response) throws Exception {
return new ModelAndView("login");
}
}
5.装配dao
baobaotao-dao.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>
<!-- 配置数据源 -->
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="url" value="jdbc:mysql://localhost:3306/sampledb"></property>
<property name="username" value="root"></property>
<property name="password" value="root"></property>
</bean>
<!-- 配置jdbc模板 -->
<bean id="jdbcTemplate"
class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"></property>
</bean>
<!-- 配置dao -->
<bean id="loginLogDao"
class="com.baobaotao.dao.jdbc.LogonLogDaoImpl">
<property name="jdbcTemplate" ref="jdbcTemplate"></property>
</bean>
<bean id="userDao"
class="com.baobaotao.dao.jdbc.UserDaoImpl">
<property name="jdbcTemplate" ref="jdbcTemplate"></property>
</bean>
</beans>
baobaotao-service.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>
<!-- 事务管理器 -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
<bean id="userSerivceTarget"
class="com.baobaotao.service.UserServiceImpl">
<property name="userDao" ref="userDao"></property>
<property name="loginLogDao" ref="loginLogDao"></property>
</bean>
<!-- 声明式事务 -->
<bean id="userService"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager" ref="transactionManager"></property>
<property name="target" ref="userSerivceTarget"></property>
<property name="transactionAttributes">
<props>
<prop key="findUserByUserName">
PROPAGATION_REQUIRED,readOnly
</prop>
<prop key="hasMatchUser">
PROPAGATION_REQUIRED,readOnly
</prop>
<prop key="loginSuccess">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
</beans>
log4j.properties
log4j.rootLogger=INFO,A1
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%d %5p [%t] (%F:%L) - %m%n
baobaotao-servlet.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>
<bean name="loginController"
class="com.baobaotao.web.LoginController">
<property name="userService" ref="userService"></property>
</bean>
<bean name="loginPage"
class="com.baobaotao.web.LoginPage">
</bean>
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/loginController.html">loginController</prop>
<prop key="/index.html">loginPage</prop>
</props>
</property>
</bean>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/jsp/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
</beans>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:baobaotao-dao.xml,classpath:baobaotao-service.xml
</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<servlet>
<servlet-name>baobaotao</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>baobaotao</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
</web-app>
build.xml
<?xml version="1.0" encoding="utf-8"?>
<!--
编译worklog中的数据库连接
-->
<project basedir="." default="build" name="baobaotao">
<!-- 定义变量 -->
<property name="project.name" value="baobaotao" />
<property name="src.dir" value="src" />
<!-- Java源文件目录 -->
<!-- 编译好的类及生成的javadoc文档目录 -->
<property name="build.dir" value="WebRoot/WEB-INF/classes" />
<property name="weblib.dir" value="WebRoot/WEB-INF/lib" />
<property name="war.dir" value="WebRoot" />
<property name="dist.dir" value="dist" />
<property name="spring.root" value="../spring" />
<property name="jdbclib.root" value="../extraLib/jdbclib" />
<!-- 用到的外部类包,即classpath -->
<path id="project.class.path">
<fileset dir="${spring.root}/dist">
<include name="spring.jar" />
</fileset>
<fileset dir="${spring.root}/lib/log4j">
<include name="log4j-1.2.14.jar" />
</fileset>
<fileset dir="${spring.root}/lib/jakarta-commons">
<include name="commons-dbcp.jar" />
<include name="commons-logging.jar" />
<include name="commons-pool.jar" />
</fileset>
<fileset dir="${spring.root}/lib/jakarta-taglibs">
<include name="standard.jar" />
</fileset>
<fileset dir="${spring.root}/lib/j2ee">
<include name="servlet-api.jar" />
<include name="jstl.jar" />
</fileset>
</path>
<target name="build" depends="clean,warfile">
</target>
<target name="clean" description="Clean output dirs (build, weblib, dist)">
<delete dir="${build.dir}" />
<delete dir="${weblib.dir}" />
<delete dir="${dist.dir}" />
</target>
<target name="compile" description="编译java">
<mkdir dir="${build.dir}" />
<javac destdir="${build.dir}" srcdir="${src.dir}">
<compilerarg line="-encoding UTF-8" />
<classpath refid="project.class.path" />
</javac>
<copy todir="${build.dir}">
<fileset dir="${src.dir}">
<include name="**/*.properties" />
<include name="**/*.xml" />
</fileset>
</copy>
<mkdir dir="${weblib.dir}" />
<copy todir="${weblib.dir}" preservelastmodified="true">
<fileset dir="${spring.root}/dist">
<include name="spring.jar" />
</fileset>
<fileset dir="${spring.root}/lib/log4j">
<include name="log4j-1.2.14.jar" />
</fileset>
<fileset dir="${spring.root}/lib/jakarta-commons">
<include name="commons-dbcp.jar" />
<include name="commons-logging.jar" />
<include name="commons-pool.jar" />
</fileset>
<fileset dir="${spring.root}/lib/j2ee">
<include name="jstl.jar" />
</fileset>
<fileset dir="${spring.root}/lib/jakarta-taglibs">
<include name="standard.jar" />
</fileset>
<fileset dir="${jdbclib.root}">
<include name="mysql.jar" />
</fileset>
</copy>
</target>
<target name="warfile" depends="compile" description="创建Web应用程序War包">
<mkdir dir="${dist.dir}" />
<war warfile="${dist.dir}/${project.name}.war" basedir="${war.dir}" webxml="${war.dir}/WEB-INF/web.xml">
<include name="*" />
<include name="images/**" />
<include name="WEB-INF/*.*" />
<include name="WEB-INF/lib/**" />
<include name="WEB-INF/jsp/**" />
<include name="WEB-INF/classes/**" />
<exclude name="WEB-INF/web.xml" />
<exclude name="**/.*" />
</war>
</target>
</project>
package com.baobaotao.domain;
import java.io.Serializable;
import java.util.Date;
public class LoginLog implements Serializable {
private int loginLogId;
private int userId;
private String ip;
private Date loginDate;
....省略getter ,setter 方法
}
package com.baobaotao.domain;
import java.io.Serializable;
import java.util.Date;
public class User implements Serializable {
private int userId;
private String userName;
private String password;
private int credits;
private String lastIp;
private Date lastVisit;
.....省略getter,setter方法
}
2.dao
package com.baobaotao.dao;
import com.baobaotao.domain.LoginLog;
//
public interface LoginLogDao {
public void insertLoginLog(LoginLog loginLog);
}
package com.baobaotao.dao;
import com.baobaotao.domain.User;
public interface UserDao {
public int getMatchCount(String userName,String password);
public User findUserByUserName(String userName);
public void updateLoginInfo(User user);
}
package com.baobaotao.dao.jdbc;
import org.springframework.jdbc.core.JdbcTemplate;
import com.baobaotao.dao.LoginLogDao;
import com.baobaotao.domain.LoginLog;
public class LogonLogDaoImpl implements LoginLogDao {
private JdbcTemplate jdbcTemplate;
public void setJdbcTemplate(JdbcTemplate jdbcTemplate){
this.jdbcTemplate=jdbcTemplate;
}
public void insertLoginLog(LoginLog loginLog) {
String sqlStr=" insert into t_login_log(user_id,ip,login_datetime) "
+" values(?,?,?) ";
Object[] args={loginLog.getUserId(),loginLog.getIp(),loginLog.getLoginDate()};
jdbcTemplate.update(sqlStr,args);
}
}
package com.baobaotao.dao.jdbc;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowCallbackHandler;
import com.baobaotao.dao.UserDao;
import com.baobaotao.domain.User;
public class UserDaoImpl implements UserDao {
private JdbcTemplate jdbcTemplate;
public void setJdbcTemplate(JdbcTemplate jdbcTemplate){
this.jdbcTemplate=jdbcTemplate;
}
public User findUserByUserName(final String userName) {
String sqlStr=" select user_id,user_name,credits "+
" from t_user where user_name=? ";
final User user=new User();
jdbcTemplate.query(sqlStr, new Object[]{userName},new RowCallbackHandler(){
public void processRow(ResultSet rs)throws SQLException{
user.setUserId(rs.getInt("user_id"));
user.setUserName(userName);
user.setCredits(rs.getInt("credits"));
}
});
return user;
}
public int getMatchCount(String userName, String password) {
String sqlStr=" select count(*) from t_user "+
" where user_name=? and password=? ";
return jdbcTemplate.queryForInt(sqlStr, new Object[]{userName,password});
}
public void updateLoginInfo(User user) {
String sqlStr=" update t_user set last_visit=?,last_ip=?,credits=? "
+" where user_id=? ";
jdbcTemplate.update(sqlStr,new Object[]{user.getLastVisit(),user.getLastIp(),user.getCredits(),user.getUserId()});
}
}
3,service
package com.baobaotao.service;
import com.baobaotao.dao.LoginLogDao;
import com.baobaotao.dao.UserDao;
import com.baobaotao.domain.User;
public interface UserService {
//����û���/�������ȷ��
public boolean hasMatchUser(String userName,String password);
//���û���Ϊ�������User����
public User findUserByUserName(String userName);
//�����û�����½ʱ���IP��Ϣ,ͬʱ��¼�û���¼��־
public void loginSuccess(User user);
}
package com.baobaotao.service;
import com.baobaotao.dao.LoginLogDao;
import com.baobaotao.dao.UserDao;
import com.baobaotao.domain.LoginLog;
import com.baobaotao.domain.User;
public class UserServiceImpl implements UserService {
private UserDao userDao;
private LoginLogDao loginLogDao;
public void setUserDao(UserDao userDao){
this.userDao=userDao;
}
public void setLoginLogDao(LoginLogDao loginLogDao){
this.loginLogDao=loginLogDao;
}
public User findUserByUserName(String userName) {
// TODO Auto-generated method stub
return userDao.findUserByUserName(userName);
}
public boolean hasMatchUser(String userName, String password) {
// TODO Auto-generated method stub
int matchCount=userDao.getMatchCount(userName, password);
return matchCount>0;
}
public void loginSuccess(User user) {
user.setCredits(5+user.getCredits());
LoginLog loginLog=new LoginLog();
loginLog.setUserId(user.getUserId());
loginLog.setIp(user.getLastIp());
loginLog.setLoginDate(user.getLastVisit());
userDao.updateLoginInfo(user);
loginLogDao.insertLoginLog(loginLog);
}
}
4,web
package com.baobaotao.web;
public class LoginCommand {
private String userName;
private String password;
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
}
package com.baobaotao.web;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractCommandController;
import com.baobaotao.domain.User;
import com.baobaotao.service.UserService;
public class LoginController extends AbstractCommandController {
private UserService userService;
public LoginController() {
setCommandClass(LoginCommand.class);
}
public void setUserService(UserService userService) {
this.userService = userService;
}
@Override
protected ModelAndView handle(HttpServletRequest request,
HttpServletResponse response, Object command, BindException errors)
throws Exception {
LoginCommand loginCommand = (LoginCommand) command;
boolean isValidUser = userService.hasMatchUser(loginCommand
.getUserName(), loginCommand.getPassword());
if (!isValidUser) {
return new ModelAndView("login", "error", "用户名或密码错误。");
} else {
User user = userService.findUserByUserName(loginCommand
.getUserName());
user.setLastIp(request.getLocalAddr());
user.setLastVisit(new Date());
userService.loginSuccess(user);
request.getSession().setAttribute("user", user);
return new ModelAndView("main");
}
}
}
package com.baobaotao.web;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;
public class LoginPage extends AbstractController {
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request,
HttpServletResponse response) throws Exception {
return new ModelAndView("login");
}
}
5.装配dao
baobaotao-dao.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>
<!-- 配置数据源 -->
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="url" value="jdbc:mysql://localhost:3306/sampledb"></property>
<property name="username" value="root"></property>
<property name="password" value="root"></property>
</bean>
<!-- 配置jdbc模板 -->
<bean id="jdbcTemplate"
class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"></property>
</bean>
<!-- 配置dao -->
<bean id="loginLogDao"
class="com.baobaotao.dao.jdbc.LogonLogDaoImpl">
<property name="jdbcTemplate" ref="jdbcTemplate"></property>
</bean>
<bean id="userDao"
class="com.baobaotao.dao.jdbc.UserDaoImpl">
<property name="jdbcTemplate" ref="jdbcTemplate"></property>
</bean>
</beans>
baobaotao-service.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>
<!-- 事务管理器 -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
<bean id="userSerivceTarget"
class="com.baobaotao.service.UserServiceImpl">
<property name="userDao" ref="userDao"></property>
<property name="loginLogDao" ref="loginLogDao"></property>
</bean>
<!-- 声明式事务 -->
<bean id="userService"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager" ref="transactionManager"></property>
<property name="target" ref="userSerivceTarget"></property>
<property name="transactionAttributes">
<props>
<prop key="findUserByUserName">
PROPAGATION_REQUIRED,readOnly
</prop>
<prop key="hasMatchUser">
PROPAGATION_REQUIRED,readOnly
</prop>
<prop key="loginSuccess">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
</beans>
log4j.properties
log4j.rootLogger=INFO,A1
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%d %5p [%t] (%F:%L) - %m%n
baobaotao-servlet.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>
<bean name="loginController"
class="com.baobaotao.web.LoginController">
<property name="userService" ref="userService"></property>
</bean>
<bean name="loginPage"
class="com.baobaotao.web.LoginPage">
</bean>
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/loginController.html">loginController</prop>
<prop key="/index.html">loginPage</prop>
</props>
</property>
</bean>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/jsp/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
</beans>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:baobaotao-dao.xml,classpath:baobaotao-service.xml
</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<servlet>
<servlet-name>baobaotao</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>baobaotao</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
</web-app>
build.xml
<?xml version="1.0" encoding="utf-8"?>
<!--
编译worklog中的数据库连接
-->
<project basedir="." default="build" name="baobaotao">
<!-- 定义变量 -->
<property name="project.name" value="baobaotao" />
<property name="src.dir" value="src" />
<!-- Java源文件目录 -->
<!-- 编译好的类及生成的javadoc文档目录 -->
<property name="build.dir" value="WebRoot/WEB-INF/classes" />
<property name="weblib.dir" value="WebRoot/WEB-INF/lib" />
<property name="war.dir" value="WebRoot" />
<property name="dist.dir" value="dist" />
<property name="spring.root" value="../spring" />
<property name="jdbclib.root" value="../extraLib/jdbclib" />
<!-- 用到的外部类包,即classpath -->
<path id="project.class.path">
<fileset dir="${spring.root}/dist">
<include name="spring.jar" />
</fileset>
<fileset dir="${spring.root}/lib/log4j">
<include name="log4j-1.2.14.jar" />
</fileset>
<fileset dir="${spring.root}/lib/jakarta-commons">
<include name="commons-dbcp.jar" />
<include name="commons-logging.jar" />
<include name="commons-pool.jar" />
</fileset>
<fileset dir="${spring.root}/lib/jakarta-taglibs">
<include name="standard.jar" />
</fileset>
<fileset dir="${spring.root}/lib/j2ee">
<include name="servlet-api.jar" />
<include name="jstl.jar" />
</fileset>
</path>
<target name="build" depends="clean,warfile">
</target>
<target name="clean" description="Clean output dirs (build, weblib, dist)">
<delete dir="${build.dir}" />
<delete dir="${weblib.dir}" />
<delete dir="${dist.dir}" />
</target>
<target name="compile" description="编译java">
<mkdir dir="${build.dir}" />
<javac destdir="${build.dir}" srcdir="${src.dir}">
<compilerarg line="-encoding UTF-8" />
<classpath refid="project.class.path" />
</javac>
<copy todir="${build.dir}">
<fileset dir="${src.dir}">
<include name="**/*.properties" />
<include name="**/*.xml" />
</fileset>
</copy>
<mkdir dir="${weblib.dir}" />
<copy todir="${weblib.dir}" preservelastmodified="true">
<fileset dir="${spring.root}/dist">
<include name="spring.jar" />
</fileset>
<fileset dir="${spring.root}/lib/log4j">
<include name="log4j-1.2.14.jar" />
</fileset>
<fileset dir="${spring.root}/lib/jakarta-commons">
<include name="commons-dbcp.jar" />
<include name="commons-logging.jar" />
<include name="commons-pool.jar" />
</fileset>
<fileset dir="${spring.root}/lib/j2ee">
<include name="jstl.jar" />
</fileset>
<fileset dir="${spring.root}/lib/jakarta-taglibs">
<include name="standard.jar" />
</fileset>
<fileset dir="${jdbclib.root}">
<include name="mysql.jar" />
</fileset>
</copy>
</target>
<target name="warfile" depends="compile" description="创建Web应用程序War包">
<mkdir dir="${dist.dir}" />
<war warfile="${dist.dir}/${project.name}.war" basedir="${war.dir}" webxml="${war.dir}/WEB-INF/web.xml">
<include name="*" />
<include name="images/**" />
<include name="WEB-INF/*.*" />
<include name="WEB-INF/lib/**" />
<include name="WEB-INF/jsp/**" />
<include name="WEB-INF/classes/**" />
<exclude name="WEB-INF/web.xml" />
<exclude name="**/.*" />
</war>
</target>
</project>
- baobaotao.war (3.5 MB)
- 下载次数: 10
相关推荐
使用Spring框架为企业开发带来的好处包括: 1. **组件解耦**:通过IOC,组件之间的耦合度降低,每个组件只需关注自身的业务逻辑,依赖关系由Spring容器负责管理和维护。 2. **事务管理**:Spring提供了声明式事务...
《Spring Boot企业级开发教程》配套资料是一份全面学习Spring Boot技术栈的宝贵资源,它涵盖了从基础到进阶的企业级应用开发知识。这个压缩包包含的教学材料多样,旨在帮助学习者深入理解并掌握Spring Boot的核心...
《Spring Boot企业级开发教程》配套资源.zip是一个包含多种学习材料的压缩文件,专为学习和研究Spring Boot的企业级开发而设计。这个资源包旨在帮助用户深入理解和掌握Spring Boot框架,以及与其相关的Java和后端...
* Mysql安装:Mysql是SpringBlade的默认数据库,需要安装Mysql的社区版或企业版。 工程导入 使用SpringBlade可以快速创建微服务工程,通过简单的步骤可以生成一个基本的微服务系统平台。 * 工程创建:使用Spring...
Java EE企业级应用开发教程(Spring+Spring MVC+MyBatis)SSM源码Java EE企业级应用开发教程(Spring+Spring MVC+MyBatis)SSM源码Java EE企业级应用开发教程(Spring+Spring MVC+MyBatis)SSM源码Java EE企业级应用...
《精通Spring企业应用开发实战》是一本深度剖析Spring在企业级应用开发中的实践指南,旨在帮助读者全面理解和掌握Spring框架的核心特性和高级用法。这本书的内容丰富,涵盖了Spring的各个重要模块,包括依赖注入、...
1.精通Spring 4.x 企业应用开发实战精通Spring 4.x 企业应用开发实战精通Spring 4.x 企业应用开发实战精通Spring 4.x 企业应用开发实战精通Spring 4.x 企业应用开发实战精通Spring 4.x 企业应用开发实战精通Spring 4...
Spring框架是由Rod Johnson创建的开源框架,旨在解决企业应用开发的复杂性。Spring框架的出现极大地简化了企业级应用的开发,并且不仅仅局限于服务器端的开发。Spring的核心概念之一是使用简单的JavaBean来实现之前...
《精通Spring4.x+企业应用开发实战》这本书的配套光盘包含了丰富的源码和资源,旨在帮助读者深入理解和掌握Spring4.x框架在实际企业开发中的应用。Spring4.x是Java领域中最受欢迎的轻量级开源框架之一,它以其模块化...
精通Spring 4.x 企业应用开发实战 高清完整版PDF书及随书源码。 精通Spring 4.x 企业应用开发实战 高清完整版PDF书及随书源码 Spring 4.0是Spring在积蓄4年后,隆重推出的一个重大升级版本,进一步加强了Spring作为...
《精通Spring4.x企业应用开发实战》是一本深入解析Spring框架在企业级应用中的实践指南。这本书涵盖了Spring框架的核心概念、重要特性和实际应用,旨在帮助开发者熟练掌握Spring4.x版本的各种开发技能,以提高软件...
本书是在《精通Spring 3.x――企业应用开发详解》的基础上,历时一年的重大调整改版而成的,延续了上一版本“追求深度,注重原理,不停留在技术表面”的写作风格,力求使读者在熟练使用Spring的各项功能的同时透彻...
《Spring 3.x企业应用开发实战》是一本深入讲解Spring框架在企业级应用程序开发中的实践指南。这本书专注于Spring 3.x版本,该版本是Spring框架发展史上的一个重要里程碑,引入了许多新特性和改进,旨在提升开发效率...
Spring作为Java企业级应用开发的主流框架,以其强大的功能、灵活的设计和广泛的社区支持,成为了现代Java开发者的必备工具。这份手册详细介绍了Spring的核心概念、配置、组件以及最佳实践,涵盖了从基础到高级的所有...
Spring MVC之一 第20章 Spring MVC之二 第21章 集成其他Web框架 第6篇 其他 第22章 Spring应用的测试 第23章 Spring工具类盘点 附录A 各种数据库连接配置及驱动 附录B IDE开发环境设置 ...
spring 4.0企业开发实战。写的不错,。。。。。。。。。
Spring势如破竹,占据着Java领域轻量级开发的王者地位。随着Java语言的发展以及市场开发的需求,Spring推陈出新,推出了全新的Spring Boot框架。Spring Boot是Spring家族的一个子项目,其设计初衷是为了简化Spring...
《精通Spring 4.x 企业应用开发实战》是由陈雄华编著的一本深度解析Spring 4.x框架的书籍,适合于对Java EE有基础的开发者进行深入学习和提升。这本书详细介绍了如何在企业环境中利用Spring 4.x进行高效、稳定的应用...