Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the ways to configure Mybatis typeAlias

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report