gpt4 book ai didi

java - Spring:java.io.NotSerializedException:MapSqlParameterSource

转载 作者:行者123 更新时间:2023-11-30 08:19:15 33 4
gpt4 key购买 nike

我尝试使用 Spring JdbcTemplate 插入一个简单的基础,将参数查询与 MapSqlParamaterSource 映射,并且将错误视为以下数据:

public void adiciona(Conta conta) {
String sql = "insert into contas (descricao, paga, valor, tipo) values (:descricao,:paga,:valor,:tipo)";
MapSqlParameterSource pss = new MapSqlParameterSource();
pss.addValue("descricao", conta.getDescricao());
pss.addValue("paga", "true");
pss.addValue("valor", conta.getValor());
pss.addValue("tipo", conta.getTipo());
getJdbcTemplate().update(sql, pss);
}

错误日志:

mar 22, 2015 12:16:00 PM org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: Servlet.service() for servlet [spring mvc] in context with path [/contas] threw exception [Request processing failed; nested exception is org.springframework.dao.TransientDataAccessResourceException: PreparedStatementCallback; SQL [insert into contas (descricao, paga, valor, tipo) values (:descricao,:paga,:valor,:tipo)]; Invalid argument value: java.io.NotSerializableException; nested exception is java.sql.SQLException: Invalid argument value: java.io.NotSerializableException] with root cause
java.io.NotSerializableException: org.springframework.jdbc.core.namedparam.MapSqlParameterSource

Java Bean:

public class Conta implements Serializable {

private static final long serialVersionUID = 4678852901357132238L;

private Long id;
private String descricao;
private boolean paga;
private double valor;
private Calendar dataPagamento;
private TipoDaConta tipo;

// getters and settes

谁能告诉我如何解决这个问题?

最佳答案

我也遇到了同样的问题,我通过更改它解决了它

this.getJdbcTemplate().update(query,mapSqlParameterSource);

this.getNamedParameterJdbcTemplate().update(query,mapSqlParameterSource);

关于java - Spring:java.io.NotSerializedException:MapSqlParameterSource,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29196286/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com