在spring的xml响应期间在bean名称之后获取hibernateproxy.rv3cg0fe

oyjwcjzk  于 2021-07-14  发布在  Java
关注(0)|答案(0)|浏览(227)

我正在尝试用springboot生成xml响应。在响应xml中,我没有将customer作为根节点,而是使用<customer.hibernateproxy.rv3cg0fe>而json,这工作非常好。
customerbean包com.aopexception.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@AllArgsConstructor()
@NoArgsConstructor
@Data
@Entity
@Table(name = "CUSTOMER")
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})

@XmlRootElement
public class Customer
{

    @Id
    @Column(name = "CUSTOMER_ID", unique = true)
    private Long customerId;

    @Column(name = "FIRST_NAME", length = 20)
    private String firstName;

    @Column(name = "LAST_NAME", length = 20)
    private String lastName;

    @Column(name = "ADDRESS", length = 50)
    private String address;

}

控制器包com.aopexception.controllers;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.aopexception.MyAopException;
import com.aopexception.model.Customer;
import com.aopexception.service.CustomerService;

@RestController
public class CustomerController 
{
    @Autowired(required = true)
    CustomerService customerService;

    @RequestMapping(
            path = "customer/fetch",
            method = RequestMethod.GET,  
            produces = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE}
    )
    public Customer getCustomer(@RequestParam Long id) throws MyAopException 
    {
        System.out.println("get Customer method invoked ");
        Customer customer = customerService.getCustomer(id);
        return customer;
    }
}

响应

<Customer.HibernateProxy.RV3cG0FE>
    <customerId>102</customerId>
    <firstName>admin</firstName>
    <lastName>admin</lastName>
    <address>India</address>
</Customer.HibernateProxy.RV3cG0FE>

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题