Spring-boot学习(二):IntelliJ IDEA Spring-boot 整合mybatis

Intellij IDEA创建SpringBoot项目(超详细)+Mybatis整合Ajax+Bootstrap前端学习增删改查 超详细的SpringBoot项目创建步骤一、SpringBoot介绍二、创建SpringBoot项目三、创建静态资源页面四、数据库编程(Mapper)五、控制器层与持久层六、整合前端界面 一、SpringBoot介绍 二、创建SpringBoot项目 三、创建静态资源页面 四、数据库编程(Mapper) 五、控制器层与持久层 六、整合前端界面 ... 阅读详情
  使用mybatis的一键生成mapper文件与基本的增删该查接口功能,只需要开发人员设计好数据库结构即可,这样大大提高
了 开发 效率,关于整合部分大家可以参考优快云博客:点击打开链接,这个博主很详细的介绍了spring-boot 和mybatis的整合
过程。
本文将展现以下几个内容:
 1、我在学习这个内容的时候遇到的问题以及解决方案。
2、对分页插件pageHelper的一些补充。

源码github地址:git@github.com:FunCodeH/spring-boot-study.git

一、对于笔者推荐的博客使用的是付费版的IDEA,如果需要使用社区办创建,可参考以下内容创建:

1、登录spring官网,生成项目demo,官网链接如下点击打开链接。选择依赖包括web、mybatis、mysql,点击Generate
Project 将demo下载到本地。

2、使用IEDA打开demo程序。选择File -> Open -> 选中demo程序的pom.xml文件,点击下一步 ->选择Open as Project
打开工程,以下是工程结构:

二、学习中遇到的问题以及解决方案
1、大家可以看到在博主原来的generatorConfig.xml配置文件里面,mysql驱动是在自己本地磁盘的保存的,代码如下:
<!-- 数据库驱动:选择你的本地硬盘上面的数据库驱动包-->
    <classPathEntry  location="E:\developer\mybatis-generator-core-1.3.2\lib\mysql-connector-java-5.1.25-bin.jar"/>
但是在开发过程中,大家本地mysql驱动的jar包位置各不相同,如果写死每个人都需要去修改,建议大家去掉这行配置,
直接在pom.xml文件里添加mysql驱动的依赖即可:
<!-- mybatis generator 自动生成代码插件 -->
			<plugin
				<groupId>org.mybatis.generator</groupId>
				<artifactId>mybatis-generator-maven-plugin</artifactId>
				<version>1.3.2</version>
				<configuration>
					<configurationFile>${basedir}/src/main/resources/generator/generatorConfig.xml</configurationFile>
					<overwrite>false</overwrite>
					<verbose>true</verbose>
				</configuration>
				<dependencies>
					<dependency>
						<groupId>mysql</groupId>
						<artifactId>mysql-connector-java</artifactId>
						<version>5.1.39</version>
					</dependency>
				</dependencies>
			</plugin>
2、如何在spring boot 启动时就初始化druid数据源,而不是在执行第一条sql的时候初始化。这个问题只需要实现spring
框架的EnvironmentAware方法即可,具体代码如下:
@Configuration
@EnableTransactionManagement
public class DatabaseConfiguration implements EnvironmentAware {
    private static final Logger logger = Logger.getLogger(DatabaseConfiguration.class);
    private RelaxedPropertyResolver propertyResolver;

    @Override
    public void setEnvironment(Environment env) {
        this.propertyResolver = new RelaxedPropertyResolver(env, "spring.datasource.");
    }

    @Bean(destroyMethod = "close", initMethod = "init")
    public DataSource writeDataSource() {
        logger.info("使用druid数据源");

        DruidDataSource datasource = new DruidDataSource();
        datasource.setUrl(propertyResolver.getProperty("url"));
        datasource.setDriverClassName(propertyResolver.getProperty("driver-class-name"));
        datasource.setUsername(propertyResolver.getProperty("username"));
        datasource.setPassword(propertyResolver.getProperty("password"));
        datasource.setInitialSize(Integer.parseInt(propertyResolver.getProperty("initialSize")));
        datasource.setMinIdle(Integer.parseInt(propertyResolver.getProperty("minIdle")));
        datasource.setMaxWait(Long.parseLong(propertyResolver.getProperty("maxWait")));
        datasource.setMaxActive(Integer.parseInt(propertyResolver.getProperty("maxActive")));
        datasource.setMinEvictableIdleTimeMillis(Long.parseLong(propertyResolver.getProperty(
                "minEvictableIdleTimeMillis")));
        try {
            datasource.setFilters(propertyResolver.getProperty("filters"));
        } catch (SQLException e) {
            throw new RuntimeException("添加过滤异常" + e);
        }
        return datasource;
    }

