mybatis对象插入一个对象 ?

dreamers 发布于 2012/07/29 00:07
阅读 5K+
收藏 0

如题。

package org.yang.beans;

import java.io.Serializable;
import java.util.Date;

public class Article implements Serializable
{
	private static final long serialVersionUID = 1L;
	private Integer id;
	private String typeClass;
	private String content;
	private Date publicedDate = new Date();
	private String author = "杨志永";
	private String title;

	public Integer getId()
	{
		return id;
	}

	public void setId(Integer id)
	{
		this.id = id;
	}

	public Date getPublicedDate()
	{
		return publicedDate;
	}

	public void setPublicedDate(Date publicedDate)
	{
		this.publicedDate = publicedDate;
	}

	public String getTypeClass()
	{
		return typeClass;
	}

	public void setTypeClass(String typeClass)
	{
		this.typeClass = typeClass;
	}

	public String getContent()
	{
		return content;
	}

	public void setContent(String content)
	{
		this.content = content;
	}

	public String getAuthor()
	{
		return author;
	}

	public void setAuthor(String author)
	{
		this.author = author;
	}

	public String getTitle()
	{
		return title;
	}

	public void setTitle(String title)
	{
		this.title = title;
	}

}

 想要在mybatis中插入这个对象,我这样做无效:

package org.yang.dao;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.yang.beans.Article;

public interface ArticleMapper
{
	@Insert("INSERT INTO articles (typeClass, content, publicedDate, author, title) VALUES (#{typeClass}, #{content}, #{publicedDate}, #{author}, #{title})")
	@Options(useGeneratedKeys = true, keyProperty = "id")
	int addNewArticle(Article article);
}

调用 Action:

int result = service.addNewArticle( this.getArticle() );

然后提示错误:

org.apache.ibatis.exceptions.PersistenceException: 
### Error updating database.  Cause: java.sql.SQLException: Incorrect string value: '\xE9\x9F\xB3\xE4\xB9\x90' for column 'typeClass' at row 1

加载中
0
水牛叔叔
水牛叔叔
插入的编码和数据库的编码不统一,不能插入
返回顶部
顶部