你意思是 我实体类中还是用String类型 然后在servlet中用StringBuffer接受?
可这样的话就没必要用StringBuffer了啊 我考虑的是性能 因为自我介绍那一项可能会有很多内容
另外,我用StringBuffer保存时 数据库中那列的类型是另外中大容量类型的
部分代码如下:
实体类:
package entity;
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
@Entity
@Table(name="t_customer")
public class Customer
{
private int c_id;
private String c_name;
private String c_password;
private String c_sex;
private Date c_birthday;
private String c_education;
private StringBuffer c_intorduce;
private String c_favor;
@Id
@GeneratedValue
public int getC_id() {
return c_id;
}
public void setC_id(int cId) {
c_id = cId;
}
public String getC_name() {
return c_name;
}
public void setC_name(String cName) {
c_name = cName;
}
public String getC_password() {
return c_password;
}
public void setC_password(String cPassword) {
c_password = cPassword;
}
public String getC_sex() {
return c_sex;
}
public void setC_sex(String cSex) {
c_sex = cSex;
}
@Temporal(TemporalType.DATE)
public Date getC_birthday() {
return c_birthday;
}
public void setC_birthday(Date cBirthday) {
c_birthday = cBirthday;
}
public String getC_education() {
return c_education;
}
public void setC_education(String cEducation) {
c_education = cEducation;
}
public StringBuffer getC_intorduce() {
return c_intorduce;
}
public void setC_intorduce(StringBuffer cIntorduce) {
c_intorduce = cIntorduce;
}
public String getC_favor() {
return c_favor;
}
public void setC_favor(String cFavor) {
c_favor = cFavor;
}
}
servlet:
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse rep)
throws ServletException, IOException {
req.setCharacterEncoding("GBK");
rep.setContentType("text/html;charset=GBK");
PrintWriter out=rep.getWriter();
String c_name=req.getParameter("c_name");
String c_password=req.getParameter("c_password");
String c_sex=req.getParameter("c_sex");
String year=req.getParameter("year");
String month=req.getParameter("month");
String date=req.getParameter("date");
String c_birthday=year+"-"+month+"-"+date;
SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd");
Date c_birth=new Date();
try {
c_birth = df.parse(c_birthday);
}
catch (ParseException e) {
e.printStackTrace();
}
String c_edu=req.getParameter("c_edu");
String c_favor=req.getParameter("c_favor");
/*StringBuffer c_intorduce=new StringBuffer();
c_intorduce.append(req.getParameter("c_intorduce"));
System.out.println(c_intorduce.toString());*/
String c_intorduce=req.getParameter("c_intorduce");
Customer customer=new Customer();
customer.setC_name(c_name);
customer.setC_password(c_password);
customer.setC_sex(c_sex);
customer.setC_birthday(c_birth);
customer.setC_education(c_edu);
customer.setC_favor(c_favor);
customer.setC_intorduce(c_intorduce);
CustomerDao dao=new CustomerDao();
dao.addcustomer(customer);
out.flush();
out.close();
}