如何在mysql响应中从变量名中删除“389;”?

vc9ivgsu  于 2021-08-25  发布在  Java
关注(0)|答案(1)|浏览(351)

我目前正在升级一个android应用程序,它通过glassfish服务器使用mysql数据库,我添加了一些方法,但数据库响应有问题。新版本在每个变量名前添加了一个“389;”,这会导致应用程序出现错误,无法恢复任何数据。我正在开发netbeans 8.0.2、glassfish 4.1和mysql workbench 6.2.5。
以下是旧版本的响应:

"m_resultat": [
{
  "code": "DEK-HORIZON.03-LIGNE1",
  "numSerie": "284992",
  "anneeFabrication": 2004,
  "miseEnService": "01/01/05",
  "affectation": "Ligne 1",
  "typeMachine": "DEK",
  "dateDerniereMaintenance": 1614938555000,
  "delaiMaintenance": 335
}]

现在是新版本的响应:

"m_resultat": [
{
  "_code": "DEK-HORIZON.03-LIGNE1",
  "_numSerie": "284992",
  "_anneeFabrication": 2004,
  "_miseEnService": "01/01/05",
  "_affectation": "Ligne 1",
  "_typeMachine": "DEK",
  "_dateDerniereMaintenance": 1614938555000,
  "_delaiMaintenance": 335
}]

我没有改变任何通信/soap方法,唯一的区别是旧版本是从2018年开始的,我已经遇到了maven 3.0.5的http过时问题,所以我认为这可能是更新/版本问题。
以下是查询的代码:

@Entity
@Table(name = "machine")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Machine.findAll", query = "SELECT m FROM Machine m"),
    @NamedQuery(name = "Machine.findByCode", query = "SELECT m FROM Machine m WHERE m._code = :_code"),
    @NamedQuery(name = "Machine.findByNumSerie", query = "SELECT m FROM Machine m WHERE m._numSerie = :_numSerie"),
    @NamedQuery(name = "Machine.findByAnneeFabrication", query = "SELECT m FROM Machine m WHERE m._anneeFabrication = :_anneeFabrication"),
    @NamedQuery(name = "Machine.findByMiseEnService", query = "SELECT m FROM Machine m WHERE m._miseEnService = :_miseEnService"),
    @NamedQuery(name = "Machine.findByAffectation", query = "SELECT m FROM Machine m WHERE m._affectation = :_affectation"),
    @NamedQuery(name = "Machine.findByTypeMachine", query = "SELECT m FROM Machine m WHERE m._typeMachine = :_typeMachine")})
public class Machine implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 255)
    @Column(name = "Code")
    private String _code;
    @Basic(optional = false)
    @NotNull
    @Size(min = 0, max = 255)
    @Column(name = "NumSerie")
    private String _numSerie;
    @Basic(optional = false)
    @NotNull
    @Column(name = "AnneeFabrication")
    private int _anneeFabrication;
    @Basic(optional = false)
    @NotNull
    @Column(name = "MiseEnService")
    @Temporal(TemporalType.TIMESTAMP)
    private Date _miseEnService;
    @Basic(optional = false)
    @NotNull
    @Size(min = 0, max = 255)
    @Column(name = "Affectation")
    private String _affectation;
    @Basic(optional = false)
    @NotNull
    @Size(min = 0, max = 255)
    @Column(name = "TypeMachine")
    private String _typeMachine;
    @Basic(optional = false)
    @NotNull
    @Column(name = "DateDerniereMaintenance")
    @Temporal(TemporalType.TIMESTAMP)
    private Date _dateDerniereMaintenance;
    @Basic(optional = false)
    @NotNull
    @Column(name = "DelaiMaintenance")
    private int _delaiMaintenance;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "_codeMachine", fetch = FetchType.EAGER)
    private Collection<LigneMaintenance> _ligneMaintenanceCollection;

    public Machine() {
    }

    public Machine(String code) {
        _code = code;
    }

    public Machine(String code, String numSerie, int anneeFabrication, Date miseEnService, String affectation, String typeMachine, 
            Date dateDerniereMaintenance, int delaiMaintenance) {
        _code = code;
        _numSerie = numSerie;
        _anneeFabrication = anneeFabrication;
        _miseEnService = miseEnService;
        _affectation = affectation;
        _typeMachine = typeMachine;
        _dateDerniereMaintenance = dateDerniereMaintenance;
        _delaiMaintenance = delaiMaintenance;
    }

    public String getCode() {
        return _code;
    }

    public void setCode(String code) {
        _code = code;
    }

    public String getNumSerie() {
        return _numSerie;
    }

    public void setNumSerie(String numSerie) {
        _numSerie = numSerie;
    }

    public int getAnneeFabrication() {
        return _anneeFabrication;
    }

    public void setAnneeFabrication(int anneeFabrication) {
        _anneeFabrication = anneeFabrication;
    }

    public Date getMiseEnService() {
        return _miseEnService;
    }

    public void setMiseEnService(Date miseEnService) {
        _miseEnService = miseEnService;
    }

    public String getAffectation() {
        return _affectation;
    }

    public void setAffectation(String affectation) {
        _affectation = affectation;
    }

    public String getTypeMachine() {
        return _typeMachine;
    }

    public void setTypeMachine(String typeMachine) {
        _typeMachine = typeMachine;
    }

    public Date getDateDerniereMaintenance() {
        return _dateDerniereMaintenance;
    }

    public void setDateDerniereMaintenance(Date dateDerniereMaintenance) {
        _dateDerniereMaintenance = dateDerniereMaintenance;
    }

    public int getDelaiMaintenance() {
        return _delaiMaintenance;
    }

    public void setDelaiMaintenance(int delaiMaintenance) {
        _delaiMaintenance = delaiMaintenance;
    }

    @XmlTransient
    public Collection<LigneMaintenance> getLigneMaintenanceCollection() {
        return _ligneMaintenanceCollection;
    }

    public void setLigneMaintenanceCollection(Collection<LigneMaintenance> ligneMaintenanceCollection) {
        _ligneMaintenanceCollection = ligneMaintenanceCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (_code != null ? _code.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if(!(object instanceof Machine)){
            return false;
        }
        Machine other = (Machine) object;
        if((_code == null && other._code != null) || (_code != null && !_code.equals(other._code))){
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "pckEntity.Machine[ code=" + _code + " ]";
    }
}

有人知道如何删除响应中的“u”吗?
先谢谢你。

ewm0tg9j

ewm0tg9j1#

Hope the below solutions work for you.

1. Soultion 1: using @JsonProperty("responseVariableNameHere"). For example:

@NotNull
@Size(min = 1, max = 255)
@Column(name = "Code")
@JsonProperty("code")
private String _code;

2. Use jolt transformation to convert one JSON to another JSON format.

相关问题