mysql 基础(三)- springboot项目连接mysql

Java(一):创建 Spring Boot 项目并实现连接操作MySQL数据库 命令 Maven 相关地址本地配置 下载并配置本地环境构建EasyCodeMyBatisPlus在中引入(别忘了) 创建并编写 利用插件快速创建操作数据库相关代码 应用程序通常使用以下几个组件来组织代码利用 搜索解决 尝试运行(报错:没有引入对应版本) 尝试运行(缺少 注解) @SpringBootApplication注解是一个组合注解,它的作用是标记一个Spring Boot应用程序的主类。它包括三个注解:, 和 @Configuration:将该类标记为Spring应用程序上下文中的一个b 阅读详情
AI摘要

本文详细介绍了如何在SpringBoot项目中集成MySQL,包括安装插件、配置POM.xml、创建数据库表、编写Controller和Mapper接口,以及使用Postman进行接口测试。

mysql 基础(三)- springboot项目连接mysql

一、通过Idea脚手架搭建springboot项目

1、在idea工具中安装插件 Alibaba Cloud Toolkit

在这里插入图片描述

2、创建新项目

在这里插入图片描述
下一步
在这里插入图片描述
选择springWeb
在这里插入图片描述
完成
在这里插入图片描述

3、得到项目

在这里插入图片描述
启动项目
在这里插入图片描述
启动成功
在这里插入图片描述
访问页面
在这里插入图片描述

二、集成springboot 与 mybits 集成

该例子仅仅是进行一个简单的集成

1、在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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>1.8</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <spring-boot.version>2.6.13</spring-boot.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!-- mybatis 依赖 -->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.0.0</version>
        </dependency>
        <!-- mysql 连接类 -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <!-- druid 数据库连接池-->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.1.9</version>
        </dependency>
        <!-- lombok 插件 用于简化实体代码 -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.1-api</artifactId>
            <version>1.0.0.Final</version>
        </dependency>
    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>${spring-boot.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>${spring-boot.version}</version>
                <configuration>
                    <mainClass>com.example.demo.DemoApplication</mainClass>
                    <skip>true</skip>
                </configuration>
                <executions>
                    <execution>
                        <id>repackage</id>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

2、按照图片创造目录结构

在这里插入图片描述

3、各个文件内容

1、StudentController

package com.example.demo.demos.mybatis.controller;

import com.example.demo.demos.mybatis.domain.Student;
import com.example.demo.demos.mybatis.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/Student")
public class StudentController {

    @Autowired
    private StudentService studentService;

    @PostMapping("")
    public int add(@RequestBody Student student){
        return studentService.add(student);
    }

    @PutMapping("/{id}")
    public int updateStudent(@PathVariable("id") Integer id, @RequestParam(value = "name", required = true) String name,
                             @RequestParam(value = "age", required = true) Integer age){
        return studentService.update(name,age,id);
    }

    @DeleteMapping("/{id}")
    public void deleteStudent(@PathVariable("id") Integer id){
        studentService.delete(id);
    }

    @GetMapping("/{id}")
    public Student findStudentById(@PathVariable("id") Integer id){
        return studentService.findStudentById(id);
    }

    @GetMapping("/list")
    public List<Student> findStudentList(){
        return studentService.findStudentList();
    }
}

2、studentMapper

package com.example.demo.demos.mybatis.dao;

import java.util.List;

import com.example.demo.demos.mybatis.domain.Student;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface StudentMapper {

    @Insert("insert into student(name, age) values(#{name}, #{age})")
    int add(Student student);

    @Update("update student set name = #{name}, age = #{age} where id = #{id}")
    int update(@Param("name") String name, @Param("age") Integer age, @Param("id") Integer id);

    @Delete("delete from student where id = #{id}")
    int delete(int id);

    @Select("select id, name as name, age as age from student where id = #{id}")
    Student findStudentById(@Param("id") Integer id);

    @Select("select id, name as name, age as age from student")
    List<Student> findStudentList();
}

3、student

package com.example.demo.demos.mybatis.domain;

import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Student {

    @Id
    @GeneratedValue
    private Integer id;

    private String name;

    private Integer age;

}

注解:
@Data:可以自动为类生成常用的方法,包括 getter、setter、equals、hashCode 和 toString 等
@NoArgsConstructor: 自动生成无参数构造函数。
@AllArgsConstructor: 自动生成全参数构造函数。
@Id :标识实体类中的主键字段
@GeneratedValue:为一个实体生成一个唯一标识的主键、提供主键的生成策略

4、studentServiceImpl

package com.example.demo.demos.mybatis.service.impl;

import java.util.List;

import com.example.demo.demos.mybatis.dao.StudentMapper;
import com.example.demo.demos.mybatis.domain.Student;
import com.example.demo.demos.mybatis.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    private StudentMapper studentMapper;

    /**
     * 添加 Student
     * @param name
     * @param age
     * @return
     */
    @Override
    public int add(Student student) {
        return studentMapper.add(student);
    }

    /**
     * 更新 Student
     * @param name
     * @param age
     * @param id
     * @return
     */
    @Override
    public int update(String name, Integer age, Integer id) {
        return studentMapper.update(name,age,id);
    }

    /**
     * 删除 Student
     * @param id
     * @return
     */
    @Override
    public int delete(Integer id) {
        return studentMapper.delete(id);
    }

    /**
     * 根据 id 查询 Student
     * @param id
     * @return
     */
    @Override
    public Student findStudentById(Integer id) {
        return studentMapper.findStudentById(id);
    }

    /**
     * 查询所有的 Student
     * @return
     */
    @Override
    public List<Student> findStudentList() {
        return studentMapper.findStudentList();
    }
}