    @Bean(name = "druid-stat-interceptor")
    public DruidStatInterceptor setDruidStatInterceptor() {
        return new DruidStatInterceptor();
    }

    @Bean(name = "druid-stat-pointcut")
    public JdkRegexpMethodPointcut setJdkRegexpMethodPointcut() {
        JdkRegexpMethodPointcut jdk = new JdkRegexpMethodPointcut();
        jdk.setPatterns("com.funcodeh.mybatis.demo.*");
        return jdk;
    }
}
3、在调试的时候如何将sql输出到控制台上,如果看不到执行的sql语句将会给调试代码带来很大的不便,这个问题可以参考
mybatis的官方文档,只需要增加一个配置,代码如下,首先增加一个mybatis-config.xml文件,内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD SQL Map Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
    <settings>
        <setting name="logImpl" value="STDOUT_LOGGING" />
    </settings>

</configuration>
目前这个配置文件只设置了logImpl属性,使用STDOUT_LOGGING作为打印sql的输出模式。然后在application配置文件
中增加如下代码,指定mybatis的配置文件的路径。
mybatis:
  mapper-locations: classpath:mapping/*.xml
  type-aliases-package: com.funcodeh.mybatis.demo
  configLocation: classpath:mybatis-config.xml
然后运行程序,调用接口就能在控制台上看到执行的sql啦,如下所示为控制台打印输出:
Creating a new SqlSession
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@2301c2d9] was not registered for synchronization because synchronization is not active
JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@6ab20f44] will not be managed by Spring
==>  Preparing: insert into t_user ( user_name, mobile, email ) values ( ?, ?, ? ) 
==> Parameters: 123string(String), 123(String), 123(String)
<==    Updates: 1
4、从第三个问题的控制台打印可以看到一个提示信息,即标红的部分,意思是该sql执行时没有加入到spring事务管理中去
有可能会导致并发问题,解决这个问题只需要在service层的实现类上增加事务Transactional注解即可:
@Service
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public class UserServiceImpl implements UserService{
     增加事务管理之后再次执行可以看到控制台打印变成以下内容,至此该问题解决:
Creating a new SqlSession
Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@6e0881c9]
JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@4eeecbcf] will be managed by Spring
==>  Preparing: insert into t_user ( user_name, mobile, email ) values ( ?, ?, ? ) 
==> Parameters: 123string(String), 123(String), 123(String)
<==    Updates: 1
     三、关于pageHelper分页插件
补充说明,在web开发中使用的分页需要进行显示,分页插件会在sql执行前,执行一次统计总查询结果的sql,通常情况下需要将一些页码信息返回给前台用于显示,这些信息都保存在Page中,代码如下:
@Override
    public List<User> findAllUser(int pageNum, int pageSize) {
        //将参数传给这个方法就可以实现物理分页了,非常简单。
        //page包含了分页结果,查询之后可以通过page获取相关的信息。
        Page page= PageHelper.startPage(pageNum, pageSize);
        List<User> list = userMapper.selectAllUser();
        System.out.println("--------------->" + page);
        System.out.println("--------------->" + page.getCountColumn());
        return  list;
    }
     如上代码所示,在执行完selectAllUser()方法之后会通过startPage()方法将page信息返回。


















IntelliJ IDEA Spring Boot(5) 集成Hibernate 上一篇集成了mybatis。这一篇我来集成hibernate,顺道把ehcache缓存也集成进去。下篇我们再讲 mybatis与ehcache集成 阅读详情

相关推荐

Java之Spring Boot入门到精通【IDEA版】SpringBoot整合其他框架【Junit,Redis,MyBatis

创建数据库!t_useridusernamepasswordidt_user*/t_useridusernamepassword创建实体类return id;

m0_60635609的博客 1208

