Mybatis工程升级到FlunetMybatis后引发的问题以及解决方法

news2025/7/14 18:39:49

0. 背景交代

为了提高开发速度,我打算将公司原有`Mybatis`框架升级为`FlunetMybatis`。可是遇到了一系列问题,下面开始爬坑

工程结构示意如下:

src/
├── main
│   ├── java.com.demo
│   │      ├── Application.java                          //SpringBoot启动类
│   │      ├── aop
│   │      │   └── GlobalExceptionHandler.java     //全局异常处理
│   │      ├── config
│   │      │   └── FluentMybatisGenerator.java     //FluentMybatis配置类
│   │      ├── controler
│   │      │   ├── CommodityController.java        //新功能,使用FluentMybatis
│   │      │   └── FeedbackController.java         //老功能,使用Mybatis
│   │      ├── enums
│   │      ├── mapper
│   │      │   └── FeedbackMapper.java             //MybatisMapper
│   │      ├── mybatis                         //Mybatis拓展
│   │      │   ├── enums                           //枚举类
│   │      │   ├── fluent                          //FluentMybatis代码生成目录
│   │      │   │   ├── dao
│   │      │   │   │   ├── impl
│   │      │   │   │   │   └── CommodityDaoImpl.java //FluentMybatis生成的DAO实现
│   │      │   │   │   └── intf
│   │      │   │   │       └── CommodityDao.java     //FluentMybatis生成的DAO接口
│   │      │   │   └── entity
│   │      │   │       └── CommodityEntity.java  //FluentMybatis生成的数据模型
│   │      │   ├── handler
│   │      │   │   └── StringListHandler.java    //自定义类型转换器(VARCHAR <==> 字符串列表)
│   │      │   └── module
│   │      │       └── StringList.java           //字符串列表
│   │      ├── plugins
│   │      │   ├── files
│   │      │   └── render
│   │      ├── pojo
│   │      │   └── Feedback.java                 //MyBatis数据模型
│   │      ├── service
│   │      │   ├── CommodityService.java         //新功能Service接口
│   │      │   ├── FeedbackService.java          //老功能Service接口
│   │      │   └── impl
│   │      │        ├── CommodityServiceImpl.java    //新功能Service接口实现
│   │      │        └── FeedbackServiceImpl.java     //老功能Service接口实现
│   │      ├── shiro
│   │      └── utils
│   └── resources
│       ├── application-dev.yml
│       ├── application-prod.yml
│       ├── application.yml
│       ├── logback.xml
│       └── mybatis
│           ├── mapper
│           │   └── FeedbackMapper.xml                //Mybatis Mapper XML文件
│           └── mybatis-config.xml
└── test
    └── java

主要涉及到的配置文件FluentMybatisGenerator内容:

package com.demo.config;

import cn.org.atool.fluent.mybatis.spring.MapperFactory;
import cn.org.atool.generator.FileGenerator;
import cn.org.atool.generator.annotation.Column;
import cn.org.atool.generator.annotation.Table;
import cn.org.atool.generator.annotation.Tables;
import com.demo.mybatis.handler.StringListHandler;
import com.demo.mybatis.module.StringList;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;

import javax.annotation.Resource;
import javax.sql.DataSource;

/**
 * FluentMybatisConfigurer
 *
 * @author adinlead
 * @desc
 * @create 2023/3/6 13:34 (星期一)
 */
@Configuration
@MapperScan({"com.demo.mapper"})
public class FluentMybatisGenerator {
    /**
     * 定义fluent mybatis的MapperFactory
     */
    @Bean
    public MapperFactory mapperFactory() {
        return new MapperFactory();
    }

    /**
     * 生成代码类
     */
    @Tables(
            srcDir = "src/main/java",
            basePack = "com.demo.mybatis.fluent", //注意,此处生成代码的路径与原生Mybatis不在同一个包下
            daoDir = "src/main/java",
            tablePrefix = {"tb_"},
            tables = {@Table(value = {"tb_commodity"}, columns = {
                    @Column(value = "create_time", insert = "now()"),
                    @Column(value = "update_time", insert = "now()", update = "now()"),
                    @Column(value = "cover_images", javaType = StringList.class, typeHandler = StringListHandler.class)
            })})
    static class CodeGenerator {
    }
}
  1. 问题以及解决

