public final class String implements java.io.Serializable, Comparable<String>, CharSequence { /** The value is used for character storage. */ private final char value[]; /** Cache the hash code for the string */ private int hash; // Default to 0 /** use serialVersionUID from JDK 1.0.2 for interoperability */ private static final long serialVersionUID = -6849794470754667710L; ...... }
<insert id="insertUser" parameterType="org.tyshawn.bean.User"> INSERT INTO t_user(name, age) VALUES (#{name}, #{age}) </insert>
public class User implements Serializable { private String name; private Integer age; public String getName() { return name; } public void setName(String name) { this.name = name; } public Integer getAge() { return age; } public void setAge(Integer age) { this.age = age; } @Override public String toString() { return "User{" "name='" name '\'' ", age=" age '}'; } }
public class SerializableTest { private static void serialize(User user) throws Exception { ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(new File("D:\\111.txt"))); oos.writeObject(user); oos.close(); } private static User deserialize() throws Exception{ ObjectInputStream ois = new ObjectInputStream(new FileInputStream(new File("D:\\111.txt"))); return (User) ois.readObject(); } public static void main(String[] args) throws Exception { User user = new User(); user.setName("tyshawn"); user.setAge(18); System.out.println("序列化前的结果: " user); serialize(user); User dUser = deserialize(); System.out.println("反序列化后的结果: " dUser); } }
public class User implements Serializable { private String name; private Integer age; private String sex; public String getName() { return name; } public void setName(String name) { this.name = name; } public Integer getAge() { return age; } public void setAge(Integer age) { this.age = age; } public String getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } @Override public String toString() { return "User{" "name='" name '\'' ", age=" age ", sex='" sex '\'' '}'; } }
private static final long serialVersionUID = 1L;
public class User implements Serializable { private static final long serialVersionUID = 1L; private String name; private Integer age; private transient String sex; private static String signature = "你眼中的世界就是你自己的样子"; public String getName() { return name; } public void setName(String name) { this.name = name; } public Integer getAge() { return age; } public void setAge(Integer age) { this.age = age; } public String getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } public static String getSignature() { return signature; } public static void setSignature(String signature) { User.signature = signature; } @Override public String toString() { return "User{" "name='" name '\'' ", age=" age ", sex='" sex '\'' ", signature='" signature '\'' '}'; } }
public class SerializableTest { private static void serialize(User user) throws Exception { ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(new File("D:\\111.txt"))); oos.writeObject(user); oos.close(); } private static User deserialize() throws Exception{ ObjectInputStream ois = new ObjectInputStream(new FileInputStream(new File("D:\\111.txt"))); return (User) ois.readObject(); } public static void main(String[] args) throws Exception { User user = new User(); user.setName("tyshawn"); user.setAge(18); user.setSex("man"); System.out.println("序列化前的结果: " user); serialize(user); User dUser = deserialize(); System.out.println("反序列化后的结果: " dUser); } }