在springhibernate中使用restapi更新web服务

owfi6suc  于 2021-07-13  发布在  Java
关注(0)|答案(0)|浏览(199)

我与api的工作,我必须使更新网络服务。我试过很多方法,但都达不到预期的效果。
我的域类是;

@Entity
    @Table(name="package")
    public class Package{

        private Integer packageId;
        private String packageName;
        private String description;
        private Date validFrom;
        private Date validUpto;
        public enum Status{Active,Inactive}
        private Status status;

        @JsonBackReference
        private Set<HospitalInformation> hospitalInformation=new HashSet<HospitalInformation>();
//getters and setters

我的刀层是

@Override
    @Transactional(propagation=Propagation.REQUIRED)
    public boolean updatePackage(Integer packageId,String packageName,String description,Date validFrom,Date validUpto, Status status) throws Exception {
        Session session=sessionFactory.openSession();
        Transaction tx= session.beginTransaction();

        Package packages=hospitalDao.findByPackageId(packageId);

        if(packages!=null){
            packages.setPackageName(packageName);
            packages.setDescription(description);
            packages.setValidFrom(validFrom);
            packages.setValidUpto(validUpto);
            packages.setStatus(status);
            session.saveOrUpdate(packages);
            return true;
        }else{
            return false;
        }

我的服务层是

@Override
    public boolean updatePackageInfo(Integer packageId,String packageName,String description,Date validFrom,Date validUpto, Status status) throws Exception {

        return updateDao.updatePackage(packageId, packageName, description, validFrom, validUpto, status);
    }

我的控制器类有编译错误:

@Controller
@RequestMapping("/update")
public class UpdateRecordController {

    @Autowired
    private UpdateService updateService;

    static final Logger logger=Logger.getLogger(RestController.class);

    @RequestMapping(value="/package", method= RequestMethod.PUT,consumes=MediaType.APPLICATION_JSON_VALUE,produces=MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody Status updatePackageIfo( @RequestParam("Id") Integer Id){
        Package packages=new Package();
    try{
        if(updateService.updatePackageInfo(Id)); //Error {

            return new Status(1,"Successfylly Updated with Package Id "+packages.getPackageId());

        }else{
            return new Status(0,"Failed. Enter a valid packageId");
        }

    }catch(Exception e){
        e.printStackTrace();
        return new Status(0,e.getMessage());
    }   
    }
}

检查了所有关于更新web服务的链接后,我在google上找不到任何有用的东西。所以我需要解决如何使web服务更新。

暂无答案!

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

相关问题