1.1 FluentMybatis无法自动生成实体类

现象:在运行后,没有在com.demo.mybatis.fluent中生成entity和dao

解决方法:

在FluentMybatisGenerator.java中,在返回自定义fluent mybatis的MapperFactory之前,执行FileGenerator.build方法:

    @Resource
    private DataSource dataSource;

    /**
     * 定义fluent mybatis的MapperFactory
     */
    @Bean
    public MapperFactory mapperFactory() {
        FileGenerator.build(dataSource, CodeGenerator.class);
        // 引用配置类,build方法允许有多个配置类
        return new MapperFactory();
    }

mvn执行clean 后 再次运行项目即可

效果如下

1.2 自定义SqlSessionFactoryBean导致的一系列问题

官方WIKI-环境部署-简单示例中看到了如下代码:

@Configuration
@MapperScan({"你的Mapper package"})
public class ApplicationConfig {
    @Bean("dataSource")
    @Bean
    public DataSource newDataSource() {
        // TODO
    }

    @Bean
    public SqlSessionFactoryBean sqlSessionFactoryBean() throws Exception {
        SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
        bean.setDataSource(newDataSource());
        ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
        // 以下部分根据自己的实际情况配置
        // 如果有mybatis原生文件, 请在这里加载
        bean.setMapperLocations(resolver.getResources("classpath*:mapper/*.xml"));
        org.apache.ibatis.session.Configuration configuration = new org.apache.ibatis.session.Configuration();
        configuration.setLazyLoadingEnabled(true);
        configuration.setMapUnderscoreToCamelCase(true);
        bean.setConfiguration(configuration);
        return bean;
    }

    // 定义fluent mybatis的MapperFactory
    @Bean
    public MapperFactory mapperFactory() {
        return new MapperFactory();
    }
}

在此示例中,作者重定义了SqlSessionFactoryBean,但是如果你没能正确配置,那么这一行为也会导致一系列错误。

1.2.1 Spring无法找到需要注入的对象

错误如下:


Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2023-03-08 13:17:02 [main] ERROR o.s.b.d.LoggingFailureAnalysisReporter - 

***************************
APPLICATION FAILED TO START
***************************

Description:

A component required a bean of type 'com.demo.mybatis.fluent.mapper.CommodityMapper' that could not be found.


Action:

Consider defining a bean of type 'com.demo.mybatis.fluent.mapper.CommodityMapper' in your configuration.

这个一般是Spring 进行DI时,找不到FluentMybatis的Mapper引起的错误,原因在于官方文档中要求你在@MapperScan中添加MybatisMapper包路径,但是如果你的MybatisMapper和FluentMybatisMapper不在一个包中时,也需要把FluentMybatis生成的Mapper路径也添加到扫描器中,或者干脆放大扫描范围。

  1. 添加FluentMybatisMapper包路径(推荐)

@Configuration
@MapperScan({"com.demo.mapper", "com.demo.mybatis.fluent.mapper"})
public class FluentMybatisGenerator {
    ...
}
  1. 扩大扫描范围

@Configuration
@MapperScan({"com.demo"})
public class FluentMybatisGenerator {
    ...
}

1.2.2 原MybatisMapper报BindingException错误

调用原生MybatisMapper中的方法时,提示无法映射到方法,错误信息如下:

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.demo.mapper.FeedbackMapper.countManagerRecords
    at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:235)
    at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:53)
    at org.apache.ibatis.binding.MapperProxy.lambda$cachedInvoker$0(MapperProxy.java:115)
    at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660)
    at org.apache.ibatis.binding.MapperProxy.cachedInvoker(MapperProxy.java:102)
    at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:85)
    at com.sun.proxy.$Proxy93.countManagerRecords(Unknown Source)
    at com.demo.service.impl.FeedbackServiceImpl.getManagerFeedbacks(FeedbackServiceImpl.java:77)
    at com.demo.controler.FeedbackController.getAdminRecords(FeedbackController.java:74)
    at com.demo.controler.FeedbackController$$FastClassBySpringCGLIB$$80abedc3.invoke(<generated>)

