如何使用mybatis连接数据库及曾删改查的操作(基于maven开发)

IDEA使用maven初次构建Mybatis项目并增删改查 IDEA使用maven初次构建Mybatis项目并增删改查一、环境说明,知识储备1、环境说明2、知识储备二、创建和配置项目1、先创建一个maven空项目2、在pom.xml中配置jar包3、创建一个数据库并进行连接3.1、创建mybatis数据库:3.2、将数据库与IDEA进行连接4、编写Mybatis核心配置文件5、编写MybatisUtils工具类6、编写User实体类7、编写UserMapp... 阅读详情

配置文件

pox.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>org.example</groupId>
    <artifactId>mybatis-demo</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>


    <dependencies>

        <!-- mybatis -->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.5.5</version>
        </dependency>
        <!-- mysql 驱动 -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.46</version>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.13</version>
            <scope>test</scope>
        </dependency>

        <!-- 添加slf4j日志api -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.20</version>
        </dependency>
        <!-- 添加logback-classic依赖 -->
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.2.3</version>
        </dependency>
        <!-- 添加logback-core依赖 -->
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-core</artifactId>
            <version>1.2.3</version>
        </dependency>

    </dependencies>

</project>

//核心配置文件

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>

    <typeAliases>
        <package name="com.mlt.pojo"/>
    </typeAliases>
    <environments default="development">
        <environment id="development">
            <transactionManager type="JDBC"/>
            <dataSource type="POOLED">
                <property name="driver" value="com.mysql.jdbc.Driver"/>
                <property name="url" value="jdbc:mysql://127.0.0.1:3306/mybatis?useSSL=false"/>
                <property name="username" value="root"/>
                <property name="password" value="1234"/>
            </dataSource>
        </environment>
    </environments>
    <mappers>
        <package name= "com.mlt.mapper"/>
    </mappers>
</configuration>

//Mapper 配置文件(注意要和Brandmapper接口在同一目录下)

<?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.mlt.mapper.BrandMapper">

<!--数据库字段名称,和实体类的属性名称不一样,则不能自动封装-->
<!--    <select id="selectAll" resultType="brand">-->
<!--    select *from tb_brand;-->
<!--    </select>-->

<!--  resultMap  -->
    <resultMap id="brandresultMap" type="brand">
        <result column="brand_name" property="brandName"/>
        <result column="company_name" property="companyName"/>
    </resultMap>



    <!-- sql片段-->
<!--    <sql id="brand_column">-->
<!--        id ,brand_name as brandName,company_name as companyName,ordered,description,status-->
<!--    </sql>-->
    <select id="selectAll" resultMap="brandresultMap">
        select
          *
            from tb_brand;
    </select>
    <select id="selectByid" resultMap="brandresultMap">
        select * from tb_brand where CD id=#{id};
    </select>

<!--条件查询!-->

<!--    <select id="selectByCondition" resultMap="brandresultMap">-->
<!--        select *-->
<!--        from tb_brand-->
<!--        where status = #{status}-->
<!--          and company_name like #{companyName}-->
<!--          and brand_name like #{brandName}-->
<!--    </select>-->

<!--动态条件查询
if 条件判断
test 逻辑表达式
*恒等式
*where 替换where
-->
    <select id="selectByCondition" resultMap="brandresultMap">
        select *
        from tb_brand
--         where 2=2
        <where>
        <if test="status !=null">
         and  status = #{status}
        </if>
        <if test="companyName !=null and companyName !=''">
          and company_name like #{companyName}
        </if>
        <if test="brandName !=null and brandName !=''">
          and brand_name like #{brandName}
        </if>
        </where>
    </select>
    <select id="selectByConditionSingle"  resultMap="brandresultMap">
        select * from tb_brand
        <where>
            <choose>  <!-- 相当于switch-->
                <when test="status !=null"><!-- case-->
                    status = #{status}
                </when>
                <when test="companyName !=null and companyName !=''"><!-- case-->
                    company_name like #{companyName}
                </when>
                <when test="brandName !=null and brandName !=''"><!-- case-->
                     brand_name like #{brandName}
                </when>
            </choose>
        </where>
    </select>