使用IDEA构建Spring boot2.0+版本+MyBatis(properties文件配置)

最近项目从SSM转SpringBoot,但是不是用MyBatis而是用Spring JDBC 这篇博文也算记录我SpringBoot的搭建 1、Intellij idea菜单栏File-&gt;new-&gt;project 选择左侧栏中spring initializr,右侧选择jdk版本,以及默认的Service URL,点击next。 2、然后填写项目的Group、Artifact等信息,...

dom402的博客 3094

IntelliJ IDEA + 阿里 Qoder:Spring Boot Agentic 编码实战指南

Agentic 编码是一种以任务规划、工具调用与自主修正为核心的智能开发范式,其本质是将大模型从‘代码补全器’升级为‘IDE 协同代理’。实现该能力需三大支柱:具备完整项目语义索引的 IDE(如 IntelliJ IDEA)、深度蒸馏领域知识的专用 AI 模型(如阿里 Qoder CN),以及轻量可扩展的指令交互协议(如 MCP)。在 Spring Boot 开发中,Qoder 基于 PSI 接口实时感知 Maven 依赖、Bean 上下文与资源配置,结合 MCP 驱动 Apache POI、iText7、

weixin_30628801的博客 603

springboot

Spring Initializr建立项目也可以在idea上直接创建,我们在创建时springboot的版本不能选择 3.0.0,因为springboot3.0.0只支持idea17的版本 我们更改端口号一般在资源目录下的application.properties 3.自动装配 pom.xml 启动器:说白了就是springboot的启动场景,下面导入的就是自动帮我们导入web环境所有的依赖 springboot会将所有的场景变成一个个启动器 ,我们要是用什么功能只需

qq_51923226的博客 4957

Spring Boot 2.7 + MyBatis 3.5 项目:3步配置永久消除 IDEA Mapper 注入警告

本文详细介绍了在Spring Boot 2.7和MyBatis 3.5项目中,如何通过3步配置永久消除IDEA中Mapper注入的警告问题。从依赖管理、IDE插件配置到SQL方言设置,提供了一套完整的解决方案,帮助开发者提升开发效率,避免视觉干扰。

weixin_34178244的博客 593

SpringBoot、IntelliJ IDEA和MyBatis整合教程

本文还有配套的精品资源,点击获取 简介:Spring Boot、IntelliJ IDEA和MyBatis是构建企业级Web应用的关键技术组件。本文详细说明了如何整合这三种技术,创建具备增删改查功能的系统。首先介绍Spring Boot的自动配置和项目初始化过程,接着阐述了IntelliJ IDEA在项目创建和管理中的优势,最后探讨了MyBatis如何通过XML或注解简化数...

weixin_36277197的博客 1389

使用IDEA2021.1搭建SpringBoot2.7.4

使用IDEA2021.1搭建SpringBoot

qq_35160479的博客 2418

IDEA中Spring Boot集成MyBatis和Spring MVC的完整指南

MyBatis是一个Java持久层框架,它通过XML或注解配置与Java对象映射的方式来管理SQL语句。它提供了对JDBC操作的轻量级封装,使得开发者可以专注于SQL本身而非繁琐的配置和复杂的API调用。虽然自动配置为大多数情况提供了便利,但在实际的开发和生产环境中,我们可能需要根据实际需要对数据源进行自定义配置。在 Spring Boot 中,可以通过配置文件或 Java 配置类来指定数据源的参数。

weixin_42613360的博客 1228

ideal中修改springboot启动参数

项目中的配置文件是存放在远程的,启动项目时需要去读取远程的配置文件,由于配置文件是共享的,所以不能随意更改他。 一般是在本地配置一个application.yaml(或properties等)。只是这种不方便,万一手滑提交到git就不好了。 IDEA中提供了在springboot项目启动时覆盖配置参数的功能: ...

Zhtt的博客 1772

从零开始:使用IntelliJ IDEA搭建Spring Boot与MyBatis入门级工程

在Spring Boot项目中,日志级别通常在配置文件中设置。比如,可以在中设置日志级别如下:这个配置会使得Spring Web相关的日志输出级别调整为DEBUG级别。如果需要更复杂的日志配置,比如不同环境使用不同的日志配置文件,可以通过日志框架的配置文件进行自定义,如使用Logback的或Log4j2的log4j2.xml。自定义配置文件允许用户根据需要调整日志输出,包括控制台输出、文件输出、日志格式、滚动策略等。