这个错误一般是由于你没有正确配置MyBatis XML文件路径导致的,需要在自定义SqlSessionFactoryBean方法中修改XML文件扫描路径:

    @Bean
    public SqlSessionFactoryBean sqlSessionFactoryBean() throws Exception {
        SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
        bean.setDataSource(dataSource);
        ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
        /* 注意!在这里需要将原生Mybatis的XML路径写到配置中 */
        bean.setMapperLocations(resolver.getResources("classpath*:mybatis/mapper/*.xml"));
        org.apache.ibatis.session.Configuration configuration = new org.apache.ibatis.session.Configuration();
        configuration.setLazyLoadingEnabled(true);
        configuration.setMapUnderscoreToCamelCase(true);
        bean.setConfiguration(configuration);
        return bean;
    }

1.2.3 Mybatis别名解析错误

在修改完1.2.2问题后,你大概率会碰到这个问题,具体表现为:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'shiroFilter' defined in class path resource [com/demo/shiro/ShiroConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.shiro.spring.web.ShiroFilterFactoryBean]: Factory method 'shiroFilterFactoryBean' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'securityManager' defined in class path resource [com/demo/shiro/ShiroConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.shiro.web.mgt.DefaultWebSecurityManager]: Factory method 'securityManager' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'shiroRealm': Unsatisfied dependency expressed through field 'userService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userMapper' defined in file [xxxx/DemoProject/target/classes/com/demo/mapper/UserMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactoryBean' defined in class path resource [com/demo/config/FluentMybatisGenerator.class]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [xxxx/DemoProject/target/classes/mybatis/mapper/FeedbackMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'file [xxxx/DemoProject/target/classes/mybatis/mapper/FeedbackMapper.xml]'. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'Feedback'.  Cause: java.lang.ClassNotFoundException: Cannot find class: Feedback
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:486)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:213)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:270)
    at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:762)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:567)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:338)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1332)
    at com.demo.Application.main(NewCommunity.java:27)

根本原因在MyBatis中:

Caused by: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'file [xxxx/DemoProject/target/classes/mybatis/mapper/FeedbackMapper.xml]'. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'Feedback'.  Cause: java.lang.ClassNotFoundException: Cannot find class: Feedback
    at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java:123)
    at org.apache.ibatis.builder.xml.XMLMapperBuilder.parse(XMLMapperBuilder.java:95)
    at org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory(SqlSessionFactoryBean.java:611)
    ... 92 common frames omitted
Caused by: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'Feedback'.  Cause: java.lang.ClassNotFoundException: Cannot find class: Feedback
    at org.apache.ibatis.builder.BaseBuilder.resolveClass(BaseBuilder.java:118)
    at org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElement(XMLMapperBuilder.java:263)
    at org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElement(XMLMapperBuilder.java:254)
    at org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElements(XMLMapperBuilder.java:246)
    at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java:119)
    ... 94 common frames omitted
Caused by: org.apache.ibatis.type.TypeException: Could not resolve type alias 'Feedback'.  Cause: java.lang.ClassNotFoundException: Cannot find class: Feedback
    at org.apache.ibatis.type.TypeAliasRegistry.resolveAlias(TypeAliasRegistry.java:120)
    at org.apache.ibatis.builder.BaseBuilder.resolveAlias(BaseBuilder.java:149)
    at org.apache.ibatis.builder.BaseBuilder.resolveClass(BaseBuilder.java:116)
    ... 98 common frames omitted
Caused by: java.lang.ClassNotFoundException: Cannot find class: Feedback
    at org.apache.ibatis.io.ClassLoaderWrapper.classForName(ClassLoaderWrapper.java:196)
    at org.apache.ibatis.io.ClassLoaderWrapper.classForName(ClassLoaderWrapper.java:89)
    at org.apache.ibatis.io.Resources.classForName(Resources.java:261)
    at org.apache.ibatis.type.TypeAliasRegistry.resolveAlias(TypeAliasRegistry.java:116)
    ... 100 common frames omitted

