输出到控制台,内容无法对齐
问题描述:输出到控制台,内容无法对齐
相关截图:
相关代码:
实体类代码:Student.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | 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(); } } |
测试输出代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | @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积分~
来为老师/同学的回答评分吧