一、安装jdk1.7
祥见http://zhinan.sogou.com/guide/detail/?id=1610006590
二、创建web项目
略
三、配置ssm环境
3.1添加spring、mybatis、springMvc的jar包及他们之间的整合包
3.2添加三个配置文件并配置相关参数
web.xml文件
<param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> <servlet-name>springmvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext-mvc.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springmvc</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping>
applicationContext.xml文件
<!-- 读取properties文件org.springframework.beans.factory.config.PlaceholderConfigurerSupport --> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath:dbconfig.properties</value> </list> </property> </bean> <!-- 配置数据库 --> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="${jdbc.driver}"/> <property name="url" value="${jdbc.url}"/> <property name="username" value="${jdbc.username}"/> <property name="password" value="${jdbc.password}"/> </bean> <!-- 配置会话工厂org.mybatis.spring.SqlSessionFactoryBean --> <!-- 配置mybatis --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="configLocation" value="classpath:mybatis-config.xml"></property> <!-- mapper扫描 --> <property name="mapperLocations" value="classpath:mybatis/*/*.xml"></property> </bean> <!-- 启用注解 --> <context:annotation-config /> <!-- aop激活自动代理功能 --> <aop:aspectj-autoproxy proxy-target-class="true"/> <!-- 事务处理器 --> <bean id="txManage" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"/> </bean>
applicationContext-mvc.xml文件
<context:component-scan base-package="com.diancan.controller"/> <!-- 配置SpringMVC的视图解析器 --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/jsp/"/> <property name="suffix" value=".jsp"/> </bean>
mybatis-config.xml文件
<settings> <setting name="cacheEnabled" value="true" /><!-- 全局映射器启用缓存 --> <setting name="useGeneratedKeys" value="true" /> <setting name="defaultExecutorType" value="REUSE" /> </settings> <!-- 别名 --> <typeAliases> <typeAlias type="com.diancan.util.PageData" alias="pd"/> <!-- 分页 --> <typeAlias type="com.diancan.entity.Page" alias="Page"/> </typeAliases>
dbconfig.properties文件
jdbc.driver:com.mysql.jdbc.Driver jdbc.url:jdbc:mysql://localhost:3306/diancan jdbc.username:root jdbc.password:root
四、创建需要的各种包
let‘s do it!
时间: 2024-09-30 19:39:48