据我猜测,其原因在于FluentMybatis没有夹在原生Mybatis的实体类,解决方法很简单,在自定义SqlSessionFactoryBean的方法中,手动添加原生MyBatis实体类所在包即可:

    @Bean
    public SqlSessionFactoryBean sqlSessionFactoryBean() throws Exception {
        SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
        bean.setDataSource(dataSource);
        ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
        /* 注意!在这里需要将原生Mybatis的XML路径写到配置中 */
        bean.setMapperLocations(resolver.getResources("classpath*:mybatis/mapper/*.xml"));
        org.apache.ibatis.session.Configuration configuration = new org.apache.ibatis.session.Configuration();
        configuration.setLazyLoadingEnabled(true);
        configuration.setMapUnderscoreToCamelCase(true);
        /* 注意!在这里需要将原生MyBatis的实体类包名添加到TypeAliasRegistry中 */
        configuration.getTypeAliasRegistry().registerAliases("com.demo.pojo");
        bean.setConfiguration(configuration);
        return bean;
    }

1.2.0 一割解千愁

经过测试,其实不需要自定义SqlSessionFactoryBean也可以正常的将原生MyBatis和FluentMybatis二者结合使用,所以如果上面的方法不能解决问题时,可以尝试将自定义SqlSessionFactoryBean方法删除后再试。

3. 完整的FluentMybatisGenerator.java:

package com.demo.config;

import cn.org.atool.fluent.mybatis.spring.MapperFactory;
import cn.org.atool.generator.FileGenerator;
import cn.org.atool.generator.annotation.Column;
import cn.org.atool.generator.annotation.Table;
import cn.org.atool.generator.annotation.Tables;
import com.demo.mybatis.handler.StringListHandler;
import com.demo.mybatis.module.StringList;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;

import javax.annotation.Resource;
import javax.sql.DataSource;

/**
 * FluentMybatisConfigurer
 *
 * @author adinlead
 * @desc
 * @create 2023/3/6 13:34 (星期一)
 */
@Configuration
public class FluentMybatisGenerator {
    /**
     * 从Spring中获取DataSource
     */
    @Resource
    private DataSource dataSource;


    /**
     * 使用定义Fluent Mybatis的MapperFactory
     */
    @Bean
    public MapperFactory mapperFactory() {
        /* 引用配置类,build方法允许有多个配置类 */
        FileGenerator.build(dataSource, CodeGenerator.class);
        return new MapperFactory();
    }

    /**
     * 使用自定义SqlSessionFactoryBean
     * @return
     * @throws Exception
     */
    @Bean
    public SqlSessionFactoryBean sqlSessionFactoryBean() throws Exception {
        SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
        bean.setDataSource(dataSource);
        ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
        /* 注意!在这里需要将原生Mybatis的XML路径写到配置中 */
        bean.setMapperLocations(resolver.getResources("classpath*:mybatis/mapper/*.xml"));
        org.apache.ibatis.session.Configuration configuration = new org.apache.ibatis.session.Configuration();
        configuration.setLazyLoadingEnabled(true);
        configuration.setMapUnderscoreToCamelCase(true);
        /* 注意!在这里需要将原生Mybatis的XML路径写到配置中 */
        configuration.getTypeAliasRegistry().registerAliases("com.demo.pojo");
        bean.setConfiguration(configuration);
        return bean;
    }

