Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the ways to configure Mybatis typeAlias

Shulou Source: shulou.com Published: 2022-06-02 01:56:08 09月15日 Update

This article mainly introduces the Mybatis typeAlias configuration methods have what knowledge, detailed and easy to understand, simple and fast operation, has a certain reference value, I believe that we read this Mybatis typeAlias configuration methods have what articles will be harvested, let's take a look at it.

Mybatis typeAlias configuration 1. Defining aliases 2. scan packet mode 3. Annotations package cn.lxc.vo;import org.apache.ibatis.type.Alias;@Alias("User")public class User { private int id; private String name; private int age; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; }}springboot Loading typeAlias issues for mybatis

After springboot is typed into jar and then run on linux, it will report that the entity class corresponding to type alias cannot be found. This is the problem of springboot scanning package.

Project default is to use Mybatis DefaultVFS scanning, but in the springboot environment, Mybatis DefaultVFS scanning package will appear problems, so only modify VFS,

For clarity, paste the code @Bean public SqlSessionFactory sqlSessionFactoryBean() throws Exception { logger.info("load SpringBootVFS"); //DefaultVFS has a problem in getting jar, which can only be modified by using springboot VFS.addImplClass(SpringBootVFS.class); SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean(); sqlSessionFactoryBean.setDataSource(dataSource()); PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); Resource[] resources1 = resolver.getResources("classpath*:/mybatis/*.xml"); Resource[] resources2 = resolver.getResources("classpath*:/mysql/mapper/*.xml"); Resource[] resources = (Resource[]) ArrayUtils.addAll(resources1,resources2); sqlSessionFactoryBean.setMapperLocations(resources); sqlSessionFactoryBean.setTypeAliasesPackage("com.xxx.xx.entity"); return sqlSessionFactoryBean.getObject(); } About "What are the configuration methods of Mybatis typeAlias", the content of this article is introduced here, thank you for reading! I believe that everyone has a certain understanding of the knowledge of "What are the configuration methods of Mybatis typeAlias". If you still want to learn more knowledge, please pay attention to the industry information channel.

Tags: Mode configuration problem knowledge content article clearly visible code value alias entity engineering easy to operate article easy to understand is in more annotations environment see Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia MariaDB MySQL Docker Xiaomi