开发者社区> 问答> 正文

mybatis对象插入一个对象 ? :报错

如题。

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

展开
收起
kun坤 2020-06-14 07:33:48 475 0
1 条回答
写回答
取消 提交回答
  • 插入的编码和数据库的编码不统一,不能插入

    2020-06-14 07:33:53
    赞同 展开评论 打赏
问答分类:
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
Java Spring Boot开发实战系列课程【第6讲】:Spring Boot 2.0实战MyBatis与优化(Java面试题) 立即下载
低代码开发师(初级)实战教程 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载

相关实验场景

更多