5、StudentService

package com.example.demo.demos.mybatis.service;

import com.example.demo.demos.mybatis.domain.Student;

import java.util.List;

public interface StudentService {

    int add(Student student);

    int update(String name, Integer age, Integer id);

    int delete(Integer id);

    Student findStudentById(Integer id);

    List<Student> findStudentList();

}

有爆红的地方引入相应的包即可

6、配置文件 application.properties

# 应用服务 WEB 访问端口
server.port=8082
spring.datasource.url=jdbc:mysql://localhost:3306/test
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

4、在navicat中操作数据库

1、新建test数据库
在这里插入图片描述
2、点击”新建查询“新建表,并插入数据

CREATE TABLE `student` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(20) NOT NULL,
  `age` double DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;
INSERT INTO `student` VALUES ('1', 'aaa', '21');
INSERT INTO `student` VALUES ('2', 'bbb', '22');
INSERT INTO `student` VALUES ('3', 'ccc', '23');

三、演示

Controller 文件中 对应的GetMapping,DeleteMapping,PutMapping、PostMapping 请求需要postman进行相应的测试
这里演示GetMapping
在这里插入图片描述

第一个搭建SpringBoot项目(连接mysql) 首先新建项目找到Spring Initializr 我使用的URL是这里最低的JDK版本是17,而且当网速不好的时候可能会显示超时,这里可以选用阿里云的镜像可以更快一些但是里面还是有一些区别的我们这里选择Java语言,Maven框架在这里我们选择一些我们需要用到的这个版本可以选低一点更加稳定进来之后我们需要先等pom文件加载,我们可以选择刷新Maven加载完之后由于我们加载了MySQL所以还不能运行可以先注释掉,然后刷新maven。 阅读详情

相关推荐

Spring Boot 通过mybatis接入MySql数据库

Spring Boot、Mybatis

Try my best的博客 1712

SpringBoot框架之SpringBoot+MySQL使用案例入门

Tip:具体代码简单不复杂,最后附上所有数据操作截图! 一、添加依赖: 在pom.xml文件里添加所需要的JDBC组件和MySQL连接器,以及方便使用JavaBean的get,set方法的lombok依赖 (注意:springBoot的mysql-connector-java如果不指定版本。默认是MySQL最高版本8.x,故为了防止不必要的bug出现,一定要看你当前安装的MySQL版本,一定要匹配上) <!--集成mysql数据库--> <dependency> &...