weixin_42578963的博客 751

Win11系统下Notepad++右键菜单失效?3种修复方法实测有效(附注册表备份指南)

本文针对Windows 11系统中Notepad++右键菜单失效的常见问题,提供了三种经过实测有效的修复方法。核心解决方案包括使用官方NppShell.dll重新注册、手动修复注册表项以及系统级问题排查,并详细说明了操作前的注册表备份指南,确保修复过程安全可靠。

m2n3b4v5c6的博客 328

Idea创建Springboot项目

一、环境配置 创建一个Springboot项目首先需要安装Idea、配置JDK、Maven,这里就不多说了 这里我用的Maven是3.6.3,相对来说比较稳定,直接解压就好 二、创建Springboot项目 方法一: 1.打开Idea,创建一个新项目: 2.选择 Spring Initializr,选择项目的SDK 为 1.8,选择 starter service URL 为 http://start.spring.io(默认),最后点击下方的 Next 按钮进行下一步 3.在 S..

qq_46017272的博客 5859

DPM|03Injection设置

摘要:本文介绍了CFD软件Fluent中粒子注入的设置方法。粒子注入是将离散颗粒引入连续相的过程,可用于模拟灰尘、燃料液滴等。设置流程包括:选择粒子类型(质量less、惰性等)、定义注入点属性(坐标、时间、粒径等)、处理多组分粒子、使用文本文件批量定义复杂注入。文中还详细说明了要考虑的湍流影响,包括随机追踪法模拟湍流扩散,以及粒子旋转建模等注意事项。最后介绍了多种注入类型和粒子类型,并强调在湍流系统中需设置足够的尝试次数以确保结果准确性。

qq_28258217的博客 2229

使用IDEA创建Spring Boot项目, 整合Mybatis ,连接MySql数据库,实现简单的登录注册功能

Java 实现登录注册(通用) 欢迎使用Markdown编辑器 你好! 这是你第一次使用 Markdown编辑器 所展示的欢迎页。如果你想学习如何使用Markdown编辑器, 可以仔细阅读这篇文章,了解一下Markdown的基本语法知识。 新的改变 我们对Markdown编辑器进行了一些功能拓展与语法支持,除了标准的Markdown编辑器功能,我们增加了如下几点新功能,帮助你用它写博客: 全新的...

赵周周的养心殿 9743

模型优化系列——模型剪枝/量化概述

模型优化目的:通过减少模型大小,提高推理速度等使模型成功部署在各个硬件中并实时有效运作。

qq_61210574的博客 1295

华为OD机试双机位C卷-字符串解密(Py/Java/C/C++/Js/Go)

华为OD机试(机考)双机位C卷 【字符串解密】,提供C语言、Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解,以及在线OJ模拟做题。华为OD机试 - 字符串解密。

qq_45776114的博客 736

HBuilderX和IntelliJ IDEA实现简单登录认证功能

今天抽空写了一个登录的demo项目,使用HBuilderX和IntelliJ IDEA创建前后端分离的项目,并实现简单的登录功能(简单连接数据库判断),通过Ajax与后端的Spring Boot项目进行交互。

沐雨橙风ιε的博客 1万+

【GameFramework扩展应用】6-5、GameFramework框架出包时增加版本信息Version.txt文件

框架在热更新的时候,会先去获取文件,然后获取版本号,对比版本号和资源大小,才会开始下载资源。但是,框架生成AssetBundle资源的包里面是没有这个文件的,只能我们新建一个文件,然后手动填入数据,非常麻烦。好消息是,框架把这些接口都留给我们了,我们只需要继承接口,重写函数,然后在打包的时候选择这个辅助器即可。下面就来看一下如何实现把。

优快云博客专家,Unity3D高级软件工程师,《Unity 3D从入门到实战》作者。 1042

Spring Boot整合MyBatis实现简单的CRUD

这篇文章主要针对java初学者,详细介绍如何创建一个基本的springboot项目来对数据库进行crud操作。

沐雨橙风ιε的博客 4490

华南理工大学-大学物理实验-绪论作业

