Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XNode#toString() cannot display all information #2080

Closed
zhanjinhao opened this issue Oct 5, 2020 · 1 comment · Fixed by #3001
Closed

XNode#toString() cannot display all information #2080

zhanjinhao opened this issue Oct 5, 2020 · 1 comment · Fixed by #3001
Assignees
Labels
Milestone

Comments

@zhanjinhao
Copy link

zhanjinhao commented Oct 5, 2020

MyBatis version

3.5.5

java version

1.8

discription

I found that this method org.apache.ibatis.parsing.XNode#toString() has a defect, it only displays nodes of type Node.ELEMENT_NODE. The reason for this problem is that the method org.apache.ibatis.parsing.XNode#getChildren will only list the child nodes of type Node.ELEMENT_NODE. Therefore, when I am debugging, I cannot see all the information.

a xml file

<mapper namespace="demo.StudentMapper">
  <select id="selectFullStudent" resultMap="fullResult" databaseId="mysql">
    select
      STUDENT.ID ID,
      STUDENT.SNO SNO,
      STUDENT.SNAME SNAME,
      STUDENT.SSEX SSEX,
      STUDENT.SBIRTHDAY SBIRTHDAY,
      STUDENT.CLASS CLASS,
      SCORE.CNO CNO,
      SCORE.DEGREE DEGREE,
      HOUSE.HOUSE_ID HOUSE_ID,
      HOUSE.HOUSE_HOLDER HOUSE_HOLDER,
      HOUSE.HOUSE_MEMBER HOUSE_MEMBER
    from STUDENT, SCORE, HOUSE
    <where>
      <if test="sex != null">
        STUDENT.SSEX = #{sex};
      </if>
      and STUDENT.SNO = SCORE.SNO and HOUSE.HOUSE_MEMBER = STUDENT.SNO
    </where>
  </select>
</mapper>

Java code

package issue;

import org.apache.ibatis.parsing.XNode;
import org.apache.ibatis.parsing.XPathParser;

import java.io.InputStream;

public class ReproduceXnode {
    public static void main(String[] args) {
        InputStream resourceAsStream = ReproduceXnode.class.getClassLoader().getResourceAsStream("issue/StudentMapper.xml");
        XPathParser xPathParser = new XPathParser(resourceAsStream);
        XNode select = xPathParser.evalNode("mapper/select");
        System.out.println(select.toString());
    }
}

Expected result

  <select id="selectFullStudent" resultMap="fullResult" databaseId="mysql">
    select
      STUDENT.ID ID,
      STUDENT.SNO SNO,
      STUDENT.SNAME SNAME,
      STUDENT.SSEX SSEX,
      STUDENT.SBIRTHDAY SBIRTHDAY,
      STUDENT.CLASS CLASS,
      SCORE.CNO CNO,
      SCORE.DEGREE DEGREE,
      HOUSE.HOUSE_ID HOUSE_ID,
      HOUSE.HOUSE_HOLDER HOUSE_HOLDER,
      HOUSE.HOUSE_MEMBER HOUSE_MEMBER
    from STUDENT, SCORE, HOUSE
    <where>
      <if test="sex != null">
        STUDENT.SSEX = #{sex};
      </if>
      and STUDENT.SNO = SCORE.SNO and HOUSE.HOUSE_MEMBER = STUDENT.SNO
    </where>
  </select>

Actual result

<select resultMap="fullResult" databaseId="mysql" id="selectFullStudent">
    <where>
        <if test="sex != null">
        STUDENT.SSEX = #{sex};
      </if>
    </where>
</select>
@harawata harawata added the bug label Oct 7, 2020
@nothingzhl
Copy link
Contributor

I'm fixed this issue.Pr

chehongwei-git pushed a commit to chehongwei-git/mybatis-3 that referenced this issue Mar 19, 2021
cszxyang added a commit to cszxyang/mybatis-3 that referenced this issue May 6, 2022
human-user added a commit to human-user/mybatis-3 that referenced this issue Nov 7, 2023
harawata added a commit to harawata/mybatis-3 that referenced this issue Nov 7, 2023
- Keeping indentation, but it won't be perfect in multi-line text nodes.
- Add a new line after each open/close tag even for a short line like `<id>3</id>`. There aren't many short lines like that in MyBatis mappers.
- Use 2 spaces for indentation instead of 4 to save earth.

Should fix mybatis#2080
Should close mybatis#2084 mybatis#2552 mybatis#2998
harawata added a commit to harawata/mybatis-3 that referenced this issue Nov 7, 2023
- Keeping indentation, but it won't be perfect in multi-line text nodes.
- Add a new line after each open/close tag even for a short line like `<id>3</id>`. There aren't many short lines like that in MyBatis mappers.
- Use 2 spaces for indentation instead of 4 to save earth.

Should fix mybatis#2080
Should close mybatis#2084 mybatis#2552 mybatis#2998
@harawata harawata self-assigned this Nov 10, 2023
@harawata harawata added this to the 3.5.15 milestone Nov 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants