productDao.xml里面的问题

来源:8-7 商品编辑之后端开发上

qq_慕哥8330561

2020-06-03

图片描述
这里会报错
Caused by: org.springframework.core.NestedIOException: Failed to parse mapping resource: ‘file [F:javawebo2o argetclassesmapperProductDao.xml]’; nested exception is org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 39; columnNumber: 17; 元素类型为 “resultMap” 的内容必须匹配 “(constructor?,id*,result*,association*,collection*,discriminator?)”。
at org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory(SqlSessionFactoryBean.java:534)
at org.mybatis.spring.SqlSessionFactoryBean.afterPropertiesSet(SqlSessionFactoryBean.java:424)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1855)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1792)
… 39 more
Caused by: org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 39; columnNumber: 17; 元素类型为 “resultMap” 的内容必须匹配 “(constructor?,id*,result*,association*,collection*,discriminator?)”。
at org.apache.ibatis.parsing.XPathParser.createDocument(XPathParser.java:260)
at org.apache.ibatis.parsing.XPathParser.(XPathParser.java:126)
at org.apache.ibatis.builder.xml.XMLMapperBuilder.(XMLMapperBuilder.java:80)
at org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory(SqlSessionFactoryBean.java:531)
… 42 more
Caused by: org.xml.sax.SAXParseException; lineNumber: 39; columnNumber: 17; 元素类型为 “resultMap” 的内容必须匹配 “(constructor?,id*,result*,association*,collection*,discriminator?)”。

写回答

2回答

qq_慕哥8330561

提问者

2020-06-03

解决了报错的问题 但是这里的错误怎么改

1
0

翔仔

2020-06-03

这里主要是mapper写错了,第39行 17列 写错了,可以对比一下视频是如何配置的