3.用公式测量某圆柱体铝的密度,测得直径=2.0420.003(cm),高=4.1260.004(cm),质量=36.4880.006(g)。计算铝的密度和测量的标准差,并以测量结果表达式表示之。(要求判别和剔除异常数据)(30分)(了解图解法的注意事项,大学物理实验众多实验数据处理采用这种方法,如PN结温度特性研究,光电效应与普朗克常数的测定,霍尔效应测磁场等等,注意规范作图)实验测得温度与对应的金属丝的长度的数据如下表所示。(了解异常数据的判断方法及具体判断过程,30分的题目n(*≧▽≦*)n)

mohen_777的博客 583

RTOS与Linux功能差异与应用场景全面对比

在嵌入式系统的开发中,操作系统的选择至关重要。和是两种广泛应用的操作系统,它们在功能、设计目标以及应用领域中各具优势。随着嵌入式系统的不断发展,已成为嵌入式行业的大趋势。那么,这两者到底有什么不同呢?

硬核科技 405

IntelliJ IDEA中Spring Boot项目整合MyBatis:从零实现高效数据持久化

MyBatis作为一款灵活且强大的‌ORM框架‌,凭借其直观的SQL映射和动态SQL能力,成为Java开发者首选的持久层解决方案。本文将以‌和‌为例,手把手教你‌在IDEA中集成MyBatis‌,涵盖‌注解与XML两种开发模式‌、‌分页插件集成‌、‌多数据源配置‌及‌生产级避坑指南‌,助你轻松实现高效数据操作!@Data通过Spring Boot与MyBatis的整合,开发者可以灵活选择注解或XML方式管理SQL,兼顾开发效率与维护性。本文从基础配置到高级应用,覆盖了企业级开发的核心需求。

weixin_42593797的博客 1338

详解Xilinx FPGA高速串行收发器GTX/GTP(1)--SerDes和GTX的关系

详解Xilinx FPGA高速串行收发器GTX/GTP(1)--SerDes和GTX的关系

孤独的单刀 4357

【Spring Boot】1.解决IDEA中springboot整合mybatis中出现的Invalid bound statement(not found)的问题

    最近学习springboot的开发,中间磕磕碰碰也是遇到了诸多问题,以前编写java IDE都是用的eclipse,现在换成idea了倒有点不适应了,中间遇到了一个让人很郁闷的问题,困扰了我一天,在这里做一下总结:     看到这个问题以后,首先想到的是不是自己的Controller写的有问题,写个测试类测试了一下,发现不是接口的问题,在网上搜了一下,是mapper文件映射的问题,这...

返璞归真 13万+

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

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

Spring Boot(4)使用 IDEA 搭建 Spring Boot+MyBatis 项目全流程实战

通过以上步骤,我们就成功地使用 IDEA 搭建了一个 Spring Boot + MyBatis 项目啦,并完成了从项目创建、配置、开发、测试到部署的全流程。Spring Boot 和 MyBatis 的结合,充分发挥了两者的优势,使得项目开发高效、灵活且易于维护。添加缓存:引入 Spring Cache 或 Redis 等缓存技术,提高系统的性能和响应速度。集成安全框架:使用 Spring Security 进行用户认证和授权,确保系统的安全性。日志管理。

綦枫Maple的博客 3305

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

Spring Boot整合tk-mybatis、PageHelper

本文介绍了tk-mybatis这一曾经流行的MyBatis增强框架的使用方法,尽管它已被MyBatis-Plus取代,但仍值得了解。文章详细展示了如何从零开始整合tk-mybatis:从数据库准备(创建歌曲表并插入测试数据)、创建Spring Boot项目、添加依赖(包括tk-mybatis和分页插件PageHelper),到配置数据源和MyBatis。重点讲解了实体类创建、Mapper接口定义(继承tk.mybatis.mapper.common.Mapper)以及核心API的使用,包括增删改查操作和基于

沐雨橙风ιε的博客 3565

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

上一篇: Spring-boot学习(一):IntelliJ IDEA 搭建Spring-boot 框架HelloWorld
下一篇: 错误解决:The superclass &quot;javax.servlet.http.HttpServlet&quot; was not found on the Java Build...
FunCodeH
博客等级 码龄9年 3粉丝 4原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值