- 浏览: 3422541 次
- 性别:
- 来自: 珠海
文章分类
- 全部博客 (1633)
- Java (250)
- Android&HTML5 (111)
- Struts (10)
- Spring (236)
- Hibernate&MyBatis (115)
- SSH (49)
- jQuery插件收集 (55)
- Javascript (145)
- PHP (77)
- REST&WebService (18)
- BIRT (27)
- .NET (7)
- Database (105)
- 设计模式 (16)
- 自动化和测试 (19)
- Maven&Ant (43)
- 工作流 (36)
- 开源应用 (156)
- 其他 (16)
- 前台&美工 (119)
- 工作积累 (0)
- OS&Docker (83)
- Python&爬虫 (28)
- 工具软件 (157)
- 问题收集 (61)
- OFbiz (6)
- noSQL (12)
最新评论
-
HEZR曾嶸:
你好博主,这个不是很理解,能解释一下嘛//左边+1,上边+1, ...
java 两字符串相似度计算算法 -
天使建站:
写得不错,可以看这里,和这里的这篇文章一起看,有 ...
jquery 遍历对象、数组、集合 -
xue88ming:
很有用,谢谢
@PathVariable映射出现错误: Name for argument type -
jnjeC:
厉害,困扰了我很久
MyBatis排序时使用order by 动态参数时需要注意,用$而不是# -
TopLongMan:
非常好,很实用啊。。
PostgreSQL递归查询实现树状结构查询
spring与mybatis三种整合方法 http://panyongzheng.iteye.com/blog/2102910
Mybatis整合Spring
http://haohaoxuexi.iteye.com/blog/1843309
选择: 简单的应用选择Mapper映射方式, 复杂的框架, 可以使用spring与mybatis三种整合方法的后两种.
MyBatis3 的Mapper XML 文件详解http://mybatis.org/mybatis-3/zh/sqlmap-xml.html
注意: 以上描述的三种分方式之外, 还有一种就是使用Mapper.xml和Mapper.java两个文件对应的方式, 其中Mapper.java类就相当于了原生的DAO接口和实现类, 如果还需要做额外的处理, 就增加实际的DAO, 然后调用Mapper.java文件. 本文是后者.
参考:
mybatis学习笔记 http://legend2011.blog.51cto.com/3018495/888848
mybatis初步----查询之resultMap和resultType http://my.oschina.net/mutianya/blog/168268
mybatis自增主键配置 http://leeyee.github.io/blog/2013/08/22/mybatis-auto-increment-primary-key/
Spring声明式事务管理示例——MyBatis http://legend2011.blog.51cto.com/3018495/1239139
数据库逆向框架代码生成工具:MyBatis Generator的使用 http://my.oschina.net/lujianing/blog/200135
web.xml
servlet.xml
jdbc.properties
jdbc.dataSource=com.alibaba.druid.pool.DruidDataSource
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/smartsangbag?useUnicode=true&characterEncoding=utf8
jdbc.username=xxxxxxx
jdbc.password=******
applicationContext.xml
applicationContext-spring.xml
定义mybatis的映射文件 src/main/resources/com/pandy/mapper/SentEmailQueueMapper.xml
映射文件对应的接口
映射文件对应的model
DAO:
Service
Controller
访问:
正常事务:http://localhost:8080/SpringMybatis/myController/test.do?isRollback=false
回滚事务:http://localhost:8080/SpringMybatis/myController/test.do?isRollback=true
附加pom.xml
Mybatis整合Spring
http://haohaoxuexi.iteye.com/blog/1843309
选择: 简单的应用选择Mapper映射方式, 复杂的框架, 可以使用spring与mybatis三种整合方法的后两种.
MyBatis3 的Mapper XML 文件详解http://mybatis.org/mybatis-3/zh/sqlmap-xml.html
注意: 以上描述的三种分方式之外, 还有一种就是使用Mapper.xml和Mapper.java两个文件对应的方式, 其中Mapper.java类就相当于了原生的DAO接口和实现类, 如果还需要做额外的处理, 就增加实际的DAO, 然后调用Mapper.java文件. 本文是后者.
参考:
mybatis学习笔记 http://legend2011.blog.51cto.com/3018495/888848
mybatis初步----查询之resultMap和resultType http://my.oschina.net/mutianya/blog/168268
mybatis自增主键配置 http://leeyee.github.io/blog/2013/08/22/mybatis-auto-increment-primary-key/
Spring声明式事务管理示例——MyBatis http://legend2011.blog.51cto.com/3018495/1239139
数据库逆向框架代码生成工具:MyBatis Generator的使用 http://my.oschina.net/lujianing/blog/200135
web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> <display-name>Archetype Created Web Application</display-name> <listener> <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class> </listener> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:applicationContext*.xml</param-value> </context-param> <servlet> <servlet-name>springmvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>springmvc</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> </web-app>
servlet.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" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <context:component-scan base-package="com"> <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service"/> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Repository"/> </context:component-scan> <mvc:annotation-driven/> <mvc:resources location="/resources/" mapping="/resources/**"/> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="requestContextAttribute" value="rc"/> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> <property name="prefix" value="/"/> <property name="suffix" value=".jsp"/> </bean> </beans>
jdbc.properties
jdbc.dataSource=com.alibaba.druid.pool.DruidDataSource
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/smartsangbag?useUnicode=true&characterEncoding=utf8
jdbc.username=xxxxxxx
jdbc.password=******
applicationContext.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" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> <context:component-scan base-package="com.pandy"/> <context:property-placeholder location="classpath:/jdbc.properties"/> <bean id="dataSource" class="${jdbc.dataSource}"> <property name="driverClassName" value="${jdbc.driver}"/> <property name="url" value="${jdbc.url}"/> <property name="username" value="${jdbc.username}"/> <property name="password" value="${jdbc.password}"/> <!-- <property name="alias" value="${proxool.alias}" /> <property name="houseKeepingTestSql" value="${proxool.houseKeepingTestSql}" /> <property name="prototypeCount" value="${proxool.prototypeCount}" /> <property name="minimumConnectionCount" value="${proxool.minimumConnectionCount}" /> <property name="maximumActiveTime" value="3600000" /> --> </bean> </beans>
applicationContext-spring.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" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:util="http://www.springframework.org/schema/util" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="mapperLocations" value="classpath:com/pandy/mapper/*.xml"/> <property name="typeAliasesPackage" value="com.pandy.model" /> </bean> <!-- 定义dao底层类 --> <bean id="sentEmailQueueMapper" class="org.mybatis.spring.mapper.MapperFactoryBean"> <property name="mapperInterface" value="com.pandy.dao.mapper.SentEmailQueueMapper" /> <property name="sqlSessionFactory" ref="sqlSessionFactory" /> </bean> <!-- 定义事务 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"/> </bean> <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/> </beans>
定义mybatis的映射文件 src/main/resources/com/pandy/mapper/SentEmailQueueMapper.xml
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.pandy.dao.mapper.SentEmailQueueMapper"> <resultMap type="com.pandy.model.SentEmailQueue" id="sentEmailQueueMap"> <id column="data_id" property="dataId"/> <result column="from_email" property="fromEmail"/> <result column="to_email" property="toEmail"/> <result column="to_user_id" property="toUserId"/> <result column="send_date_time" property="sendDateTime"/> <result column="invalid_date_time" property="invalidDateTime"/> <result column="email_type" property="emailType"/> <result column="email_data_id" property="emailDataId"/> <result column="subject" property="subject"/> <result column="template_name" property="templateName"/> <result column="content_params" property="contentParams"/> <result column="sent_status" property="sentStatus"/> <result column="actual_sent_date_time" property="actualSentDateTime"/> <result column="CREATED_TIME" property="createdTime"/> <result column="MODIFIED_TIME" property="modifiedTime"/> <result column="LAST_UPDATED_STAMP" property="lastUpdatedStamp"/> <result column="LAST_UPDATED_TX_STAMP" property="lastUpdatedTxStamp"/> <result column="CREATED_STAMP" property="createdStamp"/> <result column="CREATED_TX_STAMP" property="createdTxStamp"/> </resultMap> <!-- 一种映射方式,注意as后面的名字要跟model的属性名字一样 --> <select id="get" parameterType="int" resultType="com.pandy.model.SentEmailQueue"> SELECT data_id as dataId, from_email as fromEmail, to_email as toEmail, to_user_id as toUserId, send_date_time as sendDateTime, invalid_date_time as invalidDateTime, email_type as emailType, email_data_id as emailDataId, subject as subject, template_name as templateName, content_params as contentParams, sent_status as sentStatus, actual_sent_date_time as actualSentDateTime, CREATED_TIME as createdTime, MODIFIED_TIME as modifiedTime, LAST_UPDATED_STAMP as lastUpdatedStamp, LAST_UPDATED_TX_STAMP as lastUpdatedTxStamp, CREATED_STAMP as createdStamp, CREATED_TX_STAMP as createdTxStamp FROM send_email_queue1 where data_id = #{data_id} </select> <!-- 另一种映射方式,直接映射到model的类 --> <select id="getAll" resultMap="sentEmailQueueMap"> SELECT data_id, from_email, to_email, to_user_id, send_date_time, invalid_date_time, email_type, email_data_id, subject, template_name, content_params, sent_status, actual_sent_date_time, CREATED_TIME, MODIFIED_TIME, LAST_UPDATED_STAMP, LAST_UPDATED_TX_STAMP, CREATED_STAMP, CREATED_TX_STAMP FROM send_email_queue1 </select> <insert id="insert" parameterType="com.pandy.model.SentEmailQueue" useGeneratedKeys="true" keyProperty="dataId"> INSERT INTO send_email_queue1 (from_email, to_email) VALUES (#{toEmail}, #{toEmail}) </insert> <update id="update" parameterType="com.pandy.model.SentEmailQueue"> UPDATE send_email_queue1 SET from_email = #{toEmail}, to_email = #{toEmail} WHERE data_id = #{dataId} </update> <delete id="delete" parameterType="int"> delete from send_email_queue1 where data_id = #{dataId} </delete> </mapper>
映射文件对应的接口
package com.pandy.dao.mapper; import com.pandy.model.SentEmailQueue; import java.util.List; /** * 只定义跟xml文件的sql对应就好,不用实现这个接口,这个接口mybatis自己实现。 */ public interface SentEmailQueueMapper { public SentEmailQueue get(Integer id); public List<SentEmailQueue> getAll(); public void insert(SentEmailQueue queue); public void update(SentEmailQueue queue); public void delete(Integer dataId); }
映射文件对应的model
package com.pandy.model; import java.util.Date; public class SentEmailQueue { private Integer dataId; private String fromEmail; private String toEmail; private String toUserId; private Date sendDateTime; private Date invalidDateTime; private String emailType; private String emailDataId; private String subject; private String templateName; private String contentParams; private String sentStatus; private String actualSentDateTime; private Date createdTime; private Date modifiedTime; private Date lastUpdatedStamp; private Date lastUpdatedTxStamp; private Date createdStamp; private Date createdTxStamp; ...... @Override public String toString() { return "SentEmailQueue{" + "dataId='" + dataId + '\'' + ", fromEmail='" + fromEmail + '\'' + ", toEmail='" + toEmail + '\'' + ", toUserId='" + toUserId + '\'' + ", sendDateTime=" + sendDateTime + ", invalidDateTime=" + invalidDateTime + ", emailType='" + emailType + '\'' + ", emailDataId='" + emailDataId + '\'' + ", subject='" + subject + '\'' + ", templateName='" + templateName + '\'' + ", contentParams='" + contentParams + '\'' + ", sentStatus='" + sentStatus + '\'' + ", actualSentDateTime='" + actualSentDateTime + '\'' + ", createdTime=" + createdTime + ", modifiedTime=" + modifiedTime + ", lastUpdatedStamp=" + lastUpdatedStamp + ", lastUpdatedTxStamp=" + lastUpdatedTxStamp + ", createdStamp=" + createdStamp + ", createdTxStamp=" + createdTxStamp + '}'; } }
DAO:
package com.pandy.dao; import com.pandy.model.SentEmailQueue; import java.util.List; /** * Created by pandy on 14-8-13. */ public interface SentEmailQueueDao { public SentEmailQueue get(Integer dataId); public List<SentEmailQueue> getAll(); public void insert(SentEmailQueue queue); public void update(SentEmailQueue queue); public void delete(Integer dataId); }
package com.pandy.dao.impl; import com.pandy.dao.SentEmailQueueDao; import com.pandy.dao.mapper.SentEmailQueueMapper; import com.pandy.model.SentEmailQueue; import org.springframework.stereotype.Repository; import javax.annotation.Resource; import java.util.List; /** * Created by pandy on 14-8-13. */ @Repository("sentEmailQueueDao") public class SentEmailQueueDaoImpl implements SentEmailQueueDao { @Resource private SentEmailQueueMapper sentEmailQueueMapper; @Override public SentEmailQueue get(Integer dataId) { return sentEmailQueueMapper.get(dataId); } @Override public List<SentEmailQueue> getAll() { return sentEmailQueueMapper.getAll(); } @Override public void insert(SentEmailQueue queue) { sentEmailQueueMapper.insert(queue); } @Override public void update(SentEmailQueue queue) { sentEmailQueueMapper.update(queue); } @Override public void delete(Integer dataId) { sentEmailQueueMapper.delete(dataId); } }
Service
package com.pandy.service; /** * Created by pandy on 14-8-13. */ public interface SentEmailQueueService { public void test(boolean isRollback); }
package com.pandy.service.impl; import com.pandy.dao.SentEmailQueueDao; import com.pandy.model.SentEmailQueue; import com.pandy.service.SentEmailQueueService; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; @Service("sentEmailQueueService") @Transactional public class SentEmailQueueServiceImpl implements SentEmailQueueService { @Resource(name = "sentEmailQueueDao") private SentEmailQueueDao sentEmailQueueDao; @Override @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = RuntimeException.class) public void test(boolean isRollback) { Date date = new Date(); SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd_HHmmss"); SentEmailQueue queue = new SentEmailQueue(); queue.setToEmail(format.format(date) + "@pandy8.com"); sentEmailQueueDao.insert(queue); List<SentEmailQueue> list = sentEmailQueueDao.getAll(); int update_id = 0; for (SentEmailQueue row : list) { queue = sentEmailQueueDao.get(row.getDataId()); System.out.println(queue.toString()); update_id = row.getDataId(); } date = new Date(); format = new SimpleDateFormat("yyyyMMdd_HHmmss"); queue = new SentEmailQueue(); queue.setDataId(update_id); queue.setToEmail("update_" + format.format(date) + "@pandy8.com"); sentEmailQueueDao.update(queue); System.out.println("将被删除的id=" + (update_id - 1)); sentEmailQueueDao.delete(update_id - 1); if(isRollback) { throw new RuntimeException("事务测试: 故意抛出异常,使得对数据库的操作失败"); } } }
Controller
package com.pandy.controller; import com.pandy.service.SentEmailQueueService; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.servlet.ModelAndView; import javax.annotation.Resource; /** * Created by pandy on 14-8-13. */ @Controller @RequestMapping("/myController") public class MyController { @Resource(name="sentEmailQueueService") private SentEmailQueueService sentEmailQueueService; @RequestMapping("/test") public ModelAndView test(@RequestParam("isRollback") boolean isRollback){ System.out.println("==================>isRollback="+isRollback); sentEmailQueueService.test(isRollback); return new ModelAndView("index"); } }
访问:
正常事务:http://localhost:8080/SpringMybatis/myController/test.do?isRollback=false
回滚事务:http://localhost:8080/SpringMybatis/myController/test.do?isRollback=true
附加pom.xml
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.pandy</groupId> <artifactId>spmybatis</artifactId> <version>1.0-SNAPSHOT</version> <packaging>war</packaging> <properties> <buildNumber>1</buildNumber> <java.version>1.7</java.version> <mybatis.version>3.2.7</mybatis.version> <mybatis.spring.version>1.2.2</mybatis.spring.version> <mysql.version>5.1.30</mysql.version> <spring.version>4.0.5.RELEASE</spring.version> <spring.security.version>3.2.4.RELEASE</spring.security.version> <spring.asm.version>3.1.4.RELEASE</spring.asm.version> <aspectj.version>1.6.2</aspectj.version> <mysql.version>5.1.30</mysql.version> <jdbc.groupId>com.alibaba</jdbc.groupId> <jdbc.artifactId>druid</jdbc.artifactId> <jdbc.version>1.0.4</jdbc.version> </properties> <dependencies> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>${mybatis.version}</version> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> <version>${mybatis.spring.version}</version> </dependency> <!-- Spring 3 --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-asm</artifactId> <version>${spring.asm.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aspects</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-expression</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-orm</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>${spring.version}</version> </dependency> <!-- Log4j --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.6.1</version> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.16</version> <exclusions> <exclusion> <artifactId>log4j</artifactId> <groupId>log4j</groupId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.6.1</version> </dependency> <dependency> <groupId>org.lazyluke</groupId> <artifactId>log4jdbc-remix</artifactId> <version>0.2.7</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.5</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jsp-api</artifactId> <version>2.0</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.2</version> <scope>runtime</scope> </dependency> <dependency> <groupId>taglibs</groupId> <artifactId>standard</artifactId> <version>1.1.2</version> </dependency> <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>15.0</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>${mysql.version}</version> </dependency> <dependency> <groupId>sqljdbc</groupId> <artifactId>sqljdbc</artifactId> <version>4.0</version> </dependency> <dependency> <groupId>${jdbc.groupId}</groupId> <artifactId>${jdbc.artifactId}</artifactId> <version>${jdbc.version}</version> </dependency> </dependencies> <build> <finalName>SpringMybatis</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.5</version> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.1.1</version> <configuration> <archive> <manifest> <!--<addClasspath>true</addClasspath> --> </manifest> <manifestEntries> <Built-By>org-builder</Built-By> <Build-Jdk>${java.version}</Build-Jdk> </manifestEntries> </archive> </configuration> </plugin> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.2</version> <configuration> <url>http://localhost:8080/manager/text</url> <username>admin</username> <password>admin</password> <path>/SpringMybatis</path> </configuration> </plugin> <plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>maven-jetty-plugin</artifactId> <version>6.1.20</version> <configuration> <contextPath>/SpringMybatis</contextPath> <!--<webDefaultXml>webdefault.xml</webDefaultXml> --> <scanIntervalSeconds>0</scanIntervalSeconds> <scanTargetPatterns> <scanTargetPattern> <directory>src/main/webapp/WEB-INF</directory> <excludes> <exclude>**/*.jsp</exclude> </excludes> <includes> <include>**/*.properties</include> <include>**/*.xml</include> </includes> </scanTargetPattern> </scanTargetPatterns> </configuration> </plugin> <plugin> <artifactId>maven-war-plugin</artifactId> <version>2.0.2</version> <configuration> <archive> <manifest> <addDefaultImplementationEntries>true</addDefaultImplementationEntries> </manifest> <manifestEntries> <Implementation-Build>${buildNumber}</Implementation-Build> </manifestEntries> </archive> <dependentWarExcludes> **/jdbc.properties,**/web.xml,WEB-INF/classes/META-INF/** </dependentWarExcludes> </configuration> </plugin> </plugins> </build> </project>
- SpringMybatis.zip (60.4 KB)
- 下载次数: 33
发表评论
-
Spring Boot 属性配置
2016-06-24 11:04 1181Spring Boot 属性配置和使用 http://blog ... -
Spring Boot 集成MyBatis
2016-06-24 10:55 2025Spring Boot 集成MyBatis http://bl ... -
Spring MVC防重复提交
2016-06-17 15:47 1645http://my.oschina.net/zyqjustin ... -
Spring容器加载完之后执行特定任务
2016-06-17 15:36 2284http://my.oschina.net/simpleton ... -
使用spring-session和shiro来代理session的配置
2016-06-16 11:21 12057使用spring-session和redis来代理sessio ... -
JSTL 的 if else : 有 c:if 没有 else 的处理
2016-06-14 09:52 1335http://blog.csdn.net/xiyuan1999 ... -
spring mvc 请求转发和重定向
2016-06-14 09:48 1397http://blog.csdn.net/jackpk/art ... -
mvc:view-controller
2016-05-18 10:26 1083http://blog.csdn.net/lzwglory/a ... -
spring配置事物的方式:注解和aop配置
2016-05-14 00:26 4102参考: Spring AOP中pointcut express ... -
分布式任务调度组件 Uncode-Schedule
2016-05-13 14:47 2287http://www.oschina.net/p/uncode ... -
写个mybatis的拦截插件,实现将所有执行的sql写入文件里
2016-05-12 15:59 5104原文 http://3131854.blog.51cto.co ... -
Mybatis分库分表扩展插件
2016-05-12 15:47 1620http://fangjialong.iteye.com/bl ... -
spring+mybatis+atomikos 实现JTA事务
2016-05-11 22:00 5522sping配置多个数据源 不同用户操作不同数据库 http:/ ... -
Spring中使用注解 @Scheduled执行定时任务
2016-05-10 09:39 1566原文:http://dwf07223.blog.51cto.c ... -
Spring中配置Websocket
2016-05-05 16:55 1276spring+websocket整合(springMVC+sp ... -
redis 集群中Session解决方案之Spring Session
2016-05-04 08:54 1315集群中Session解决方案之Spring Session h ... -
使用Spring-data进行Redis操作
2016-05-04 08:54 4791使用Spring-data进行Redis操作 http://z ... -
Spring4新特性——集成Bean Validation 1.1(JSR-349)到SpringMVC
2016-05-03 13:35 1060Spring4新特性——集成Bean Validation 1 ... -
SpringMVC介绍之Validation
2016-05-03 13:10 983SpringMVC介绍之Validation http://h ... -
spring 注解方式下使用commons-validator 验证表单
2016-05-03 11:08 3076原文: http://www.programgo.com/ar ...
相关推荐
Spring、SpringMVC和Mybatis是Java开发中最常用的三大开源框架,它们的整合使用,通常被称为SSM框架。这个框架组合提供了完整的后端服务解决方案,包括依赖注入(DI)、面向切面编程(AOP)、模型-视图-控制器(MVC...
**整合SpringMVC和MyBatis** 1. **配置**:在Spring的配置文件中,需要配置DataSource、SqlSessionFactoryBean以及MapperScannerConfigurer,后者用于扫描标记为@Mapper的接口。 2. **Mapper接口和XML映射文件**:...
"Spring+SpringMVC+Mybatis框架项目整合"是一个典型的后端技术栈,旨在提供高效、灵活且可维护的解决方案。下面将详细介绍这三个框架及其整合过程中的关键知识点。 **Spring框架**: Spring是一个开源的Java平台,...
这个"springMVC+mybatis+shiro+redis 项目整合demo"就是一个实例,展示了如何将这些技术集成到一个项目中,以实现高效的数据处理、用户认证授权和缓存管理。 首先,`SpringMVC` 是 Spring 框架的一部分,它是一个...
Mybatis是一个优秀的持久层框架,它简化了数据库操作,通过XML或注解的方式配置和映射SQL,使得开发者能够更加专注于SQL本身,而无需过多关注JDBC的繁琐细节。Mybatis支持动态SQL,可以更灵活地编写查询语句。 在...
《Spring+SpringMVC+Mybatis 整合实践详解》 在Java Web开发领域,Spring、SpringMVC和Mybatis的整合(简称SSM)是常见的应用架构模式,它为开发者提供了灵活、高效的开发环境。这个名为"spring+springMVC+Mybatis ...
《图书管理系统SpringMvc+Mybatis实现详解》 在IT领域,构建高效、稳定的软件系统是至关重要的。本项目“图书管理系统”就是这样一个实例,它利用了SpringMvc和Mybatis两大主流框架,为图书管理提供了全面的解决...
这种整合方式在现代企业级应用中非常常见,它将Spring的全面性、SpringMVC的Web处理能力和MyBatis的数据库操作灵活性完美结合,极大地提高了开发效率和代码质量。在学习和使用过程中,理解每个框架的核心概念以及...
开发者可以从中学习到如何配置SpringMVC和Mybatis的整合,如在Spring的配置文件中定义数据源、SqlSessionFactoryBean以及Mybatis的Mapper接口和XML映射文件。此外,还可能涉及到SpringMVC的拦截器、视图解析器、异常...
标题 "Spring+SpringMVC+Mybatis资源课件" 提供了一个学习路径,涉及Java开发中的三个关键组件:Spring框架、SpringMVC和Mybatis。这些技术是构建现代企业级Web应用程序的基础,尤其是在Java世界中。 Spring框架是...
在SpringMVC+MyBatis的整合中,我们需要配置MyBatis-Spring的SqlSessionFactoryBean,并将数据源和Mapper接口的扫描路径加入配置。这样,Spring可以管理SqlSession,使得MyBatis的操作可以通过@Autowired注解注入到...
在MyBatis中,可以配置数据源、事务管理器以及Mapper接口,以便与SpringMVC进行交互。对于Redis,可以设置连接池,定义键值策略,并在需要缓存数据的地方调用RedisTemplate的方法。 例如,在处理用户登录请求时,...
《SpringMVC与MyBatis整合详解》 在现代企业级Web开发中,SpringMVC和MyBatis是两个非常重要的技术组件。SpringMVC作为Spring框架的一部分...通过掌握这种整合方式,开发者可以更便捷地构建和管理复杂的Web应用程序。
SSM框架整合是Java开发中常见的技术栈,包括Spring、SpringMVC和Mybatis三个核心组件。这个压缩包提供了一个已经验证过的整合示例,帮助开发者理解和实践这三大框架的协同工作。 首先,Spring框架是Java企业级应用...
整合Spring、SpringMVC和MyBatis是常见的Java Web开发模式,这种整合可以充分利用每个框架的优点,实现松耦合和高效的数据访问。以下是整合过程中的关键步骤: 1. **配置Spring**:首先,需要创建一个Spring的配置...
下面将详细讲解这四个组件及其整合方式。 1. **Spring Framework**: Spring 是一个开源的应用框架,主要用于简化企业级Java应用的开发。它提供了一个全面的编程和配置模型,使得开发人员可以更专注于业务逻辑,而...
开发者需要熟悉MyBatis的XML或注解方式的SQL映射文件,以及如何在服务层调用这些映射的SQL语句。 3. **EasyUI**:EasyUI是一个基于jQuery的UI库,提供了丰富的组件和主题,使得开发者可以快速构建美观的用户界面。...
通过学习和分析这个demo,开发者可以深入理解Spring、SpringMVC和MyBatis的整合方式,以及如何利用Mybatis-Paginator实现高效便捷的分页功能。这对于提升Java Web开发技能和理解企业级应用架构具有重要意义。