今天遇到个奇葩问题,首先没报错,是想查询所有一级分类记录(实体类有二级分类集合)。结果项目执行添加功能之后,数据库看到新增数据,但代码查询获得的结果集合始终和没新增之前一样。

原因:排除了事务配置,sql语句的问题,最后发现是因为新增一级分类是木有所属二级分类的,而恰恰我在mybatis里定义了一个DAO方法,是将其二级分类一起装好返回一级分类集合。我新增了个二级分类归属于新增一级分类,然后再次查询就可以查到新增一级分类。

<select id="selectByExampleWithSecondCategory" parameterType="com.pojo.CategoryExample" resultMap="BaseResultMapWithSecondCategory">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_ListWithSecondCategory" />
    from category,categorysecond
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    
      where category.cid=categorysecond.cid
    
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>

想想也是傻, 新增数据面对where category.cid=categorysecond.cid,查得到就见鬼了!


	@RequestMapping("/admin-category-select")
	public String selectAllCategory(Model model) {
		//新增的是木有二级分类的,所以调用这个方法查不出新增的一级分类,坑!mmp
		 //List<Category> cList=categorySevice.selectAllCategoriesWithSecondCategory();