不使用获取请求将数据发送到服务器

时间:2019-09-23 18:35:18

标签: java mysql json spring-mvc

我尝试通过Restlet将获取请求发送到服务器(http://localhost:9999/ad/ad/get/41),但它不发送任何数据。 不明白原因

AdController类

@RestController
@RequestMapping("ad")
public class AdController {
@Autowired
private AdService<Ad> adService;

@GetMapping("/get/{id}")
public Ad get(@PathVariable int id) {
    return adService.getById(id);
}

MysqlAdDAO类

@Repository
@Transactional
public class MysqlAdDAO implements AdDAO {

@PersistenceContext
private EntityManager em;

@PersistenceUnit
private EntityManagerFactory emf;

@Override
public Ad getById(int id) {
    return em.find(Ad.class, id);
}

类广告

@Entity
public class Ad {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "ad_id")
private int id;
private String name;
private Date date;
private String text;
@Column(name = "price", precision = 10, scale = 2)
private BigDecimal price;

@ManyToOne
@JoinColumn(name = "author_fk_id")
private Author author;

@ManyToOne
@JoinColumn(name = "category_fk_id")
private Category category;


public Ad(String name, Date date, String text, BigDecimal price, Author 
author, Category category) {
    this.name = name;
    this.date = date;
    this.text = text;
    this.price = price;
    this.author = author;
    this.category = category;
}

public Ad() { }
......
}

我希望它以具有给定ID的广告的形式返回我的结果

0 个答案:

没有答案