在MyBatis中,如何将数据库中的字符串类型映射为枚举类型?

embedded/2024/9/25 10:38:21/

在MyBatis中,如何将数据库中的字符串类型映射为枚举类型?

网上看了很多教程。说了很多,但是都没说到重点!

很简单,xml文件中,··· 使用resultType,而不是使用resultMap就可以了。

 

resultType="org.jeecg.modules.hc.entity.HcMainCategories">

源码:

Entity


/*** 名称*/@Excel(name = "名称", width = 15)@ApiModelProperty(value = "名称")private java.lang.String name;/*** 排序*/@Excel(name = "排序", width = 15)@ApiModelProperty(value = "排序")private java.lang.Integer sort;/*** 状态*/@Excel(name = "状态", width = 15)@ApiModelProperty(value = "状态")private HcUpFlagEnum state;

Xml

 
<resultMap id="BaseResultMap" type="org.jeecg.modules.hc.entity.HcMainCategories"><id property="id" column="ID" jdbcType="VARCHAR"/><result property="createBy" column="CREATE_BY" jdbcType="VARCHAR"/><result property="createTime" column="CREATE_TIME" jdbcType="TIMESTAMP"/><result property="updateBy" column="UPDATE_BY" jdbcType="VARCHAR"/><result property="updateTime" column="UPDATE_TIME" jdbcType="TIMESTAMP"/><result property="icon" column="ICON" jdbcType="VARCHAR"/><result property="name" column="NAME" jdbcType="VARCHAR"/><result property="sort" column="SORT" jdbcType="BIGINT"/><result property="state" column="STATE" jdbcType="VARCHAR"/></resultMap><sql id="Base_Column_List">ID,CREATE_BY,CREATE_TIME,UPDATE_BY,UPDATE_TIME,ICON,NAME,SORT,STATE</sql><select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">select<include refid="Base_Column_List" />from hc_main_categorieswhere ID = #{id,jdbcType=VARCHAR}</select><!--根据地址ID查询主营品类--><select id="selectByAddressId" resultType="org.jeecg.modules.hc.entity.HcMainCategories">select distinctd.ID,d.CREATE_BY,d.CREATE_TIME,d.UPDATE_BY,d.UPDATE_TIME,d.ICON,d.NAME,d.SORT,d.STATEfromhc_site_address_details aleft join hc_site_relation b on b.SITE_ID = a.SITE_IDleft join hc_main_relation c on c.MERCHANT_ID = b.MERCHANT_IDleft join hc_main_categories d on d.ID = c.MAIN_CATEGORIES_IDwherea.ID = #{vo.id} and d.STATE = 'yes'</select>

Column 'ID' in field list is ambiguous;

SELECT ID, CREATE_BY, CREATE_TIME, UPDATE_BY, UPDATE_TIME, ICON, NAME, SORT, STATE FROM hc_site_address_details a LEFT JOIN hc_site_relation b ON b.SITE_ID = a.SITE_ID LEFT JOIN hc_main_relation c ON c.MERCHANT_ID = b.MERCHANT_ID LEFT JOIN hc_main_categories d ON d.ID = c.MAIN_CATEGORIES_ID WHERE a.ID = ?

### Cause: java.sql.SQLIntegrityConstraintViolationException: Column 'ID' in field list is ambiguous

; Column 'ID' in field list is ambiguous;

nested exception is java.sql.SQLIntegrityConstraintViolationException: Column 'ID' in field list is ambiguous] with root cause

java.sql.SQLIntegrityConstraintViolationException: Column 'ID' in field list is ambiguous

----

错误原因:

··· Base_Column_List中的字段没有加上别名d.

<sql id="Base_Column_List">ID,CREATE_BY,CREATE_TIME,UPDATE_BY,UPDATE_TIME,ICON,NAME,SORT,STATE
</sql><select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">select<include refid="Base_Column_List" />from hc_main_categorieswhere  ID = #{id,jdbcType=VARCHAR}
</select>
<select id="selectByAddressId" resultType="org.jeecg.modules.hc.entity.HcMainCategories">select distinctd.ID,d.CREATE_BY,d.CREATE_TIME,d.UPDATE_BY,d.UPDATE_TIME,d.ICON,d.NAME,d.SORT,d.STATEfromhc_site_address_details aleft join hc_site_relation b on b.SITE_ID = a.SITE_IDleft join hc_main_relation c on c.MERCHANT_ID = b.MERCHANT_IDleft join hc_main_categories d on d.ID = c.MAIN_CATEGORIES_IDwherea.ID = #{vo.id} and d.STATE = 'yes'
</select>

 


http://www.ppmy.cn/embedded/41540.html

相关文章

微信小程序使用过程注意事项

整个页面的样式设置&#xff1f; 全局页面和单个页面设置整个页面的样式时都可以通过 page标签选择器来设置。 page {background:red; }给轮播图swiper设置圆角&#xff0c;使用border-radius:10rpx;不生效? 需要再加上overflow:hidden. swiper {border-radius: 10rpx;overflo…

SharePoint 使用renderListDataAsStream方法查询list超过5000时的数据

问题&#xff1a; 当SharePoint List里的数据超过5000时&#xff0c;如果使用常用的rest api去获取数据&#xff0c;例如 await this.sp.web.lists.getByTitle(Document Library).rootFolder.files.select(*, listItemAllFields).expand(listItemAllFields).filter(listItemA…

开源模型应用落地-CodeQwen模型小试-集成langchain(四)

一、前言 通过学习代码专家模型&#xff0c;开发人员可以获得高效、准确和个性化的代码支持。这不仅可以提高工作效率&#xff0c;还可以在不同的技术环境中简化软件开发工作流程。代码专家模型的引入将为开发人员带来更多的机会去关注创造性的编程任务&#xff0c;从而推动软件…

go语言中的数组和切片

Go语言中的数组和切片 数组 定义 一维数组 一维数组是具有相同数据类型的固定大小的数据序列。在Go语言中&#xff0c;一维数组的定义形式为var arrayName [size]dataType&#xff0c;其中arrayName是数组的名称&#xff0c;size是数组的大小&#xff0c;dataType是数组中元…

GateWay检查接口耗时

添加gateway依赖 <dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-gateway</artifactId> </dependency>创建一个LogTimeGateWayFilterFactory类&#xff0c;可以不是这个名字但是后面必须是x…

【案例】使用Vue实现拖拽课表

效果展示 效果说明 点击左侧的课程并进行拖拽&#xff0c;拖拽到要开设本课程的地方然后松手&#xff0c;即可将本节课设置为当前所拖拽的科目并且背景色为当前科目的背景色&#xff0c;当多次拖拽到同一节课的时候将会实现后者覆盖前者的效果。 效果实现代码 第一步&#x…

【SpringBoot整合系列】SpringBoot整合RabbitMQ业务应用Demo

目录 业务要求代码实现1.依赖2.配置3.配置类4.接口Controller5.业务Service5.1模拟保存商品记录5.2提交订单业务5.3用户支付业务&#xff08;模拟&#xff09;完整代码 6.消息消费者Consumer完整代码 7.其他mapper、model、工具类mapper注意&#xff1a;启动类上别忘了加Mapper…

基于yolov2深度学习网络的单人口罩佩戴检测和人脸定位算法matlab仿真

目录 1.算法运行效果图预览 2.算法运行软件版本 3.部分核心程序 4.算法理论概述 5.算法完整程序工程 1.算法运行效果图预览 2.算法运行软件版本 MATLAB2022A 3.部分核心程序 ..............................................................I0 imresize…