ssi框架学习总结(mvc三层架构)(3)
applicationContext-web.xml: xml version="1.0" encoding="UTF-8"beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http:/
applicationContext-web.xml:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> <!-- 配置数据源,连接池采用的是c3p0,具体各参数代表意义参看c3p0自带的doc,非常详细。 --> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <property name="driverClass" value="${jdbc.driverClass}" /> <property name="jdbcUrl" value="${jdbc.url}" /> <property name="user" value="${jdbc.user}" /> <property name="password" value="${jdbc.password}" /> <property name="minPoolSize" value="${jdbc.minPoolSize}" /> <property name="maxPoolSize" value="${jdbc.maxPoolSize}" /> <property name="maxIdleTime" value="${jdbc.maxIdleTime}" /> <property name="acquireIncrement" value="${jdbc.acquireIncrement}" /> <property name="maxStatements" value="${jdbc.maxStatements}" /> <property name="initialPoolSize" value="${jdbc.initialPoolSize}" /> <property name="idleConnectionTestPeriod" value="${jdbc.idleConnectionTestPeriod}" /> <property name="acquireRetryAttempts" value="${jdbc.acquireRetryAttempts}" /> </bean> <!-- 上面的数据源的value值用的是表达式,原因就在这里,这将配置文件放到了iBatis目录下,也就是jdbc.properties,设置了c3p0的各项参数 --> <bean id="propertyConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location"> <value>/WEB-INF/ibatis/jdbc.properties</value> </property> </bean> <!-- 配置iBatis的sqlMapClient,这里当然是交给了spring去处理,其中,将SqlMapConfig文件放到了WEB-INF的iBatis目录下,也是便于管理 --> <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean"> <property name="configLocation"> <value>/WEB-INF/ibatis/SqlMapConfig.xml</value> </property> <!-- 这里使用的数据源就是上面配置的数据源 --> <property name="dataSource"> <ref bean="dataSource" /> </property> </bean> <bean id="userdaoId" class="com.broada.demo.daoImpl.UserDaoImpl"> <property name="sqlMapClient" ref="sqlMapClient"></property> </bean> <bean id="userDaoServiceId" class="com.broada.demo.serviceImpl.UserDaoServiceImpl"> <property name="userdao" ref="userdaoId"> </property> </bean> <!-- 用户注册action--> <bean id="registerAction" name="registerAction" class="com.broada.demo.action.RegisterAction" scope="prototype"> <property name="userdaoServiceInter" ref="userDaoServiceId"></property> </bean> </beans>
这样,ssi框架的大致配置就完成了。
最后编写相关的dao层,service层,action层以及jsp等等,我就不详细说明了,直接上相关代码:
RegisterAction.java:
package com.broada.demo.action; /** * @author smm */ import com.broada.demo.entity.User; import com.broada.demo.service.UserDaoServiceInter; import com.opensymphony.xwork2.ActionSupport; public class RegisterAction extends ActionSupport { private static final long serialVersionUID = 1L; private UserDaoServiceInter userdaoServiceInter; public UserDaoServiceInter getUserdaoServiceInter() { return userdaoServiceInter; } public void setUserdaoServiceInter(UserDaoServiceInter userdaoServiceInter) { this.userdaoServiceInter = userdaoServiceInter; } private String name; //用户名 private String password; //密码 private String username; //昵称 private String address; //地址 public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String addUser() { System.out.println("添加成功!"); User user = new User(); String name = this.name; String password = this.password; String username = this.username; String address = this.address; user.setName(name); user.setPassword(password); user.setUsername(username); user.setAddress(address); boolean b = userdaoServiceInter.insertUser(user); if (b==true) { return SUCCESS; } else return INPUT; } public String loginUser(){ System.out.println("登陆======="); String name = this.name; String password = this.password; User user = userdaoServiceInter.querybyname(name); if(user != null && password.equals(user.getPassword())){ return SUCCESS; } else return ERROR; } }
精彩图集
精彩文章