guihua55的博客 2万+

Springboot项目本地连接并操作MySQL数据库

CrossOrigin(origin=“*”):允许所有来源访问该url,解决本地访问跨域问题@RestController:@Controller和@ResponseBody的组合,它告诉Spring这个类是一个控制器(Controller),并且所有的方法返回的内容都直接写入HTTP响应体中,而不是解析为跳转路径,这通常用于RESTful Web服务,其中返回的数据是JSON或XML等格式。

m0_74823892的博客 1662

【SpringBoot】7 数据库(MySQL&MyBatis)

MySQL,SpringBoot,MyBatis,MyBatisPlus,thymeleaf

寻道书生的博客 3134

Vivado时序违例debug

显示了数据路径延迟。例如,对于违例路径,若布线延迟超过50%,说明该延迟是导致时序不能收敛的主要因素,因此可围绕降低布线延迟这一靶心达到时序收敛。对于跨时钟域路径,Requirement数值会有所变化,但如果数值为0.1,显然是不合理的。目的时钟路径单元,时钟从adc0_bufg/O输出,到达PLLE4_ADV,经过BUFGCE输出,最终到达SRLC32E移位寄存器,对应。源时钟路径单元,时钟从adc0_bufg/O输出,到达PLLE4_ADV,经过BUFGCE输出,最终到达FDRE触发器,对应。

weixin_44513618的博客 1618

kali破解WIFI密码

今天我们来学习一下通过kali和一个好的字典来破解WIFI密码。 声明:此教程仅供学习研究使用,严禁使用此技术进行非法行为 首先我们需要一个具有监听功能的无线网卡(这里我给大家推荐:rt3070) 本章实验通过虚拟机VMware进行: 先通过services.msc来打开VMware USB Arbitration Service 插上监听网卡,连接USB到虚...

#的博客 5810

详记:linux服务器使用Docker部署springboot+vue项目(三:安装并远程连接MySQL8.0)

安装并远程连接MySQL8.0

chen_cm的博客 779

【CloudCompare】Windows源码编译CloudCompare

本文详细介绍了在Windows环境下编译安装CloudCompare V2.12.0的过程。首先配置了PCL 1.14.1、CMake 3.30.6和QT 5.14.2开发环境,使用Visual Studio 2022工具集。然后下载源码并通过CMake进行配置,特别注意勾选PLUGIN_STANDARD_QPCL以支持PCD文件加载。最后在VS2022中编译安装,并指出Debug模式下可能遇到的VTK库后缀问题,需添加CMAKE_DEBUG_POSTFIX变量解决。整个流程涵盖了从环境搭建到最终编译成功的

yijiujiusan的博客 485

【java多数据源连接】SpringBoot+MyBatis同一项目连接MySQL与SQLServer数据库,多数据源事务管理(三)

对于多事务管理,还有一个 Seata 分布式事务管理框架,里面包含了 AT模式、TCC模式、Saga模式、XA模式。在这里讨论一个方法中同时操作两个数据源,方法报错后两个数据源的数据是否会回滚。第三篇为使用连接多个数据库后事务管理与细节;

qq_45062700的博客 380

手把手教你学Simulink--单相逆变器模糊逻辑控制策略仿真

本文介绍了在Simulink中设计单相逆变器模糊逻辑控制策略的完整流程。主要包括:1)构建单相逆变器模型;2)使用FuzzyLogicToolbox设计模糊控制器,定义输入输出变量和模糊规则;3)将控制器集成到Simulink模型;4)添加干扰源和示波器;5)配置仿真参数并分析结果。该方法利用模糊控制处理非线性系统的优势,可实现输出电压的精确跟踪,具有良好的鲁棒性。文中提供了详细的步骤说明和示例代码,强调准确设计隶属函数和规则库对控制性能的关键作用。该仿真设计为电力电子控制系统的开发提供了有效支持。

