source is null for getProperty(null, "shop")
来源:8-10 商品列表展示之后端开发
慕粉1556544580
2021-02-02
Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.builder.BuilderException: Error evaluating expression ‘productCondition.shop!=null and productCondition.shop.shopId!=null’. Cause: org.apache.ibatis.ognl.OgnlException: source is null for getProperty(null, “shop”)
描述 服务器遇到一个意外的情况,阻止它完成请求。
例外情况
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.builder.BuilderException: Error evaluating expression ‘productCondition.shop!=null and productCondition.shop.shopId!=null’. Cause: org.apache.ibatis.ognl.OgnlException: source is null for getProperty(null, “shop”)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1013)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:897)
javax.servlet.http.HttpServlet.service(HttpServlet.java:626)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882)
javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
根本原因。
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.builder.BuilderException: Error evaluating expression ‘productCondition.shop!=null and productCondition.shop.shopId!=null’. Cause: org.apache.ibatis.ognl.OgnlException: source is null for getProperty(null, “shop”)
org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:77)
org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446)
src/test/java单元测试都过了,最后再浏览器中输入url却报这个错误是为什么啊?网上有的说是空指针,我也没看懂。
1回答
-
慕粉1556544580
提问者
2021-02-02
试着写下面两种清空也不行 第一种情况: <where> <if test="productCondition!=null"> <if test="productCondition.shop!=null"> <if test="productCondition.shop.shopId!=null"> and shop_id = #{productCondition.shop.shopId} </if> </if> </if> <if test="productCondition!=null"> <if test="productCondition.productCategory!=null"> <if test="productCondition.productCategory.productCategoryId!=null"> and product_category_id = #{productCondition.productCategory.productCategoryId} </if> </if> </if> <!-- 写like语句的时候 一般都会写成 like '% %' 在mybatis里面写就是应该是 like '%${name} %' 而不是 '%#{name} %' ${name} 是不带单引号的,而#{name} 是带单引号的 --> <if test="productCondition!=null"> <if test="productCondition.productName!=null"> and product_name like '%${productCondition.productName}%' </if> </if> <if test="productCondition!=null"> <if test="productCondition.enableStatus!=null"> and enable_status = #{productCondition.enableStatus} </if> </if> </where> 第二种情况: <where> <if test="productCondition!=null"> <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> </if> </where>
上面这两种where根本不管用,虽然能查出来,但是是把所有的都查出来
粘你的代码就会报错!!!
00
相似问题