    /**
     * 生成代码类
     */
    @Tables(
            srcDir = "src/main/java",
            basePack = "com.demo.mybatis.fluent",
            daoDir = "src/main/java",
            tablePrefix = {"tb_"},
            tables = {@Table(value = {"tb_commodity"}, columns = {
                    @Column(value = "create_time", insert = "now()"),
                    @Column(value = "update_time", insert = "now()", update = "now()"),
                    @Column(value = "cover_images", javaType = StringList.class, typeHandler = StringListHandler.class)
            })})
    static class CodeGenerator {
    }
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/396035.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

常见数据模型

目录 1.1两类数据模型 1.2概念模型 1.3数据模型的组成要素 1.4常见数据模型 层次模型 网状模型 关系模型 数据模型是对现实世界数据特征的抽象&#xff0c;也就是说数据模型是用来描述数据、组织数据和对数据进行操作的。数据模型是数据库系统的核心和基础。 1.1两类数…

ip地址的分类及地址范围

IP地址根据网络ID的不同分为5种类型&#xff0c;A类地址、B类地址、C类地址、D类地址和E类地址。1、A类IP地址一个A类IP地址是指&#xff0c; 在IP地址的四段号码中&#xff0c;第一段号码为网络号码&#xff0c;剩下的三段号码为本地计算机的号码。A类IP地址中网络的标识长度为…

一种用于智能建筑云辅助检测的快速传感器放置位置优化方法

随着健康意识的觉醒&#xff0c;人们对居住的建筑提出了一系列与健康相关的要求&#xff0c;以期改善居住条件。在此背景下&#xff0c;BIM&#xff08;Building Information Modeling&#xff09;充分利用健康、环境、信息技术等诸多领域的前沿理论和技术&#xff0c;为工程师…

低代码开发的优势是什么?

低代码开发的优势是什么?低代码开发这个概念这两年来经常出现在人们的视野中&#xff0c;市场对于低代码的需求也越来越庞大。 Gartner预测&#xff0c;到2025年&#xff0c;75%的大型企业将使用至少四种低代码/无代码开发工具&#xff0c;用于IT应用开发和公民开发计划。 可…

Java面试题--Spring事务失效

Spring事务失效概述 Spring对事务的管理和处理&#xff0c;是基于AOP和编程范式的。因此Spring事务失效的场景较为丰富&#xff0c;包括但不限于以下常见情况&#xff1a; 异常被吞掉&#xff1a;当事务管理中出现异常但没有被正确捕捉并处理时&#xff0c;事务就会失效。例如…

Sedona 简介

Sedona 可以做什么? 分布式空间数据集 Spatial RDD on SparkSpatial DataFrame/SQL on SparkSpatial DataStream on FlinkSpatial Table/SQL on Flink 处理复杂的空间类型 Vector geometries / trajectoriesRaster images with Map AlgebraVarious input formats: CSV, TSV…

Vue 项目如何迁移小程序

最近我们看到有开发者在社群里提出新的疑惑「我手头已经有一个成熟的 HTML5 项目了&#xff0c;这种项目可以转为小程序在 FinClip 环境中运行吗&#xff1f;」。 经过工作人员的沟通了解&#xff0c;开发者其实是想将已有的 Vue 项目转为小程序&#xff0c;在集成了 FinClip …

(蓝桥真题)扫描游戏(计算几何+线段树二分)

题目链接&#xff1a;P8777 [蓝桥杯 2022 省 A] 扫描游戏 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn) 样例输入&#xff1a; 5 2 0 1 1 0 3 2 4 3 5 6 8 1 -51 -33 2 样例输出&#xff1a; 1 1 3 4 -1 分析&#xff1a;先考虑如何对物件进行排序&#xff0c;首先&…

【PSO-PID】使用粒子群算法整定PID参数控制起动机入口压力值

最近在学优化算法&#xff0c;接触到了经典寻优算法之粒子群PSO&#xff0c;然后就想使用PSO算法来调节PID参数&#xff0c;在试验成功之后将此控制算法应用到了空气起动系统上&#xff0c;同时与之前的控制器进行对比看看哪种控制效果最好。 0 引言 PID参数整定主要有两种&…

谁说程序员不懂了浪费,女神节安排

Python的PyQt框架的使用一、前言二、女神节文案三、浪漫的代码四、官宣文案一、前言 个人主页: ζ小菜鸡大家好&#xff0c;我是ζ小菜鸡&#xff0c;特在这个特殊的日子献上此文&#xff0c;希望小伙伴们能讨自己的女神欢心。 二、女神节文案 1.生活一半是柴米油盐&#xff0c…

优化设计流程的“闭环”问题

7.优化设计流程的“闭环”问题 交互设计师有一项很重要的工作就是定义任务流程。在接到需求之后&#xff0c;设计师需要把抽象的需求设计成具象的流程&#xff0c;然后再把流程分配到不同的界面&#xff0c;最终形成成品。设计流程不难&#xff0c;但是设计好的流程非常难&…

VisualStudio2022制作多项目模板及Vsix插件

一、安装工作负载 在vs2022上安装“visual studio扩展开发 ”工作负载 二、制作多项目模板 导出项目模板这个我就不再多说了&#xff08;项目→导出模板→选择项目模板&#xff0c;选择要导出的项目→填写模板信息→完成&#xff09;。 1.准备模板文件 将解决方案中的多个…

SpringBoot整合ElasticSearch实现模糊查询,排序,分页,高亮

目录 前言 1.框架集成-SpringData-整体介绍 1.1Spring Data Elasticsearch 介绍 2.框架集成Spring Data Elasticsearch 2.1版本说明 2.2.idea创建一个springboot项目 2.3.导入依懒 2.3.增加配置文件 2.4Spring Boot 主程序。 2.5.数据实体类 2.6.配置类 2.7.DAO 数据…

速卖通、亚马逊、ebay打造爆款,借助测评自养号提高转化率

做速卖通、亚马逊、ebay只有打造爆款&#xff0c;才能够挣到钱&#xff0c;如果一年到头&#xff0c;不断测款&#xff0c;不断测试不同的广告打法&#xff0c;那么代表了什么&#xff1f;代表了你的试错成本相当高&#xff0c;一不小心&#xff0c;分分钟就能够把手头上仅有的…

【YOLOv8/YOLOv7/YOLOv5/YOLOv4/Faster-rcnn系列算法改进NO.57】引入可形变卷积

文章目录前言一、解决问题二、基本原理三、​添加方法四、总结前言 作为当前先进的深度学习目标检测算法YOLOv8&#xff0c;已经集合了大量的trick&#xff0c;但是还是有提高和改进的空间&#xff0c;针对具体应用场景下的检测难点&#xff0c;可以不同的改进方法。此后的系列…

SRP合批问题

1&#xff09;SRP合批问题 ​2&#xff09;多个Base相机渲染到同一个渲染目标&#xff0c;移动平台花屏的问题 3&#xff09;粒子系统对GPU Instancing的支持 4&#xff09;如何修改URP下场景和UI分辨率分离&#xff08;不需要改颜色空间&#xff09; 这是第327篇UWA技术知识分…

苹果新专利实现无线技术传输睡眠数据,蓝牙在智能家居中的应用

苹果于 2017 年 5 月收购了芬兰科技公司 Beddit&#xff0c;只是在过去 6 年时间里并没有太大的动作。根据美国商标和专利局本周公示的清单&#xff0c;苹果获得了一项 Beddit 相关的技术专利。 根据专利描述&#xff0c;苹果使用一根或者多根天线&#xff0c;利用电磁辐射的…

详解Java8中如何通过方法引用获取属性名/::的使用

在我们开发过程中常常有一个需求&#xff0c;就是要知道实体类中Getter方法对应的属性名称&#xff08;Field Name&#xff09;&#xff0c;例如实体类属性到数据库字段的映射&#xff0c;我们常常是硬编码指定 属性名&#xff0c;这种硬编码有两个缺点。 1、编码效率低&#x…

Simulink 自动代码生成电机控制:在某国产ARM0定点MCU上实现自动代码生成无感电机控制

目录 前言 开发流程 定点化的技巧 代码生成运行演示 总结 前言 这次尝试了在国产arm0内核的MCU上实现Simulink自动代码生成永磁同步电机无传感控制。机缘巧合之下拿到了一块国产MCU的电机控制板和一个5000RPM的小电机。最后实现了无传感控制&#xff0c;在这里总结下一些经…

10.系统级I/O

1.基础所有的I/O设备被模型化为文件&#xff0c;所有的输入和输出被当作相应文件的读和写来执行应用程序在文件结尾检测到EOF(end of file)条件文本文件是只含有ASCII或Unicode字符的普通文件二进制文件是所有的其他文件对于内核&#xff0c;文本文件和二进制文件没有区别目录是…