SSM框架整合实现增删改查(简单的实现)SSM框架整合实现增删改查
⽂件结构
POM⽂件
<packaging>war</packaging>
<!-- 处理乱码 -->
<properties>
<!-- 设置项⽬字符集 -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- spring版本号 -->
<spring.version>4.3.2.RELEASE</spring.version>
</properties>
<dependencies>
<!--Dao层Mybatis  jar包  -->
<!-- mybatis -->
<dependency>
mysql面试题 增删改查<groupId&batis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.5</version>
</dependency>
<!-- mysql -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>  <version>8.0.11</version>
</dependency>
<!-- druid -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.8</version>
</dependency>
<!-- Service层 Spring -->
<!-- Spring-context -->
<dependency>
<groupId>org.springframework</groupId>  <artifactId>spring-context</artifactId>
<version>4.3.2.RELEASE</version>
</dependency>
<!-- Spring-core -->
<dependency>
<groupId>org.springframework</groupId>  <artifactId>spring-core</artifactId>
<version>4.3.2.RELEASE</version>
</dependency>
<!-- Spring-bean -->
<dependency>
<groupId>org.springframework</groupId>  <artifactId>spring-beans</artifactId>
<version>4.3.2.RELEASE</version>
</dependency>
<!-- Spring-expression -->
<dependency>
<groupId>org.springframework</groupId>  <artifactId>spring-expression</artifactId>
<version>4.3.2.RELEASE</version>
</dependency>
<!-- Spring-tx -->
<dependency>
<groupId>org.springframework</groupId>  <artifactId>spring-tx</artifactId>
<version>4.3.2.RELEASE</version>
</dependency>
<!-- Spring-jbdc -->
<dependency>
<groupId>org.springframework</groupId>  <artifactId>spring-jdbc</artifactId>
<version>4.3.2.RELEASE</version>
</dependency>
<!-- Spring-mybatis -->
<dependency>
<groupId&batis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.3.2</version>
</dependency>
<!-- Servlet层SpringMVC -->
<!-- Spring-web -->
<dependency>
<groupId>org.springframework</groupId>  <artifactId>spring-web</artifactId>
<version>4.3.2.RELEASE</version>
</dependency>
<!-- Spring-mvc -->
<dependency>
<groupId>org.springframework</groupId>  <artifactId>spring-webmvc</artifactId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.2.RELEASE</version>
</dependency>
<!-- servlet -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
<!-- jsp -->
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.3</version>
<scope>provided</scope>
</dependency>
<!-- jsp.jstl -->
<dependency>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- servlet.jstl -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- standard -->
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
error parse return value<!-- aspect注解 -->
<!--使⽤AspectJ⽅式注解需要相应的包 -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.6.11</version>
</dependency>
<!--使⽤AspectJ⽅式注解需要相应的包 -->
<dependency>
手机新闻网页模板
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.6.11</version>
</dependency>
</dependencies>
<!-- Tomcat插件 -->
<build>
<!-- 配置tomcat插件,web端 -->
<plugins>
<plugin>
<groupId>at.maven</groupId>    <artifactId>tomcat7-maven-plugin</artifactId>    <configuration>
<path>/</path>
<port>8080</port>
金字塔魔方教程图解
</configuration>
</plugin>
</plugins>
</build>
Mybatis的XML⽂件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="/schema/beans"
xmlns:xsi="/2001/XMLSchema-instance"
xmlns:p="/schema/p"
xmlns:context="/schema/context"
xmlns:aop="/schema/aop"
slice into
xmlns:tx="/schema/tx"
xsi:schemaLocation="/schema/beans
/schema/beans/spring-beans-4.3.xsd
/schema/context
/schema/context/spring-context-4.3.xsd
/schema/aop
/schema/aop/spring-aop-4.3.xsd
/schema/tx
/schema/tx/spring-tx-4.3.xsd">
<!-- 加载数据库配置⽂件 -->
<context:property-placeholder location="classpath:druid.properties"/>
<!-- 配置数据库连接池 -->
<bean id="dataSource"
class="com.alibaba.druid.pool.DruidDataSource" init-method="init"
destroy-method="close">
<!-- 配置数据库连接基本信息 -->
<property name="driverClassName" value="${driver}" />
<property name="url" value="${url}" />
<property name="username" value="${name}" />
<property name="password" value="${password}" />
<!-- ******配置数据库连接池相关信息******* -->
<!-- 配置初始化⼤⼩、最⼩、最⼤ -->
<property name="initialSize" value="5" />
<property name="minIdle" value="2" />
<property name="maxActive" value="10" />
<!-- 配置获取连接等待超时的时间 -->
<property name="maxWait" value="10000" />
<!-- 配置间隔多久才进⾏⼀次检测,检测需要关闭的空闲连接,单位是毫秒 -->
<property name="timeBetweenEvictionRunsMillis" value="60000" />
<!-- 配置⼀个连接在池中最⼩⽣存的时间,单位是毫秒 -->
<property name="minEvictableIdleTimeMillis" value="300000" />
<property name="testWhileIdle" value="true" />
<!-- 这⾥建议配置为TRUE,防⽌取到的连接不可⽤ -->
<property name="testOnBorrow" value="true" />
<property name="testOnReturn" value="false" />
<!-- 打开PSCache,并且指定每个连接上PSCache的⼤⼩ -->
<property name="poolPreparedStatements" value="true" />
<property name="maxPoolPreparedStatementPerConnectionSize"
value="20" />
<!-- 这⾥配置提交⽅式,默认就是TRUE,可以不⽤配置 -->
<property name="defaultAutoCommit" value="true" />
<!-- 验证连接有效与否的SQL,不同的数据配置不同 -->
<property name="validationQuery" value="select 1" />
</bean>
<!-- sqlsessionFactory -->
<bean id="sqlSessionFactoryBean"
class="batis.spring.SqlSessionFactoryBean">
<!-- 注⼊数据源 -->
<property name="dataSource" ref="dataSource"></property>
<!-- 加载mybatis配置⽂件 -->
<property name="configLocation" value="l"></property>
<!-- 加载映射⽂件 -->
<property name="mapperLocations" value="classpath:cn/edu360/mybatis/entity/*.xml"></property> </bean>
<!-- 配置事物管理器 -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">  <!-- 注⼊数据源 -->
<property name="dataSource" ref="dataSource"></property>
</bean>
<!-- 通过aop管理事务(事务应该做⽤在service层) -->
<aop:config proxy-target-class="true">
<aop:advisor pointcut="execution (* cn.edu360.service.impl.*.*(..))"
advice-ref="departmentAdvice" />
</aop:config>
<!-- 创建⼀个事物 -->
<tx:advice id="departmentAdvice"
transaction-manager="transactionManager">
<!-- 设置事物的级别和属性 -->
<tx:attributes>
<tx:method name="insert*" isolation="READ_COMMITTED"
propagation="REQUIRED" read-only="false" timeout="-1"
rollback-for="Exception" />
<tx:method name="delete*" isolation="READ_COMMITTED"
propagation="REQUIRED" read-only="false" timeout="-1"
rollback-for="Exception" />
<tx:method name="update*" isolation="READ_COMMITTED"
propagation="REQUIRED" read-only="false" timeout="-1"
rollback-for="Exception" />
<tx:method name="select*" propagation="SUPPORTS"
read-only="false" rollback-for="Exception" />
<tx:method name="*" isolation="READ_COMMITTED"
propagation="REQUIRED" timeout="-1" rollback-for="Exception"
read-only="false" />
</tx:attributes>
</tx:advice>
<!-- 扫描Dao层连接Mybatis的mapper接⼝ -->
<bean id="mapperScannerConfigurer"
class="batis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="batis.mapper"></property>  <property name="sqlSessionFactoryBeanName"
value="sqlSessionFactoryBean"></property>
</bean>
</beans>
Mybatis配置⽂件
ajax请求的五个步骤的含义
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-////DTD Config 3.0//EN"
"/dtd/mybatis-3-config.dtd">
<configuration>
</configuration>
Spring配置⽂件

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。