Mybatis框架

MyBatis框架 MyBatis是一款优秀的持久层(数据访问层)框架.MyBatis避免了JDBC代码手动设置参数以及手动获取结果集的操作,自动将ResultSet结果映射到对应的数据库表对象MyBatis可以使用XML或注解,将数据库中的记录映射成java对象就是将我们查询到的结果封装到我们与数据库表的对应对象的操作例如:在数据库中我们有一个学生表,我们用sql语句查询到一个学生,学生信息都保存在了ResultSet对象中,我们要将信息提取到我们对应的学生类中。 阅读详情

Mybatis 是spring框架中用于提交数据的一个持久层框架。

它支持动态SQL、存储过程,以及高级映射(一对一,一对多)。降低SQL与程序代码的耦合。

导入Mybatis jar包

   <!--mybatis依赖包-->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.2.0</version>
        </dependency>

        <!--jdbc依赖包-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <!--小辣椒包-->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>

进行配置Mybatis的 yml 文件 配置端口号等

#配置端口号
server:
  port: 8091

#管理数据源
spring:
  datasource:
    #高版本驱动使用
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://127.0.0.1:3306/jt?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&autoReconnect=true&allowMultiQueries=true
    #设定用户名和密码
    username: root
    password: root

#SpringBoot整合Mybatis
mybatis:
  #指定别名包
  type-aliases-package: com.jt.pojo
  #扫描指定路径下的映射文件
  mapper-locations: classpath:/mappers/*.xml
  #开启驼峰映射
  configuration:
    map-underscore-to-camel-case: true
  # 一二级缓存默认开始 所以可以简化

#打印mysql日志
logging:
  level:
    com.jt.mapper: debug

设置接口实现类Mapper的xml映射文件  

在映射文件中进行动态取值

1.如果是单个参数使用#{}  获取的参数的值

2.如果是对象的参数则使用#{属性}  获取的是属性值

3.如果是使用Map集合时,则使用#{key} 通过key匹配到value的值

resultTupe:自动进行了封装  resultType只能指出字段名称与属性名称一致时才能自动映射

在其中进行封装  执行SQL语句

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

<!--namespace是mybatis映射文件的唯一标识,与接口对应-->
<mapper namespace="com.jt.mapper.EmpMapper"> <!--确认要进行执行的接口-->
    <!--id 表示接口方法 与接口方法一一对应
        resultType 返回值结果类型

        要与接口的方法名 以及返回pojo文件的路径名一致将pojo文件的属性与sql属性想匹配
        根据路径找到标签进行执行sql语句
    -->
</mapper>

创建pojo类 ,类型名称要与表的名称一致

 定义完以上的方法定义UserMapper接口。

使用注解将接口提交给spring容器

使用Mybatis进行增删改查

在测试类中需要进行依赖注入,调用接口 使用接口中的方法进行操作

 在映射文件中进行执行SQL语句,确认上面的路径是否正确,确认后进行操作

在pojo中的属性名称,映射到xml文件时想要两方对应必须使用 #{} 进行操作。

测试简单的查询where判断

 测试便利查询数组中的对应id数据

因为定义的是数组,所以要使用标签<foreach>进行定义

collection 表示数组的类型    item 定义要遍历的变量     separator 表示用什么分隔数组

测试更改数据

需要使用标签<update>  且set也必须使用标签 是为了去除if中多余的逗号。

 测试添加数据

使用<insert>标签

<?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.jt.dao.ZJInfoDao">
    <!-- 可根据自己的需求,是否要使用 -->
    <resultMap type="com.jt.dao.SjkInfoDao" id="sjkInfoMap">
        <result property="id" column="id"/>
        <result property="gdResourceId" column="gd_resource_id"/>
        
    </resultMap>
<!--    查询-->
    <select id="getZJInfoByResource" resultType="java.util.Map">
        select * from ds_form_gd_resource_info where GD_ID = #{resourceId}
    </select>
<!--添加-->
<insert id="insert">
    insert into ds_form_gd_resource_info_all value (5 ,null ,null ,null ,null ,null ,null ,null ,null ,null ,null ,null ,null ,null ,null ,null ,null ,null ,null ,null ,null ,null ,null ,null ,null ,null ,null ,null ,null ,null ,null ,null ,null ,null,#{sjk},#{bf},#{zjj},#{zcp},#{sjp} )
</insert>

</mapper>

 删除同理就不多写了。

测试分支结构

与if else同理

在增删改查中经常会对多个表进行查询,也就是多表联查

一般都为:一对一  或者 多对一

单表操作使用  resultType

多表关联操作使用   resultMap   就是一个封装的方式

进行一对一需要在pojo类中进行定义需要关联的pojo类

一对一

 在映射文件中进行编译

id是名字 与上面相对应 代表调用

type 是你要进行查询的类

autoMapping 代表进行关联

 多对一

多对一中  关联的标签为

collection

对象的类为 

ofType

 Mybatis缓存

 就是将数据进行缓存 再从缓存中进行查询

一级缓存

默认开启,同一个SqlSesion级别共享的缓存,在一个SqlSession的生命周期内,执行2次相同的SQL查询,则第二次SQL查询会直接取缓存的数据,而不走数据库,当然,若第一次和第二次相同的SQL查询之间,执行了DML(INSERT/UPDATE/DELETE),则一级缓存会被清空,第二次查询相同SQL仍然会走数据库

一级缓存在下面情况会被清除

在同一个SqlSession下执行增删改操作时(不必提交),会清除一级缓存
SqlSession提交或关闭时(关闭时会自动提交),会清除一级缓存
对mapper.xml中的某个CRUD标签,设置属性flushCache=true,这样会导致该MappedStatement的一级缓存,二级缓存都失效(一个CRUD标签在mybatis中会被封装成一个MappedStatement)
在全局配置文件中设置 <setting name="localCacheScope" value="STATEMENT"/>,这样会使一级缓存失效,二级缓存不受影响


二级缓存

默认开启(官网进行的声明),通过多线程操作同一个业务让同一个SqlSessionFactory创建多个
SqlSession操作数据库。第二次相同业务SqlSessionFactory创建的SqlSession  就会使用上一次创建的SqlSession存放于缓存区的数据

springBoot是默认不使用一级缓存的  需要添加注释 @Transactional 事物注解 就可以开启一级缓存,使用同一个SqlSession

二级缓存有两种方式:不能同时存在

第一种:在映射文件中添加二级缓存的标签 

第二种:使用注解的形式添加  

 

SysResult

package com.jt.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.io.Serializable;

@Data
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
public class SysResult implements Serializable {
    private Integer status; //200业务执行成功 201业务执行失败
    private String msg; //服务器的提示信息
    private Object data; //封装后台返回值

    public static SysResult fail(){
        return new SysResult(201,"业务执行失败",null);
    }

    public static SysResult success(){
        return new SysResult(200,"业务执行成功",null);
    }

    //服务器返回业务数据
    public static SysResult success(Object data){
        return new SysResult(200,"业务执行成功",data);
    }

    public static SysResult success(String msg,Object data){
        return new SysResult(200,msg,data);
    }
}

R

package com.wx.vo;

import lombok.Data;
import lombok.experimental.Accessors;

import java.util.HashMap;
import java.util.Map;

@Data
@Accessors(chain = true)
public class R {

    private Integer code; //响应码
    private String message; //响应消息
    private Map<String, Object> data = new HashMap<>();

    public static R ok(){
        R r = new R();
        r.setCode(200);
        r.setMessage("成功");
        return r;
    }

    public static R error(){
        R r = new R();
        r.setCode(201);
        r.setMessage("失败");
        return r;
    }

    public R data(String key, Object value){
        this.data.put(key, value);
        return this;
    }

}

阅读数量加一:

UPDATE zh_randomly SET countt =( CASE WHEN countt IS NULL THEN 1 ELSE countt + 1 END ) WHERE id =?

Mybatis-plus中的IService

service层中继续IService并将对象放入

public interface ProductService extends IService<Product> {

serviceImpl中进行实现和继承


@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements ProductService {

完成上面的继承和实现后,service层也可以进行直接调用mybatis-plus的增删改查API

@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements ProductService {


    @Override
    public Map<String, Object> getAll() {

        Product product = baseMapper.selectById(1);
        System.out.println("查询 = " + product);

        QueryWrapper<Product> queryWrapper = new QueryWrapper<>();
        queryWrapper.le("id","1");
        List<Product> products = baseMapper.selectList(queryWrapper);
        System.out.println("查询list = " + products);
        
        baseMapper.insert();
        baseMapper.delete();
        baseMapper.update();
        

        Map<String, Object> map = new HashMap<>();
        map.put("product",product);
        map.put("products",products);
        return map;
    }

}

在controller中通过注入Service也可直接调用API

@CrossOrigin
@RestController
@RequestMapping("/api/product")
@Api(tags = "商品管理")
public class ProductController {


    @Resource
    private ProductService productService;


    @GetMapping("/list")
    public R list(){
        List<Product> list = productService.list();//得到所有数据
        return  R.ok().data("productList",list);
    }


    @ApiOperation("测试IService")
    @GetMapping("/l")
    public R l(){
        List<String> list = new ArrayList<>();
        list.add("1");
        list.add("2");
        list.add("3");
        List<Product> products = productService.listByIds(list);//多个id得到数据


        Map<String, Object> all = productService.getAll();

        return  R.ok().data("products",products);
    }

}

WHERE   IF if判断

 <select id="findGys" resultType="java.util.Map">
        select * from rc_lbj
        <where>
            <if test=" offices != ''">
                and offices like concat('%', #{offices}, '%')
            </if>
            

            <if test="listF  != ''">

                <if test="maxF  != '' and maxF  != '0'">
                    and lbj_mark_all >= #{listF} and lbj_mark_all <![CDATA[ <= ]]> #{maxF}
                </if>

            </if>

            <if test="state != ''">
                and status = #{state}
            </if>
            and del_flag = '0'

        </where>
    </select>

mybatis 遍历for循环

    <select id="selectListById" parameterType="map" resultType="java.util.Map">
        select * from ${database}

        <where>
            <if test="id != null and id != ''">
                and zid IN
                <foreach collection="id" index="id" item="id" separator="," open="(" close=")">
                    #{id}
                </foreach>
            </if>
        </where>
        ORDER BY create_time DESC

    </select>

Mybatis、Mybatis-plus框架 3、PageHelper插件:引入依赖、开启分页(PageHelper.startPage(pageNum,pageSize))、分装结果(PageInfo<~> pageInfo = new PageInfo<>(结果对象))通过XML或注解的方式将statement配置起来,用java对象与动态参数进行映射形成最终的执行语句,由Mybatis执行SQL语句,并将结果映射为java对象。半ORM(对象关系映射)框架,内部封装JDBC,只需关注SQL,严格控制SQL执行性能,灵活性高。 阅读详情

相关推荐

NPP/VIIRS夜间灯光数据下载和介绍

夜间灯光数据作为当前比较火热的研究数据,与其他遥感数据不同,它是通过DN值来体现所携带的信息,最常用的使用月度数据。 该数据数据量大,下载慢,相对来说较难快速获取。 一、数据下载 美国国家海洋大气管理局NOAA下属的NCEI国家环境信息中心Earth Observation Group。 二、月度数据文件介绍 从网站上下载的逐月的灯光数据文件是压缩包的形式,每月的数据包括vcm, vcmsl两个版本的压缩包,其中vcm版本排除了受杂散光影响的数据,vcmsl版本为辐射值经过杂散光校正程序后的数

端木宛白的博客家园 7376

Mybatis 框架详解

MyBatis 最初是由 Clinton Begin 在 2002 年开发的 iBATIS,在经过多年的发展和改进后,于 2010 年正式更名为 MyBatis,并成为一个独立的开源项目。// 省略 getter 和 setter 方法 }本文简单介绍了 MyBatis 的基本使用和高级用法,并讲解了如何将其整合到 Spring 框架中。MyBatis 是一款优秀的 ORM 框架,具有灵活性强、易于学习和使用等优点,适合各种规模的应用程序的开发。

兴趣是最好的老师,勤能补拙 9253

数据科学常见模型总结(二)-倾向性得分匹配模型

PSM的核心思想是从未受干预的用户群体中,找到和干预对象一模一样的用户,这样就可以把因果效应归因到干预上。

wudelong0112的专栏 4891

MyBatis 框架

使用sqlSession.commit()提交事务,是因为在连接池中取出的连接,都会将调用connection.setAutoCommit(false)方法,这样我们就必须使用sqlSession.commit()方法,相当于使用了JDBC中的connection.commit()方法实现事务提交。代表占位符,类似jdbc中的?框架是我们使用软件开发中的一套解决方案,不同的框架能解决不同的问题,在框架中封装了很多的细节,使开发者可以使用极为简便的方式实现功能,大大的提升了开发的效率。

2501_90255619的博客 4827

Unity UI适配实战:从Canvas Scaler到主流游戏适配方案解析

本文深入解析Unity UI适配的核心技术,重点介绍Canvas Scaler组件的关键参数如Reference Resolution和Screen Match Mode,并提供主流游戏适配方案实战分析。通过九宫格拉伸、动态调整等技巧,帮助开发者解决多设备适配难题,提升游戏UI在不同分辨率下的表现。

weixin_29001419的博客 972

3、★☛基于STM32的手机通过wifi控LED灯√♠★

3、基于STM32的手机通过wifi控LED灯 文章目录3、基于STM32的手机通过wifi控LED灯1、Introduce介绍1.1、课题背景及其意义1.2、 国内外的研究状况2、方案的设计2.1、控制方案的确定2.2、控制方式的选择2.2.1、 单片机芯片的选择方案一方案二方案三方案四2.2.2、无线遥控模块的选择方案一方案二方案三3、硬件电路的设计3.1、系统的功能分析及体系结构设计3.1.1、系统功能分析3.1.2、系统总体结构3.2、模块电路的设计3.2.1、 STM32单片机核心电路设计3.2.

行走的皮卡丘 2962

Mybatis框架的学习

MyBatis 是一款优秀的框架,它支持定制化以及高级映射。MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取。MyBatis 可以使用简单的 XML 或注解来配置和映射原生信息,将接口和 Java 的(Plain Ordinary Java Object,普通的 Java对象)映射成数据库中的记录。

zhujuanlideyang7的博客 1622

408 | 408常用计算公式与方法 —— 计组篇 汇总

408常用计算公式与方法 —— 计算机组成原理篇 汇总

"You are worthy! You can do it!" 4655

mybatis框架

MyBatis最初是Apache的一个开源项目iBatis, 2010年6月这个项目由Apache Software Foundation迁移到了随着开发团队转投Google Code旗下,iBatis3.x正式更名为MyBatis。代码于2013年11月迁移到Github。MyBatis 是一款优秀的持久层框架,用于简化 JDBC 开发。它支持自定义 SQL、存储过程以及高级映射。MyBatis 免除了几乎所有的 JDBC 代码以及设置参数和获取结果集的工作。

2401_85217463的博客 2084

[企业AI落地] RAG 知识库系统在多租户环境下的细粒度权限隔离设计

多租户 RAG 系统真正的风险不只是搜不到,而是把不该看到的内容查出来、说出来、写回去。本文结合多客户售后知识助手场景,用元数据结构、向量检索过滤、回答策略和审计回写示例拆解租户、资源、检索、生成、审计五层权限边界。

技术小甜甜:传播可落地技术,帮助个人和企业降低解决真实场景问题的成本 220

YOLO26优化:注意力魔改 | EMA:基于跨空间学习的高效多尺度注意力,效果优于ECA、CBAM、CA

加入EMA注意力,一种基于跨空间学习的高效多尺度注意力,效果优于ECA、CBAM、CA等经典注意力。

①答疑群聊服务;②YOLO大模型知识问答系统;③计算机视觉论文生成智能体; 334

MyBatis框架详解

MyBatis由Apache软件基金会维护,旨在解决传统JDBC的复杂性。它不是一个完整的ORM(对象关系映射)框架(如Hibernate),而是聚焦于SQL管理。

2302_78370645的博客 1678

深度学习工具包 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")

MyBatis框架的作用

1.什么是框架 框架(Framework)是整个或部分系统的可重用设计,表现为一组抽象构件及构件实例间交互的方法;另一种定义认为,框架是可被应用开发者定制的应用骨架。前者是从应用方面而后者是从目的方面给出的定义。简而言之,框架其实就是某种应用的半成品,就是一组组件,供你选用完成你自己的系统。简单说就是使用别人搭好的舞台,你来做表演。而且,框架一般是成熟的,不断升级的软件。 2.框架要解决的问题 框...

一点博客 1万+

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

上一篇: Mybatis jar包
下一篇: Nacos 服务注册中心
辣椒太少不适合吃
博客等级 码龄5年 2691粉丝 88原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值