productDao.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.imooc.o2o.dao.ProductDao">
	<resultMap id="productMap" type="com.imooc.o2o.entity.Product">
		<id column="product_id" property="productId" />
		<result column="product_name" property="productName" />
		<result column="product_desc" property="productDesc" />
		<result column="img_addr" property="imgAddr" />
		<result column="normal_price" property="normalPrice" />
		<result column="promotion_price" property="promotionPrice" />
		<result column="priority" property="priority" />
		<result column="create_time" property="createTime" />
		<result column="last_edit_time" property="lastEditTime" />
		<result column="enable_status" property="enableStatus" />
		<result column="point" property="point" />
		<association property="productCategory" column="product_category_id"
			javaType="com.imooc.o2o.entity.ProductCategory">
			<id column="product_category_id" property="productCategoryId" />
			<result column="product_category_name" property="productCategoryName" />
		</association>
		<association property="shop" column="shop_id"
			javaType="com.imooc.o2o.entity.Shop">
			<id column="shop_id" property="shopId" />
			<result column="owner_id" property="ownerId" />
			<result column="shop_name" property="shopName" />
		</association>
		<collection property="productImgList" column="product_id"
			ofType="com.imooc.o2o.entity.ProductImg">
			<id column="product_img_id" property="productImgId" />
			<result column="detail_img" property="imgAddr" />
			<result column="img_desc" property="imgDesc" />
			<result column="priority" property="priority" />
			<result column="create_time" property="createTime" />
			<result column="product_id" property="productId" />
		</collection>
	</resultMap>
	<select id="queryProductList" resultType="com.imooc.o2o.entity.Product">
		SELECT
		product_id,
		product_name,
		product_desc,
		img_addr,
		normal_price,
		promotion_price,
		priority,
		create_time,
		last_edit_time,
		enable_status,
		point,
		product_category_id,
		shop_id
		FROM
		tb_product
		<where>
			<if
				test="productCondition.shop!=null
				 and productCondition.shop.shopId!=null">
				and shop_id = #{productCondition.shop.shopId}
			</if>
			<if
				test="productCondition.productCategory!=null
				 and productCondition.productCategory.productCategoryId!=null">
				and product_category_id =
				#{productCondition.productCategory.productCategoryId}
			</if>
			<!-- 写like语句的时候 一般都会写成 like '% %' 在mybatis里面写就是应该是 like '%${name} %' 而不是 
				'%#{name} %' ${name} 是不带单引号的,而#{name} 是带单引号的 -->
			<if test="productCondition.productName!=null">
				and product_name like '%${productCondition.productName}%'
			</if>
			<if test="productCondition.enableStatus!=null">
				and enable_status = #{productCondition.enableStatus}
			</if>
		</where>
		ORDER BY
		priority DESC
		LIMIT #{rowIndex},#{pageSize};
	</select>

	<select id="queryProductCount" resultType="int">
		SELECT count(1) FROM tb_product
		<where>
			<if
				test="productCondition.shop!=null
				 and productCondition.shop.shopId!=null">
				and shop_id = #{productCondition.shop.shopId}
			</if>
			<if
				test="productCondition.productCategory!=null
				 and productCondition.productCategory.productCategoryId!=null">
				and product_category_id =
				#{productCondition.productCategory.productCategoryId}
			</if>
			<if test="productCondition.productName!=null">
				and product_name like '%${productCondition.productName}%'
			</if>
			<if test="productCondition.enableStatus!=null">
				and enable_status = #{productCondition.enableStatus}
			</if>
		</where>
	</select>
	<select id="queryProductById" resultMap="productMap"
		parameterType="Long">
		<!-- 具体的sql -->
		SELECT
		p.product_id,
		p.product_name,
		p.product_desc,
		p.img_addr,
		p.normal_price,
		p.promotion_price,
		p.priority,
		p.create_time,
		p.last_edit_time,
		p.enable_status,
		p.point,
		p.product_category_id,
		p.shop_id,
		pm.product_img_id,
		pm.img_addr AS detail_img,
		pm.img_desc,
		pm.priority,
		pm.create_time
		FROM
		tb_product p
		LEFT JOIN
		tb_product_img pm
		ON
		p.product_id =
		pm.product_id
		WHERE
		p.product_id =
		#{productId}
		ORDER BY
		pm.priority DESC
	</select>
	<insert id="insertProduct" parameterType="com.imooc.o2o.entity.Product"
		useGeneratedKeys="true" keyProperty="productId" keyColumn="product_id">
		INSERT INTO
		tb_product(product_name,product_desc,img_addr,
		normal_price,promotion_price,priority,create_time,
		last_edit_time,enable_status,point,product_category_id,
		shop_id)
		VALUES
		(#{productName},#{productDesc},#{imgAddr},
		#{normalPrice},#{promotionPrice},#{priority},#{createTime},
		#{lastEditTime},#{enableStatus},#{point},#{productCategory.productCategoryId},
		#{shop.shopId})
	</insert>
	<update id="updateProduct" parameterType="com.imooc.o2o.entity.Product"
		keyProperty="product_id" useGeneratedKeys="true">
		UPDATE tb_product
		<set>
			<if test="productName != null">product_name=#{productName},</if>
			<if test="productDesc != null">product_desc=#{productDesc},</if>
			<if test="imgAddr != null">img_addr=#{imgAddr},</if>
			<if test="normalPrice != null">normal_price=#{normalPrice},</if>
			<if test="promotionPrice != null">promotion_price=#{promotionPrice},</if>
			<if test="priority != null">priority=#{priority},</if>
			<if test="lastEditTime != null">last_edit_time=#{lastEditTime},</if>
			<if test="enableStatus != null">enable_status=#{enableStatus},</if>
			<if test="point != null">point=#{point},</if>
			<if
				test="productCategory != null
				 and productCategory.productCategoryId != null">
				product_category_id=#{productCategory.productCategoryId}
			</if>
		</set>
		WHERE product_id = #{productId}
		AND shop_id=#{shop.shopId}
	</update>
	<update id="updateProductCategoryToNull" parameterType="Long">
		UPDATE
		tb_product
		SET
		product_category_id = null
		WHERE product_category_id =
		#{productCategoryId}
	</update>
	<delete id="deleteProduct">
		DELETE FROM
		tb_product
		WHERE
		product_id = #{productId}
		AND shop_id=#{shopId}
	</delete>
</mapper>


0
2
翔仔
回复
qq_慕哥8330561
是的,这个是错的,正好我们没有使用到相关信息所以没报错,应该是
2020-06-04
共2条回复

Java双版本(SSM到SpringBoot)校园商铺全栈开发

SSM商铺V1.0,解决毕设痛点;SpringBoot商铺V2.0,满足工作刚需

5101 学习 · 8139 问题

查看课程