<!--添加-->


    <insert id="add" useGeneratedKeys="true" keyProperty="id">
        insert into tb_brand (brand_name, company_name, ordered, description, status)
        values (#{brandName}, #{companyName}, #{ordered}, #{description}, #{status});
    </insert>
<!--    修改-->
    <update id="update">
        update tb_brand
        <set>
            <if test="brandName !=null and brandName !=''">
            brand_name=#{brandName},
            </if>
        <if test="companyName !=null and companyName !=''">
            company_name=#{companyName},
        </if>
        <if test="ordered !=null ">
            ordered=#{ordered},
        </if>
        <if test="description !=null and description !=''">
            description=#{description},
        </if>
        <if test="status !=null">
            status=#{status}
        </if>
        </set>
            where id=#{id};
    </update>

<!--    删除-->

    <delete id="delete">
        delete from  tb_brand where id=#{id}
    </delete>
<!--    批量删除
    *array=数组
    * 使用注解
-->
    <delete id="deleteBylds">
        delete from  tb_brand where id
        in
         <foreach collection="array" item="id" separator="," open="(" close=")">
                #{id}
            </foreach>
    </delete>
</mapper>

//brand类

package com.mlt.pojo;

/**
 * 品牌
 *
 * alt + 鼠标左键:整列编辑
 *
 * 在实体类中,基本数据类型建议使用其对应的包装类型
 */

public class Brand {
    // id 主键
    private Integer id;
    // 品牌名称
    private String brandName;
    // 企业名称
    private String companyName;
    // 排序字段
    private Integer ordered;
    // 描述信息
    private String description;
    // 状态:0:禁用  1:启用
    private Integer status;


    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getBrandName() {
        return brandName;
    }

    public void setBrandName(String brandName) {
        this.brandName = brandName;
    }

    public String getCompanyName() {
        return companyName;
    }

    public void setCompanyName(String companyName) {
        this.companyName = companyName;
    }

    public Integer getOrdered() {
        return ordered;
    }

    public void setOrdered(Integer ordered) {
        this.ordered = ordered;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    @Override
    public String toString() {
        return "Brand{" +
                "id=" + id +
                ", brandName='" + brandName + '\'' +
                ", companyName='" + companyName + '\'' +
                ", ordered=" + ordered +
                ", description='" + description + '\'' +
                ", status=" + status +
                '}';
    }
}

//BrandMapper代理的接口(以后实现方法,利于扩展)

package com.mlt.mapper;

import com.mlt.pojo.Brand;
import org.apache.ibatis.annotations.Param;


import java.util.List;
import java.util.Map;


public interface BrandMapper {

    List<Brand> selectAll();
    /**
     * 查询
     */
    Brand selectByid(int id);

    /**
     * 条件查询
     * 1.散装参数:如果方法有多个参数,需要使用@param包装
     * @param status
     * @param companyName
     * @param brandName
     * @return
     */
    List<Brand> selectByCondition(@Param("status") int status,
                                  @Param("companyName") String companyName,
                                  @Param("brandName") String brandName);


    List<Brand> selectByCondition(Brand brand);

    List<Brand> selectByCondition(Map map);

    List<Brand> selectByConditionSingle(Brand brand);


    /**
     * 添加
     *
     */
    void add(Brand brand);
    /**
     *
     * 修改
     */
    int update(Brand brand);
    /**
     * 删除
     */
    int delete(int id);

    /**
     * 批量删除
     */
    void deleteBylds( int[] ids);
}

//测试代码()

package com.mlt.test;

import com.mlt.mapper.BrandMapper;
import com.mlt.pojo.Brand;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MyBatisTest {


    @Test
    public void testSelectAll() throws IOException {
        //1.获取sqlSessionFactory

        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession sqlSession =sqlSessionFactory.openSession();

        //2.获取mapper接口代理对象
        BrandMapper mapper = sqlSession.getMapper(BrandMapper.class);

        List<Brand> barns = mapper.selectAll();

        System.out.println(barns);

        //3.关闭

        sqlSession.close();
    }



    @Test
    public void testSelect() throws IOException {
        //1.获取sqlSessionFactory
        int id =1;
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession sqlSession =sqlSessionFactory.openSession();

        //2.获取mapper接口代理对象
        BrandMapper mapper = sqlSession.getMapper(BrandMapper.class);

        Brand brand = mapper.selectByid(id);
        System.out.println(brand);

        //3.关闭

        sqlSession.close();
    }


    @Test
    public void testSelectByCondition() throws IOException {
        //1.获取sqlSessionFactory
      //  int status=1;
        String companyName = "华为";
    //    String brandName = "华为";

        //处理参数

        companyName = "%"+companyName+"%";
     //   brandName = "%"+brandName+"%";

        Map<String,Object> map =new HashMap<>();
     //   map.put("status",status);
        map.put("companyName",companyName);
   //     map.put("brandName",brandName);
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession sqlSession =sqlSessionFactory.openSession();

        //2.获取mapper接口代理对象
        BrandMapper mapper = sqlSession.getMapper(BrandMapper.class);

        List<Brand> brands = mapper.selectByCondition(map);
        System.out.println(brands);

        //3.关闭

        sqlSession.close();
    }



    @Test
    public void testSelectByConditionSinggo() throws IOException {
        //1.获取sqlSessionFactory
        int status=1;
        String companyName = "华为";
         String brandName = "华为";

        //处理参数

        companyName = "%"+companyName+"%";
       brandName = "%"+brandName+"%";

        Brand brand = new Brand();
       // brand.setStatus(status);
      //  brand.setCompanyName(companyName);
      //  brand.setBrandName(brandName);
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession sqlSession =sqlSessionFactory.openSession();

        //2.获取mapper接口代理对象
        BrandMapper mapper = sqlSession.getMapper(BrandMapper.class);

        List<Brand> brands = mapper.selectByConditionSingle(brand);
        System.out.println(brands);

        //3.关闭

        sqlSession.close();
    }

    /**
     * 添加数据
     *
     */
    @Test
    public void testAdd() throws IOException {
        //1.获取sqlSessionFactory
        int status=1;
        String companyName = "华为shouji";
        String brandName = "华为";
        String description="手机中的战斗机";
        int ordered=100;

        Brand brand = new Brand();
         brand.setStatus(status);
          brand.setCompanyName(companyName);
          brand.setBrandName(brandName);
          brand.setDescription(description);
          brand.setOrdered(ordered);
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession sqlSession =sqlSessionFactory.openSession(true);

        //2.获取mapper接口代理对象
        BrandMapper mapper = sqlSession.getMapper(BrandMapper.class);

         mapper.add(brand);

        //提交事务
        sqlSession.commit();
               //3.关闭

        sqlSession.close();
    }

    @Test
    public void testAdd2() throws IOException {
        //1.获取sqlSessionFactory
        int status=1;
        String companyName = "华为shouji";
        String brandName = "华为";
        String description="手机中的战斗机";
        int ordered=100;

        Brand brand = new Brand();
        brand.setStatus(status);
        brand.setCompanyName(companyName);
        brand.setBrandName(brandName);
        brand.setDescription(description);
        brand.setOrdered(ordered);
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession sqlSession =sqlSessionFactory.openSession(true);

        //2.获取mapper接口代理对象
        BrandMapper mapper = sqlSession.getMapper(BrandMapper.class);

        mapper.add(brand);

        //提交事务
        sqlSession.commit();
        //3.关闭
        System.out.println(brand.getId());
        sqlSession.close();
    }

    /**
     * 修改
     * @throws IOException
     */
    @Test
    public void testUpdate() throws IOException {
        //1.获取sqlSessionFactory
        int status=1;
        String companyName = "sadadsa";
        String brandName = "华dasdasdasdada为";
        String description="手dsadasdasda机中的战斗机";
        int ordered=100;
        int id =8;

        Brand brand = new Brand();
        brand.setStatus(status);
        brand.setCompanyName(companyName);
        brand.setBrandName(brandName);
        brand.setDescription(description);
        brand.setOrdered(ordered);
        brand.setId(id);
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession sqlSession =sqlSessionFactory.openSession(true);

        //2.获取mapper接口代理对象
        BrandMapper mapper = sqlSession.getMapper(BrandMapper.class);

        int update = mapper.update(brand);
        System.out.println(update);
        //提交事务
        sqlSession.commit();
        //3.关闭
        System.out.println(brand.getId());
        sqlSession.close();
    }

    /**
     * 修改
     * @throws IOException
     */
    @Test
    public void testUpdate2() throws IOException {
        //1.获取sqlSessionFactory
        int status=0;
        String companyName = "sadadsa";
        String brandName = "华dasdasdasdada为";
        String description="手dsadasdasda机中的战斗机";
        int ordered=10000000;
        int id =6;

        Brand brand = new Brand();
  //     brand.setStatus(status);
//        brand.setCompanyName(companyName);
//        brand.setBrandName(brandName);
        brand.setDescription(description);
  //      brand.setOrdered(ordered);
        brand.setId(id);
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession sqlSession =sqlSessionFactory.openSession(true);

        //2.获取mapper接口代理对象
        BrandMapper mapper = sqlSession.getMapper(BrandMapper.class);

        int update = mapper.update(brand);
        System.out.println(update);
        //提交事务
        sqlSession.commit();
        //3.关闭
        System.out.println(brand.getId());
        sqlSession.close();
    }


    /**
     * 根据id删除
     * @throws IOException
     */
    @Test
    public void testdeleteByid() throws IOException {


        int id =6;


        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession sqlSession =sqlSessionFactory.openSession(true);

        //2.获取mapper接口代理对象
        BrandMapper mapper = sqlSession.getMapper(BrandMapper.class);

        int update = mapper.delete(id);
        System.out.println(update);
        //提交事务
        sqlSession.commit();
        //3.关闭

        sqlSession.close();
    }


    /**
     * 删除
     * @throws IOException
     */
    @Test
    public void testdeleteByids() throws IOException {


        int[] ids ={5,6,7,8};


        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession sqlSession =sqlSessionFactory.openSession(true);

        //2.获取mapper接口代理对象
        BrandMapper mapper = sqlSession.getMapper(BrandMapper.class);

        mapper.deleteBylds(ids);

        //提交事务
        sqlSession.commit();
        //3.关闭

        sqlSession.close();
    }
}
idea 环境下 mybatis连接数据库实现增删改查 第一步搭建maven环境 第二步填写包名 第三步在新建的项目中找到pom.xml文件 添加mybatismysql还有junit(单元测试)的依赖 依赖代码(此处注意一些遇到的异常处理,看备注) <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/X... 阅读详情

相关推荐

idea使用springBoot + mybatis +maven实现注册登录和简单增删改查(crud)

idea使用springBoot + mybatis +maven实现注册登录和简单增删改查(crud) 完成后的项目目录如下(所有文件都可拷贝) (一)第一部分(创建项目) 1、File——>New——>Project——>Spring Initializr——>Next——jdk版本选择和刚才项目SDK版本一致的,我这里是1.8,其他的项目名称可不做修改。修改完点finish即可 2、继续Next,这里选择需要用的就可以,这里选择了Web下的SpingWeb 和SQL里面的两

菜的睡不着 4012

mybatis(一)连接数据库操作

使用Mybatis直接链接数据库操作数据 1. 建立对应表的用户实体类(普通的java bean)User.java 2. 定义DAO接口(也就是Mapper映射接口),与数据库交互作用:UserMapper.java 3.创建统一写sql语句的XML文件与DAO接口(也就是Mapper映射接口)对应,路径报名要一致,XML文件与数据层接口类的名称一致,UserMapper.xml 4. 建立Mybatis核心配置文件mybatis-config.xml,在resources文件包下。配置文件中定义了数据

u011529483的博客 1万+

ccproxy 6.61 注册机(纯绿/傻瓜/真正去除线程限制)

导读:   软件介绍   1、 CCPROXY 6.61 注册机(纯绿/傻瓜/真正去除线程限制)   ***前言,这次的升级官方改动不大,据说只是为了不被某些软件当病毒***   附件包中解压即免安装版,CcREGTOOLFF.exe为注册机。   本人继续向大家隆重推出《CCPROXY6.61哎呀……破解版》   还是那个提示:   在此之前,本人还是那句老话想提示大家,CCPROXY是

i53nd的专栏 1万+

Mybatsi连接数据库

⑤编写映射文件UserMapper.xml 和 UserMapper接口。④编写核心文件MyBatisConfig.xml。3 创建mapper接口和对应的xml文件。3.创建mapper接口和对应的文件。①添加MyBatis的maven包。4.编写mybatis的配置文件。4 Service接口类和实现类。7 mybatis的配置文件。6 spring配置文件。1 导入maven依赖。6.写spring文件。②创建user数据表。③编写User实体类。2 创建账户的实体类。5 数据库的配置文件。

m0_64756308的博客 244

树莓派c语言串口通讯程序

在网上搜了很多关于树莓派串口通讯的例子,但是都是用python写的,虽然python很有名,而且最近也在学习这门语言, 但是还是想用c语言实现一下,因为需要用到整套系统里,其他内容都是用c语言写的。但是网上没有找打现成的。 还好,之前做过天嵌2440开发板的串口程序(参照天嵌工程师提供的代码),发现串口程序其实是通用的, 驱动层屏蔽了硬件细节,个人猜测,几乎所有移植好的系统的串口,都可以用一

realank的专栏 1万+

告别玄学调参:手把手教你用20元件模型搞定GaN HEMT高频仿真(附S参数提取避坑指南)

本文详细介绍了如何使用20元件模型优化GaN HEMT高频仿真,解决传统16元件模型在10GHz以上频段的误差问题。通过S参数提取避坑指南和实战案例,帮助工程师精准建模分布式电极效应和寄生反馈路径,提升射频电路设计效率。

weixin_42523693的博客 443

使用Mybatis 连接数据库 项目示例

【代码】使用Mybatis 连接数据库 项目示例。

2401_82686243的博客 407

STM32F103C8T6键盘DIY全攻略:从电路设计到固件烧录(附避坑指南)

本文详细介绍了基于STM32F103C8T6微控制器的DIY键盘制作全流程,涵盖硬件电路设计、按键矩阵实现、USB HID通信及固件烧录等关键步骤。特别针对常见问题提供避坑指南,帮助开发者高效完成从电路设计到功能实现的完整过程,打造个性化瀚文键盘。

soda5的博客 770

IDEA使用Maven和MyBatis简化数据库连接(配置篇)

Maven和MyBatis协同开发指南

2501_90864902的博客 1895

【OCCT】第3讲 OpenCasCade&VTK实现三维建模Demo

本文分享OpenCasCade&VTK共同实现三维建模Demo,希望对各位小伙伴有所帮助!1. 新建Visual Studio工程新建空项目添加main.cpp添加main函数2. 配置OpenCasCade & VTK 库配置包含路径:配置库文件:添加链接库:添加运行环境:注意:VTK库的版本要与编译OpenCasCade库时选择的版本一致,否则会出错!

qq_40041064的博客 782

lammps后处理:ovito选择原子高级技巧讲解

大家好,我是小马老师。 本文介绍如何在ovito中使用公式(Expression)选择需要的原子。 用ovito查看lammps模拟结果时,可能会遇到选择特定原子的情况,比如选择坐标位于一定范围内的原子,或者选择结构为fcc的原子等等。 这时候,就需要用到expression selection功能。 Expression selection功能比较强大,下面分别介绍几种选择原子的方法。 在输入公式前,先点击“Add modification”->"Expression selection"选项,在B

lammps_jiayou的博客 2万+

如何使用mybatis连接数据库?详细解析

实现mybatis连接数据库的步骤: 1.建表 2.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 htt

欢迎来到我的博客 1万+

YOLOv11改进缝合FasterBlock | 一种新型轻量化卷积结构C3k2的设计与实证:兼顾精度与速度的改进方法(附代码)

YOLO系列一直是目标检测领域的明星算法,凭借其实时性和准确性在众多应用中占据一席之地。随着YOLO版本的不断迭代,网络架构逐渐变得更为复杂,尤其是在卷积模块的设计上。本文将介绍如何利用FasterNet的FasterBlock创新,并通过二次创新C3k2提出一种全新的卷积结构。该结构旨在提高YOLOv11的计算效率和准确性,特别是在视觉任务中的表现。我们的创新在保证高精度的前提下,有效降低了计算量和内存需求,特别适合在资源受限的设备上运行。

一键难忘的博客 908

Eclipse:基于Maven-Mybatis实现对数据库的增删改查操作

Eclipse:基于Maven-Mybatis实现对数据库的增删改查操作 一、项目描述 使用eclipse配置maven项目,并使用JDBC和Mybatis对学生选课数据库三张表:student、course、xueke做增删改查操作。 1.对student表的操作: 2.对course表的操作: 3.对xunake表的操作: 二、项目架构 1.,项目 2.数据库(使用MySql) 三、相关配置 1.Maven配置 1.下载Maven 官网下载 解压得到apache-maven-3.8.5-

qq_50684015的博客 1937

运放+MOS恒流源电路仿真分析

利用运放设计一个恒流源

HW-BASE的博客 4101

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

Mybatis对数据库数据进行增删改查

gannimeiwent的博客 1798

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

IDEA使用Mybatis进行连接Mysql并执行增删改查(CRUD)操作

一步步完成mybatis的CRUD小项目的搭建以及测试,对初学mybatis很有帮助

weder的博客 4652

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

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

Maven+Mybatis的基本使用

  Maven:            是一个项目管理工具,负责管理项目开发过程中的几乎所有东西,主要用于项目构建,依赖管理,项目信息管理,Maven为开发者提供了一套完整的构建生命周期框架,开发团队几乎不用花多少时间就能够自动完成工程的基础构建配置,因为Maven使用了一个标准的目录结构和一个默认的构建生命周期,在有多个开发团队环境的情况下,Maven能够在很短的时间内使得每项工作都按照标准...

CodeChen 1万+

MyBatis框架操作数据库增删改查基本操作

MyBatis框架操作数据库增删改查基本操作 需要配置一些xml等等,可以去MyBatis中文站点查看引导文档,复制下来修改部门内容即可使用 如有探讨请点击这里与我交流(^U^)ノ~YO 一、准备工作 1、创建maven项目后引入maven依赖 &lt;dependencies&gt; &lt;dependency&gt; &lt;groupId&gt;o...

Jamson 2240

IDEA配置MyBatis实现数据库增删改查

您的支持是我持续创作的动力,也欢迎留言交流,让我们一起探讨技术,共同成长!🚀✨”

saber的博客 2454

告别繁琐的数据库操作,MyBatis带你领略一键增删改查的魅力!

在这个数字化时代,数据库已经成为了企业的核心资产之一。然而,繁琐的数据库操作却让许多开发者望而却步。MyBatis作为一款优秀的持久层框架,以其简洁的XML配置、强大的映射功能和高效的执行速度,让一键增删改查变得触手可及。这不仅大大提高了开发效率,还让开发者能够更加专注于业务逻辑的实现。让我们一起期待MyBatis为我们带来的便捷与魅力吧!

万维网连五洲,二进制写尽天下事,喜欢结识新伙伴寻找志同道合的朋友,欢迎一起探讨学习 2646

mybatis连接数据库实现增删改查,使用maven

第一步最基础的创建一个数据库,创建一个用户表 五个属性:编号 名称 生日 性别 地址 创建数据库的代码 CREATE TABLE `user` ( `id` int(11) NOT NULL AUTO_INCREMENT, `username` varchar(32) NOT NULL COMMENT '用户名称', `birthday` date DEFAULT NULL...

nongxi6701的博客 491

用idea开发springboot+mybatis后端:连接以openGauss为数据库并操作的方法

本文介绍了在SpringBoot项目中集成MyBatis并连接openGauss数据库的方法。首先需在pom.xml中添加openGauss-JDBC驱动和MyBatis依赖,配置application.yml中的数据库连接信息。针对openGauss的安全限制,需使用超级用户授权普通用户权限。文章详细演示了在IDEA中通过数据库控制台执行建表、插入和查询操作,特别指出openGauss使用PostgreSQL驱动,并提供兼容的建表语法。最后强调非SSL连接的安全提示,并附上相关文档参考。

Love_ou的博客 1489

MyBatis如何连接Mysql数据库

MyBatis 如何连接Mysql数据库什么是MyBatis     MyBatis是apache的一个开源(公开的源代码)项目iBatis。iBATIS一词来源于“internet(互联网)”和“abatis(有刺铁丝网)”的组合,后来被谷歌改成Mybatis。它是一个基于Java的持久层框架。Mybatis需要什么配置什么东西?    首先了解MyBatis作用是什么?MyBatis是支持MS...

G_P918P_G的博客 9445

IDEA创建Maven工程使用Mybatis框架,对单表进行简单的增删改查的操作

搭建环境 搭建数据库表 使用的是MySQL数据库。新建名为task的数据库,在task数据库中新建名为student的表。在表中适当添加数据。创建表的SQL语句如下所示。 SET FOREIGN_KEY_CHECKS=0; --创建表 DROP TABLE IF EXISTS `student`; CREATE TABLE `student` ( `sid` varchar(40) NOT NULL DEFAULT '' COMMENT 'UUID,唯一标识', `i

kid_0_kid的博客 891

在Idea中创建maven工程,搭建mybatis框架并完成数据库表的增删改查操作

1.创建maven工程 (1)首先打开idea点击idea中的File->New->Project... (2)在左侧找到Maven如图所示: 然后点击Next 在配置好工程名后点击Next 然后确认工程路径点击Finish创建。 (3)创建一个数据库和表结构如下: 我的库名是190506,表名是users 在添加几条记录: 2.搭建mybatis框架 之后导入mysql的jar包 在创建包与类结构如下: 在Users类中编...

weixin_46102505的博客 2706
上一篇: 实现服务端与浏览器的通信
下一篇: Java异常概述及分类
有你是我的福气Love
博客等级 码龄4年 40粉丝 35原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值