输出到控制台,内容无法对齐
问题描述:输出到控制台,内容无法对齐
相关截图:
相关代码:
实体类代码:Student.java
package com.imooc.mybatis.entity; /** * @author Gavin * @version 1.00 */ public class Student { private Integer id; private Integer regNo; private String name; private String sex; private Integer age; private String grade; private String major; public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public Integer getRegNo() { return regNo; } public void setRegNo(Integer regNo) { this.regNo = regNo; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } public Integer getAge() { return age; } public void setAge(Integer age) { this.age = age; } public String getGrade() { return grade; } public void setGrade(String grade) { this.grade = grade; } public String getMajor() { return major; } public void setMajor(String major) { this.major = major; } @Override public String toString() { return getId() + "\t\t" + getRegNo() + "\t" + getName() + "\t" + getAge() + "\t" + getSex() + "\t" + getGrade() + "\t" + getMajor(); } }
测试输出代码:
@Test public void testSelectAllStudent() { SqlSession session = null; try { session = MyBatisUtils.openSession(); List<Student> list = session.selectList("student.selectAll"); System.out.println("用户编号\t学号\t\t\t姓名\t\t年龄\t性别\t年级\t\t专业"); for (Student s: list) { System.out.println(s); } } catch (Exception e) { throw e; } finally { MyBatisUtils.closeSession(session); } }
尝试过的解决方式:
用\t调整,但是姓名是2个字的,就无法对齐。
13
收起
正在回答 回答被采纳积分+1
1回答
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星