Mybatis与Spring整合

Mybatis与Spring的整合 10.1 整合环境搭建 Spring和MyBatis的整合主要涉及准备所需的JAR包和编写配置文件,下面将详细介绍。 10.1.1 准备所需的JAR包 要实现MyBatis与Spring的整合,需要这两个框架相关的JAR包,除此之外,还需要其他的JAR包来配合使用。 1.所需Spring框架的JAR包 Spring框架所需要准备的JAR包共10个,其中包括4个核心模块JAR、AOP开发使用的JAR、JDBC和事务的JAR(其中核心容器依赖的commons-logging的JAR在MyBatis框架的lib包 阅读详情

Mybatis与Spring整合

既然我们已经学了Mybatis的基本开发了,接下来就是Mybatis与Spring的整合了!

以下使用的是Oracle数据库来进行测试

导入jar包

  • aopalliance.jar
  • asm-3.3.1.jar
  • aspectjweaver.jar
  • c3p0-0.9.1.2.jar
  • cglib-2.2.2.jar
  • commons-logging.jar
  • log4j-1.2.16.jar
  • mybatis-3.1.1.jar
  • mybatis-spring-1.1.1.jar
  • mysql-connector-java-5.1.7-bin.jar
  • ojdbc5.jar
  • org.springframework.aop-3.0.5.RELEASE.jar
  • org.springframework.asm-3.0.5.RELEASE.jar
  • org.springframework.beans-3.0.5.RELEASE.jar
  • org.springframework.context-3.0.5.RELEASE.jar
  • org.springframework.core-3.0.5.RELEASE.jar
  • org.springframework.expression-3.0.5.RELEASE.jar
  • org.springframework.jdbc-3.0.5.RELEASE.jar
  • org.springframework.orm-3.0.5.RELEASE.jar
  • org.springframework.transaction-3.0.5.RELEASE.jar
  • org.springframework.web.servlet-3.0.5.RELEASE.jar
  • org.springframework.web-3.0.5.RELEASE.jar

创建表


create table emps(
  eid number(5) primary key,
  ename varchar2(20),
  esal number(8,2),
  esex varchar2(2)
);

创建实体


package entity;

/**
 * 员工
 * @author AdminTC
 */
public class Emp {
    private Integer id;
    private String name;
    private Double sal;
    private String sex;
    public Emp(){}
    public Emp(Integer id, String name, Double sal, String sex) {
        this.id = id;
        this.name = name;
        this.sal = sal;
        this.sex = sex;
    }
    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public Double getSal() {
        return sal;
    }
    public void setSal(Double sal) {
        this.sal = sal;
    }
    public String getSex() {
        return sex;
    }
    public void setSex(String sex) {
        this.sex = sex;
    }
}

创建实体与表的映射文件


<?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="empNamespace">

    <resultMap type="entity.Emp" id="empMap">
        <id property="id" column="eid"/>
        <result property="name" column="ename"/>
        <result property="sal" column="esal"/>
        <result property="sex" column="esex"/>
    </resultMap>    

    <!-- 增加员工 -->
    <insert id="add" parameterType="entity.Emp">
        insert into emps(eid,ename,esal,esex) values(#{id},#{name},#{sal},#{sex})
    </insert>

</mapper>

创建Mybatis映射文件配置环境

数据库的信息交由Spring管理!Mybatis配置文件负责加载对应映射文件即可


    <mappers>
        <mapper resource="zhongfucheng/entity/EmpMapper.xml"/>

    </mappers>
</configuration>

配置Spring核心过滤器【也是加载总配置文件】


    <!-- 核心springmvc核心控制器 -->
    <servlet>
        <servlet-name>DispatcherServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:spring.xml</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>DispatcherServlet</servlet-name>
        <url-pattern>*.action</url-pattern>
    </servlet-mapping>

配置数据库信息、事务


<?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:aop="http://www.springframework.org/schema/aop"
       xmlns:context="http://www.springframework.org/schema/context"
       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/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">


    <!-- 配置C3P0连接池,目的:管理数据库连接 -->
    <bean id="comboPooledDataSourceID" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="driverClass" value="oracle.jdbc.driver.OracleDriver"/>
        <property name="jdbcUrl" value="jdbc:oracle:thin:@127.0.0.1:1521:ZHONGFUCHENG"/>
        <property name="user" value="scott"/>
        <property name="password" value="tiger"/>
    </bean>


    <!-- 配置SqlSessionFactoryBean,目的:加载mybaits配置文件和映射文件,即替代原Mybatis工具类的作用 -->
    <bean id="sqlSessionFactoryBeanID" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="configLocation" value="classpath:mybatis.xml"/>
        <property name="dataSource" ref="comboPooledDataSourceID"/>
    </bean>


    <!-- 配置Mybatis的事务管理器,即因为Mybatis底层用的是JDBC事务管事器,所以在这里依然配置JDBC事务管理器 -->
    <bean id="dataSourceTransactionManagerID" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="comboPooledDataSourceID"/>
    </bean>

    <!-- 配置事务通知,即让哪些方法需要事务支持 -->
    <tx:advice id="tx" transaction-manager="dataSourceTransactionManagerID">
        <tx:attributes>
            <tx:method name="*" propagation="REQUIRED"/>
        </tx:attributes>
    </tx:advice>

    <!-- 配置事务切面,即让哪些包下的类需要事务 -->
    <aop:config>
        <aop:pointcut id="pointcut" expression="execution(* zhongfucheng.service.*.*(..))"/>
        <aop:advisor advice-ref="tx" pointcut-ref="pointcut"/>
    </aop:config>

    <!--扫描注解-->
    <context:component-scan base-package="zhongfucheng"/>


</beans>

创建Dao、Service、Action


@Repository
public class EmpDao {
    @Autowired
    private SqlSessionFactory sqlSessionFactory;
    /**
     * 增加员工
     */
    public void add(Emp emp) throws Exception {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        sqlSession.insert("empNamespace.add", emp);
        sqlSession.close();
    }


}
@Service
public class EmpService {


    @Autowired
    private zhongfucheng.dao.EmpDao empDao;
    public void addEmp(Emp emp) throws Exception {
        empDao.add(emp);
    }
}


@Controller
@RequestMapping("/emp")
public class EmpAction {

    @Autowired
    private EmpService empService;

    @RequestMapping("/register")
    public void register(Emp emp) throws Exception {
        empService.addEmp(emp);
        System.out.println("注册成功");
    }

}

JSP页面测试


<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>员工注册</title>
  </head>
  <body>
    <form action="${pageContext.request.contextPath}/emp/register.action" method="POST">
        <table border="2" align="center">
            <tr>
                <th>编号</th>
                <td><input type="text" name="id"></td>
            </tr>
            <tr>
                <th>姓名</th>
                <td><input type="text" name="name"></td>
            </tr>
            <tr>
                <th>薪水</th>
                <td><input type="text" name="sal"></td>
            </tr>
            <tr>
                <th>性别</th>
                <td>
                    <input type="radio" name="sex" value="男"/>男
                    <input type="radio" name="sex" value="女" checked/>女
                </td>
            </tr>
            <tr>
                <td colspan="2" align="center">
                    <input type="submit" value="注册"/>
                </td>
            </tr>
        </table>
    </form>     
  </body>
</html>

总结

  • web.xml加载Spring配置文件
  • Spring配置文件配置数据连接池,SessionFactory、事务、扫描注解
  • Mybatis总配置文件、实体以及相对应的映射文件
  • 将映射文件加入到总配置文件中。

如果文章有错的地方欢迎指正,大家互相交流。习惯在微信看技术文章,想要获取更多的Java资源的同学,可以关注微信公众号:Java3y

MyBatis与Spring整合 Mybatis和spring整合后的事务管理是由Spring管理的,事务管理器依然使用jdbc的事务管理器。mapper是交给spring管理了,但是如果mapper多了需要一个个设置,也比较繁琐;2)添加spring配置文件applicationContext.xml到resources/spring资源配置目录下。注意:因为这里没有整合web内容,所以没有web.xml文件,也就不需要在其中添加spring 的监听器。 阅读详情

相关推荐

Spring 如何整合 Mybatis 的详细讲解

文章目录一、jar 包介绍1、 Mybatis 的 jar 包:2、 Mybatis 整合 Spring 的 jar 包:3、 Spring 的 jar 包:4、 数据库驱动 jar 包:二、搭建环境1、 创建项目2、 添加 jar 包3、 创建配置文件4、 添加 log4j 配置文件5、 创建映射配置文件与接口6、 创建实体类7、 创建业务层三、配置 Spring 与 Mybatis 整合1、 配置解析 properties 文件1.1、 添加 db.properties 文件1.2、 修改 Spring

康康要加油的博客 3082

Spring——Spring整合MyBatis

Spring——Spring整合MyBatis

贝尔摩德苦艾酒 2万+

Spring与MyBatis整合实践案例

MyBatis 是一款优秀的持久层框架,它支持定制化 SQL、存储过程以及高级映射。MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集。MyBatis 可以使用简单的 XML 或注解用于配置和原始映射,将接口和 Java 的 POJOs(Plain Old Java Objects,普通的 Java对象)映射成数据库中的记录。MyBatis 的工作原理可以概括为以下几个步骤:1.加载配置文件和映射器。

weixin_35749796的博客 840

Spring 整合Mybatis。

▶ Junit运行后是基于Spring环境运行的,所以Spring提供了一个专用的类运行器,这个务必要设置,这个类运行器就在Spring的测试专用包中提供的,导入的坐标就是这个东西`SpringJUnit4ClassRunner`○ SqlSessionFactoryBean是前面我们讲解FactoryBean的一个子类,在该类中将SqlSessionFactory的创建进行了封装,简化对象的创建,我们只需要将其需要的内容设置即可。在运行类中,从IOC容器中获取Service对象,调用方法获取结果。

yzh2776680982的博客 2362

使用Matlab进行IEEE 33节点潮流计算的NR法实现详解及应用实例

IEEE 33节点系统是一个标准的配电系统模型,广泛用于学术研究和工程应用。该系统由33个节点和37条线路组成,结构复杂,具有代表性。其潮流计算结果可用于验证各种潮流计算方法的准确性和效率。NR法是一种基于迭代求解的潮流计算方法,通过不断迭代求解非线性方程组,直到达到预定的收敛条件。NR法具有收敛速度快、计算精度高的优点,适用于大规模复杂电力系统的潮流计算。

m0_57781768的博客 2071

基于ARDUINIO的5路红外循迹小车

基于ARDUINIO的5路红外循迹小车 新手抄袭了很多大神的代码。这里表示感谢。 #define STOP 0 #define FORWARD 1 #define BACKWARD 2 #define STURNLEFT 3 #define STURNRIGHT 4 #define TURNLEFT 5 #define TURNRIGHT 6 #define TURNRIGHT90 7 #define TURNLEFT90 8 int leftA_PIN = A0; int

weixin_48214416的博客 4381

Spring:Spring整合Mybatis

对其中分析,看看哪些可以交给spring管理:Mybatis程序核心对象分析从图中可以获取到,真正需要交给Spring管理的是整合Mybatis,就是将Mybatis用到的内容交给Spring管理,分析下配置文件第一行读取外部properties配置文件,Spring有提供具体的解决方案,需要交给Spring第二行起别名包扫描,为SqlSessionFactory服务的,需要交给Spring第三行主要用于做连接池,Spring之前我们已经整合了Druid连接池,这块也需要交给Spring。

qq_41187116的博客 1524

OAI数据集申请下载全攻略:从个人NDA账号注册到数据包下载的保姆级避坑指南

本文提供OAI数据集申请下载的完整指南,涵盖从个人NDA账号注册到数据包下载的全流程。重点解析login.gov验证陷阱、浏览器兼容性问题、NDA权限申请技巧及nda-tools高效使用方法,帮助医学影像研究者避开常见技术障碍,快速获取全球骨关节炎研究数据库OAI的宝贵数据资源。

weixin_28698059的博客 752

Spring和Mybatis的整合

spring和mybatis的整合,回顾之前的笔记

beautifulsen的博客 6021

UQLab——其他概率分布随机变量转换标准Gaussian分布

1、使用UQLab将其他类型的随机变量转换成标准Gaussian分布; 2、使用科学计数法输出样本,方便后续ANSYS的调用分析; 3、基于MC的可靠度分析。 原随机变量分布类型: % 调用UQLab进行采样 clc clear uqlab %% Specify these distributions as a UQLab INPUT object: PriorOpts.Marginals(1...

ikhui7的博客 3013

节卡Jaka Zu APP编程避坑指南:从频繁通讯错误到稳定Socket交互的调试心得

本文详细解析了节卡Jaka Zu APP编程中常见的通讯错误问题,并提供了从基础排查到高级调试的完整解决方案。通过优化网络配置、固件匹配、心跳机制和数据交互规范,开发者可实现稳定的Socket通讯,有效提升工业机器人操控的可靠性。文章特别针对v1.6.7.3版本的典型问题给出了实用调试技巧。

weixin_42639633的博客 325

【Spring】Spring 整合 MyBatis

在实际项目开发中,将 Spring 和 MyBatis 进行整合可以提高开发效率、简化配置、增强事务管理和可维护性,同时利用 Spring 的强大功能来提升系统的稳定性。这里从独立使用 MyBatis 开始,逐步实现与 Spring 框架的整合。

zzy_NIC的博客 1445

《QGIS快速入门与应用基础》009:国内镜像源(清华大学/阿里云)下载技巧

针对国内用户下载QGIS速度慢、易中断的问题,推荐使用清华大学和阿里云两大国内镜像源,提供3-10MB/s的极速下载方案。详细解析镜像源核心优势、分步骤下载指南及校验方法,对比清华(同步快、北方优选)与阿里云(南方节点多)的特点。针对常见问题如版本延迟、404错误等提供解决方案,并介绍搭配IDM等工具实现多线程加速的进阶技巧。通过镜像源+下载工具组合,用户可高效获取QGIS安装包,为后续系统安装奠定基础。

LuckyHanMo的博客 1738

Spring与mybatis整合

spring与mybatis整合spring与mybatis整合mybatis是一个持久层框架,实现了对数据库操作的封装。可以单独使用mybatis,使用mybatis主要包括以下几个部分:1、编写各个映射文件xxMapper.xml,以及对应的各个接口文件xxMapper.java。

cxbtdd的博客 1480

2023年12月机器人技术等级考试试卷(三级理论) 试题解析

2023年12月机器人技术等级考试试卷(三级理论) 试题解析

http://www.cierobot.com 4095

HTML流光爱心(完整代码)

HTML语言实现红蓝色流光爱心效果的完整代码。

AIGC 1万+

Mybatis整合Spring详解

mybatis最常见的用法是整合进spring项目中,组成ssm项目(spring+springMVC+mybatis),而springboot也是java生态中使用量最大的框架,本文介绍mybatis如何与spring和springboot进行整合。

qq_43408971的博客 1137

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

Spring整合Mybatis

需维护独立的mybatis-config.xml文件:数据源、事务、映射配置分散在不同文件:修改配置需要重启应用。

2302_77465225的博客 1917

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

Spring整合MyBatis——超详细

(2)将MyBatis的SqlSessionFactory交给Spring IoC容器创建并管理,使用spring-mybatis整合jar包中提供的SqlSessionFactoryBean类代替项目中的MyBatisUtil工具类。映射文件中的select 的id为findUserList,因此接口文件中的方法名就为findUserList,出现红线也不用着急,运行的时候不影响。把上方的mapper接口文件都自动注入到IoC容器中,实现类Bean的名称默认为接口类名的首字母小写。选择自动导入jar包。

web15085415935的博客 1708

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

Spring与Mybatis整合

一、 MyBatis与Spring的集成 在学习mybatis配置时,对于mybatis-config配置的时候我们发现,大致是需要配置三个方面:setting、datasource、mappers 而mybatis的setting往往使用默认配置,所以我们经常配置datasource数据源与mappers映射,但学习spring之后发现,对于datasource的配置交由spring进行管理,所以在spring与mybatis整合后mybatis的配置文件中将不需要配置datasource,mybatis

Amour恋空的博客 1431

Spring之整合Mybatis底层源码

有很多框架需要与Spring进行整合,而整合的核心思路就是把其他框架所产生的对象放到Spring容器中,让其成为一个bean。

qq_43456605的博客 1415

Spring整合MyBatis详解

企业级开发中,Spring(负责依赖管理和事务控制)与MyBatis(负责持久层操作)的整合是主流方案,本文我将详细讲解Spring整合MyBatis的完整流程,这种整合能充分发挥两者优势:Spring的IoC容器管理MyBatis的核心组件,AOP实现事务控制;MyBatis简化数据库操作。

aa_hdkf_vg的博客 1575

Mybatis的spring整合

mybatis和spring的整合

AYGZC233的博客 1554

spring整合mybatis原理

我们先来实现MyBatis和Spring的整合操作。

m0_73671382的博客 1331

Spring 整合 Mybatis

Spring整合Mybatis 详细配置及源码分析

2301_78163113的博客 269

Spring+Mybatis的整合

所以,该整合,只需要将 SqlSessionFactory 的对象生成器 SqlSessionFactoryBean 注册在 Spring 容器中,再将其注入给 Dao 的实现类即可完成整合。实现 Spring 与 MyBatis 的整合常用的方式:扫描的 Mapper 动态代理 Spring 像插线板一样,mybatis 框架是插头,可以容易的组合到一起。使用mybatis,需要创建mybatis框架中的某些对象,使用这些对象,就可以使用mybatis提供的功能了。在基础的 MyBatis 中,通过。

weixin_65824274的博客 2108
上一篇: SSM【史上最详细整合】
下一篇: Spring入门看这一篇就够了
Java3y
Java3y 领域专家: 后端开发技术领域 领域专家: 后端开发技术领域
博客等级 码龄9年 1万+粉丝 509原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值