MHD0815的博客 200

【文献阅读】使用深度语音后验改进独立于说话者的构音障碍可懂度分类

原文名称:本文探讨了利用DeepSpeech后验概率改进说话人无关的构音障碍可理解性分类方法。作者提出了一个基于DeepSpeech(一种端到端的语音转文本引擎)输出的新特征集,用于评估构音障碍患者的语音可理解性。这些新特征在说话人无关的情况下表现良好,能够更好地处理不同说话人的变异性。背景介绍:数据集:特征提取:实验设置:结果:本文提出的新特征集在说话人无关的构音障碍可理解性分类任务中表现出色,特别是在低可理解性和高可理解性类别上。未来的工作将集中在减少低可理解性和中可理解性类别之间的混淆,以进一步提高系

帅小柏的博客 452

SpringBoot中集成Mybatis配置数据库连接的若干问题

即3.0版本只支持SpringBoot3及JDK17,所以最开始创建SpringBoot工程不小心创建成了SpringBoot3版本的,在依赖选择时选择了Mybatis Framework,自动引入的是3.0.2版本的mybatis-spring-boot-starter,后续手动修改了SpringBoot版本为2.7.16,但是没有修改mybatis-spring-boot-starter的版本为2.3之前,因此运行测试就报了错。1)使用mysql-connector-j引入最新版本的驱动包。

cjkjj的博客 804

基于Matlab使用雷达资源管理有效跟踪多个机动目标仿真(附源码)

多功能雷达可以搜索目标,确认新轨道,并重新访问轨道以更新状态。为了执行这些功能,多功能雷达通常由资源管理器管理,该资源管理器创建用于搜索、确认和跟踪的雷达任务。这些任务是根据优先级和时间安排的,因此,在每个时间步长中,多功能雷达都可以将其波束指向所需的方向。在此示例中,对于用于跟踪机动目标的雷达,有两个相互冲突的要求:目标的数量及其初始位置通常事先不知道。因此,雷达必须不断搜索感兴趣的区域才能找到目标。此外,雷达需要在进入雷达覆盖区域后立即检测并建立对每个目标的跟踪。目标机动的时间段事先是未知的。

珞瑜的博客 3145

基于SpringBoot后端实现连接MySQL数据库并存贮数据

MySQL是一种流行的关系型数据库管理系统(RDBMS),它是开源的,由瑞典公司MySQL AB开发。现在MySQL是Oracle公司的一部分,但MySQL仍然作为开源项目继续开发和维护。1. 关系型数据库管理系统(RDBMS):MySQL是一种关系型数据库,数据以表格的形式存储,这些表格可以通过关系进行连接。MySQL是开源的,意味着你可以免费使用它,而且有一个庞大的开源社区支持。3. 跨平台性:MySQL支持多种操作系统,包括Linux、Windows、macOS等,可以在各种环境中部署和运行。

a910247的博客 9450

贝叶斯时空模型-INLA-4

该文章中,会简化数学计算的过程,主要是针对,在有数据的基础上,如何应用贝叶斯时空模型,找出影响因素,绘制时间变化的空间分布预测图。上述中关键一步与前几期介绍的不一样的地方是,我们加入了n.group参数,用来指定年份,先看一下Year有多少年的,然后封装在s.index里面。在前述的内容中,我们介绍了,如何处理空间的数据,利用海拔高度预测降雨量的例子。建立好数据及mesh以后,我们现在写INLA公式,如果不考虑残差项,那就是固定效应,现在我们增加残差项,及空间与时间效应。这里的Mesh设定值为10,20。

学习中 2948

tsmc12:via0的spacing问题(Via0.S.1)

