我正在使用MyBatis 2.0.0并遇到问题:我有一个userId和status字段需要检索数据,因此我正在使用Mybatis。但是当我试图获取数据MyBatis不起作用时,我不断收到相同的错误。我试图将这些行添加到application.properties
#mybatis entity scan packages
mybatis.type-aliases-package=com.cnoga.**.dao
#Mapper.xml location
mybatis.mapper-locations=classpath*:/mybatis/**/*.xml
mybatis.configuration.map-underscore-to-camel-case=true
但什么都没发生,我仍然得到我的错误。我甚至试图像这样创建mybatis-config.xml:
<?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>
<settings>
<setting name="mapUnderscoreToCamelCase" value="true" />
</settings>
</configuration>
并将此行添加到application.properties而不是上面的行:
“mybatis.config-位置=类路径:/mybatis-config.xml”
映射文件:
<?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.proj.user.dao.UserMapper" >
<select id="query4Regist" resultType="java.util.Map" parameterType="java.util.Map" >
select u.user_id userId,
status
from t_user u
left join t_user_group ug on u.user_id = ug.user_id
where u.is_del = 1
and u.status between 0 and 4
and (
u.email = #{account,jdbcType=NVARCHAR}
<if test="countryCode != null and countryCode != ''">
or (u.mobile = #{account,jdbcType=NVARCHAR} and u.country_code = #{countryCode,jdbcType=NVARCHAR})
</if>
)
and (u.region_name = #{regionName} or ug.group_id = 7 or ug.group_id = 8)
order by u.user_id desc offset 0 rows fetch next 1 rows only
</select>
</mapper>
我解决了这个问题!问题是使用地图功能。要使用MYBATIS,我只为我想要传输的值构建了struct,我只是在我调用map函数的所有地方都进行了更改以从新结构中获取数据