12nm有个via0 grid的概念,除了普通fill外,基本都有via0这一层,这一层需要与via0 grid对齐。手动调整cell的位置比较容易出这个drc,比如修m0po max length drc时。解决方法1: 替换EEQV类型cell,这种类型是专门为了修via0 Grid问题存在的。更多学习内容请关注「拾陆楼」知识星球。解决方法2: 翻转或移动。

m0_61544122的博客 1115

SpringBoot 项目连接MySQL 数据库

一般在新建SpringBoot 项目时,勾选了的依赖无需再次导入,可以直接使用。依赖查找:https://mvnrepository.com/

我是聂可的博客 3万+

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

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

【springboot基础】项目结构mysql、neo4j连接

这些文件位于 src/main/resources 目录下,用于配置 Spring Boot 应用程序。选择其一使用即可,不需要同时使用。UserDic.java 位于 src/main/java/com/example/entity 目录下,表示 Neo4j 的一个实体类。

qq_41767061的博客 1481

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

使用IDEA创建SpringBoot+MyBatis+MySql项目连接数据库实例(绝对可行)

1、首先我们先在IDEA上创建一个SpringBoot的Web项目 (1)file ——&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt; new ——&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt; project (2)——&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt; next 这里是包路径前缀,可修改也可不修改(默认)com.example.demo (

zeng_ll的博客 4万+

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

使用docker部署springboot项目并连接上mysql数据库

使用docker部署springboot项目并连接上mysql数据库 需要的知识 Linux操作系统 docker(了解git的工作方式即可) 工具 xshell(用来连接linux服务器) xftp用来给linux服务器上传文件 sqlyog(或者navicat)在服务器上解析.sql脚本 maven(idea自带) 用来打包 接下来我们开始正式操作 服务器的选择 我选择的是阿里...

hangao233的博客 2万+

【IDEA】创建 SpringBoot 项目连接 MySQL

IntelliJ IDEA作为一款强大的Java集成开发环境(IDE),在创建和管理Spring Boot项目方面具有显著优势。

GISer help GISer 2792

项目实战第一篇:springboot集成mysql以及连接池

项目实战第一篇:springboot集成mysql,并配置数据库连接池

java进阶之路 3782

Docker部署springboot项目并连接上docker的mysql

首先:我是参考着几篇博客: 所以直接从docker hub上拉取mysql:5.7 3,运行mysql 4,查看容器是否创建成功 有个命令,可以进入容器内部,ctrl+p+q可以以后台运行的方式退出这个软件 5,使用navicat连接服务器或虚拟机上的mysql 然后可以看到数据已经传输成功: 打包成功会看到出现一个target的目录,里面的jar包就是我们刚刚打包好的 然后对yml文件进行编辑: 在idea的插件市场搜索docker,并安装 然后在根目录下新建一个Dockerfile的文件

m0_49683806的博客 8047

SpringBoot使用MyBatis连接MySQL

[!NOTE] 本教程是《SpringBoot系列基础教程》之一,教程目录:https://blog.youkuaiyun.com/laisc7301/article/details/135918617 首先按照图示新建项目: 添加以下依赖: 找到application.properties文件,并写入下面内容: server.port=8001 #设置数据库名为testdata spring.datasource.url=jdbc:mysql://127.0.0.1:3306/testdata?chara

睿虎的博客 2293

java后端_Springboot项目连接mysql数据库

springboot项目连接mysql数据库完整案例

gzmhxsn的博客 3039

docker 安装以及部署springboot项目和连接mysql

docker 安装以及部署springboot项目和连接mysql 一、安装docker 1.查看centos版本,Docker要求Centos系统的内核版本最低 3.10 # uname -r 2.若Centos的内核最低版本低于 3.10 的话需要执行更新操作,若Centos的最低版本高于 3.10就无需更新 # yum update 3.安装需要的软件包, yum-util 提供yum-.........

itboy 5907
上一篇: mysql基础(二)-数据库增、删、改、查
下一篇: mysql报错 this is incompatible with sql_mode=only_full_group_by
马鱼羊
博客等级 码龄7年 426粉丝 18原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值