• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Pet类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.springframework.samples.petclinic.model.Pet的典型用法代码示例。如果您正苦于以下问题:Java Pet类的具体用法?Java Pet怎么用?Java Pet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Pet类属于org.springframework.samples.petclinic.model包,在下文中一共展示了Pet类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: validate

import org.springframework.samples.petclinic.model.Pet; //导入依赖的package包/类
@Override
public void validate(Object obj, Errors errors) {
    Pet pet = (Pet) obj;
    String name = pet.getName();
    // name validation
    if (!StringUtils.hasLength(name)) {
        errors.rejectValue("name", "required", "required");
    }

    // type validation
    if (pet.isNew() && pet.getType() == null) {
        errors.rejectValue("type", "required", "required");
    }

    // birth date validation
    if (pet.getBirthDate() == null) {
        errors.rejectValue("birthDate", "required", "required");
    }
}
 
开发者ID:PacktPublishing,项目名称:DevOps-for-Web-Development,代码行数:20,代码来源:PetValidator.java


示例2: findById

import org.springframework.samples.petclinic.model.Pet; //导入依赖的package包/类
@Override
public Pet findById(int id) throws DataAccessException {
    JdbcPet pet;
    try {
        Map<String, Object> params = new HashMap<>();
        params.put("id", id);
        pet = this.namedParameterJdbcTemplate.queryForObject(
            "SELECT id, name, birth_date, type_id, owner_id FROM pets WHERE id=:id",
            params,
            new JdbcPetRowMapper());
    } catch (EmptyResultDataAccessException ex) {
        throw new ObjectRetrievalFailureException(Pet.class, id);
    }
    Owner owner = this.ownerRepository.findById(pet.getOwnerId());
    owner.addPet(pet);
    pet.setType(EntityUtils.getById(findPetTypes(), PetType.class, pet.getTypeId()));

    List<Visit> visits = this.visitRepository.findByPetId(pet.getId());
    for (Visit visit : visits) {
        pet.addVisit(visit);
    }
    return pet;
}
 
开发者ID:PacktPublishing,项目名称:DevOps-for-Web-Development,代码行数:24,代码来源:JdbcPetRepositoryImpl.java


示例3: shouldInsertPetIntoDatabaseAndGenerateId

import org.springframework.samples.petclinic.model.Pet; //导入依赖的package包/类
@Test
@Transactional
public void shouldInsertPetIntoDatabaseAndGenerateId() {
    Owner owner6 = this.clinicService.findOwnerById(6);
    int found = owner6.getPets().size();

    Pet pet = new Pet();
    pet.setName("bowser");
    Collection<PetType> types = this.clinicService.findPetTypes();
    pet.setType(EntityUtils.getById(types, PetType.class, 2));
    pet.setBirthDate(new LocalDate());
    owner6.addPet(pet);
    assertThat(owner6.getPets().size()).isEqualTo(found + 1);

    this.clinicService.savePet(pet);
    this.clinicService.saveOwner(owner6);

    owner6 = this.clinicService.findOwnerById(6);
    assertThat(owner6.getPets().size()).isEqualTo(found + 1);
    // checks that id has been generated
    assertThat(pet.getId()).isNotNull();
}
 
开发者ID:PacktPublishing,项目名称:DevOps-for-Web-Development,代码行数:23,代码来源:AbstractClinicServiceTests.java


示例4: validate

import org.springframework.samples.petclinic.model.Pet; //导入依赖的package包/类
@Override
public void validate(Object obj, Errors errors) {
    Pet pet = (Pet) obj;
    String name = pet.getName();
    // name validation
    if (!StringUtils.hasLength(name)) {
        errors.rejectValue("name", REQUIRED, REQUIRED);
    }

    // type validation
    if (pet.isNew() && pet.getType() == null) {
        errors.rejectValue("type", REQUIRED, REQUIRED);
    }

    // birth date validation
    if (pet.getBirthDate() == null) {
        errors.rejectValue("birthDate", REQUIRED, REQUIRED);
    }
}
 
开发者ID:PacktPublishing,项目名称:DevOps-for-Web-Development,代码行数:20,代码来源:PetValidator.java


示例5: shouldInsertPetIntoDatabaseAndGenerateId

import org.springframework.samples.petclinic.model.Pet; //导入依赖的package包/类
@Test
@Transactional
public void shouldInsertPetIntoDatabaseAndGenerateId() {
    Owner owner6 = this.clinicService.findOwnerById(6);
    int found = owner6.getPets().size();

    Pet pet = new Pet();
    pet.setName("bowser");
    Collection<PetType> types = this.clinicService.findPetTypes();
    pet.setType(EntityUtils.getById(types, PetType.class, 2));
    pet.setBirthDate(new Date());
    owner6.addPet(pet);
    assertThat(owner6.getPets().size()).isEqualTo(found + 1);

    this.clinicService.savePet(pet);
    this.clinicService.saveOwner(owner6);

    owner6 = this.clinicService.findOwnerById(6);
    assertThat(owner6.getPets().size()).isEqualTo(found + 1);
    // checks that id has been generated
    assertThat(pet.getId()).isNotNull();
}
 
开发者ID:PacktPublishing,项目名称:DevOps-for-Web-Development,代码行数:23,代码来源:AbstractClinicServiceTests.java


示例6: validate

import org.springframework.samples.petclinic.model.Pet; //导入依赖的package包/类
public void validate(Pet pet, Errors errors) {
    String name = pet.getName();
    // name validaation
    if (!StringUtils.hasLength(name)) {
        errors.rejectValue("name", "required", "required");
    } else if (pet.isNew() && pet.getOwner().getPet(name, true) != null) {
        errors.rejectValue("name", "duplicate", "already exists");
    }
    
    // type valication
    if (pet.isNew() && pet.getType() == null) {
        errors.rejectValue("type", "required", "required");
    }
    
 // type valication
    if (pet.getBirthDate()==null) {
        errors.rejectValue("birthDate", "required", "required");
    }
}
 
开发者ID:jenkinsci,项目名称:docker-workflow-plugin,代码行数:20,代码来源:PetValidator.java


示例7: findById

import org.springframework.samples.petclinic.model.Pet; //导入依赖的package包/类
@Override
public Pet findById(int id) throws DataAccessException {
    JdbcPet pet;
    try {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("id", id);
        pet = this.namedParameterJdbcTemplate.queryForObject(
                "SELECT id, name, birth_date, type_id, owner_id FROM pets WHERE id=:id",
                params,
                new JdbcPetRowMapper());
    } catch (EmptyResultDataAccessException ex) {
        throw new ObjectRetrievalFailureException(Pet.class, new Integer(id));
    }
    Owner owner = this.ownerRepository.findById(pet.getOwnerId());
    owner.addPet(pet);
    pet.setType(EntityUtils.getById(findPetTypes(), PetType.class, pet.getTypeId()));

    List<Visit> visits = this.visitRepository.findByPetId(pet.getId());
    for (Visit visit : visits) {
        pet.addVisit(visit);
    }
    return pet;
}
 
开发者ID:jenkinsci,项目名称:docker-workflow-plugin,代码行数:24,代码来源:JdbcPetRepositoryImpl.java


示例8: shouldInsertPetIntoDatabaseAndGenerateId

import org.springframework.samples.petclinic.model.Pet; //导入依赖的package包/类
@Test
@Transactional
public void shouldInsertPetIntoDatabaseAndGenerateId() {
    Owner owner6 = this.clinicService.findOwnerById(6);
    int found = owner6.getPets().size();
    
    Pet pet = new Pet();
    pet.setName("bowser");
    Collection<PetType> types = this.clinicService.findPetTypes();
    pet.setType(EntityUtils.getById(types, PetType.class, 2));
    pet.setBirthDate(new DateTime());
    owner6.addPet(pet);
    assertThat(owner6.getPets().size()).isEqualTo(found + 1);
    
    this.clinicService.savePet(pet);
    this.clinicService.saveOwner(owner6);
    
    owner6 = this.clinicService.findOwnerById(6);
    assertThat(owner6.getPets().size()).isEqualTo(found + 1);
    // checks that id has been generated
    assertThat(pet.getId()).isNotNull();
}
 
开发者ID:jenkinsci,项目名称:docker-workflow-plugin,代码行数:23,代码来源:AbstractClinicServiceTests.java


示例9: validate

import org.springframework.samples.petclinic.model.Pet; //导入依赖的package包/类
@Override
public void validate(Object obj, Errors errors) {
    Pet pet = (Pet) obj;
    String name = pet.getName();
    // name validation
    if (!StringUtils.hasLength(name)) {
        errors.rejectValue("name", "required", "required");
    } else if (pet.isNew() && pet.getOwner().getPet(name, true) != null) {
        errors.rejectValue("name", "duplicate", "already exists");
    }
    
    // type validation
    if (pet.isNew() && pet.getType() == null) {
        errors.rejectValue("type", "required", "required");
    }
    
    // birth date validation
    if (pet.getBirthDate()==null) {
        errors.rejectValue("birthDate", "required", "required");
    }
}
 
开发者ID:YoannBuch,项目名称:DependencyInjectionAgent,代码行数:22,代码来源:PetValidator.java


示例10: findById

import org.springframework.samples.petclinic.model.Pet; //导入依赖的package包/类
@Override
public Pet findById(int id) throws DataAccessException {
    JdbcPet pet;
    try {
        Map<String, Object> params = new HashMap<>();
        params.put("id", id);
        pet = this.namedParameterJdbcTemplate.queryForObject(
                "SELECT id, name, birth_date, type_id, owner_id FROM pets WHERE id=:id",
                params,
                new JdbcPetRowMapper());
    } catch (EmptyResultDataAccessException ex) {
        throw new ObjectRetrievalFailureException(Pet.class, id);
    }
    Owner owner = this.ownerRepository.findById(pet.getOwnerId());
    owner.addPet(pet);
    pet.setType(EntityUtils.getById(findPetTypes(), PetType.class, pet.getTypeId()));

    List<Visit> visits = this.visitRepository.findByPetId(pet.getId());
    for (Visit visit : visits) {
        pet.addVisit(visit);
    }
    return pet;
}
 
开发者ID:YoannBuch,项目名称:DependencyInjectionAgent,代码行数:24,代码来源:JdbcPetRepositoryImpl.java


示例11: insertPet

import org.springframework.samples.petclinic.model.Pet; //导入依赖的package包/类
@Test
@Transactional
public void insertPet() {
    Owner owner6 = this.clinicService.findOwnerById(6);
    int found = owner6.getPets().size();
    Pet pet = new Pet();
    pet.setName("bowser");
    Collection<PetType> types = this.clinicService.findPetTypes();
    pet.setType(EntityUtils.getById(types, PetType.class, 2));
    pet.setBirthDate(new DateTime());
    owner6.addPet(pet);
    assertEquals(found + 1, owner6.getPets().size());
    // both storePet and storeOwner are necessary to cover all ORM tools
    this.clinicService.savePet(pet);
    this.clinicService.saveOwner(owner6);
    owner6 = this.clinicService.findOwnerById(6);
    assertEquals(found + 1, owner6.getPets().size());
    assertNotNull("Pet Id should have been generated", pet.getId());
}
 
开发者ID:jptiancai,项目名称:spring-petclinic-study,代码行数:20,代码来源:AbstractClinicServiceTests.java


示例12: getOwnerVisits

import org.springframework.samples.petclinic.model.Pet; //导入依赖的package包/类
@RequestMapping(value = "/owner/{ownerId}/getVisits", method = RequestMethod.GET)
public ResponseEntity<List<Visit>> getOwnerVisits(@PathVariable int ownerId){
    List<Pet> petList = this.owners.findById(ownerId).getPets();
    List<Visit> visitList = new ArrayList<Visit>();
    petList.forEach(pet -> visitList.addAll(pet.getVisits()));
    return new ResponseEntity<List<Visit>>(visitList, HttpStatus.OK);
}
 
开发者ID:awslabs,项目名称:amazon-ecs-java-microservices,代码行数:8,代码来源:OwnerController.java


示例13: getOwnerVisits

import org.springframework.samples.petclinic.model.Pet; //导入依赖的package包/类
@RequestMapping(value = "/owner/{ownerId}/getVisits", method = RequestMethod.GET)
public ResponseEntity<List<Visit>> getOwnerVisits(@PathVariable int ownerId){
    List<Pet> petList = this.owners.findById(ownerId).getPets();
    List<Visit> visitList = new ArrayList<Visit>();
    petList.forEach(pet -> {
        logger.info(getPetVisits(pet.getId()).toString());
        visitList.addAll(getPetVisits(pet.getId()));
    });
    return new ResponseEntity<List<Visit>>(visitList, HttpStatus.OK);
}
 
开发者ID:awslabs,项目名称:amazon-ecs-java-microservices,代码行数:11,代码来源:OwnerController.java


示例14: getPetVisits

import org.springframework.samples.petclinic.model.Pet; //导入依赖的package包/类
private List<Visit> getPetVisits(int petId){
    List<Visit> visitList = new ArrayList<Visit>();
    RestTemplate restTemplate = new RestTemplate();
    Pet pet = restTemplate.getForObject("http://"+serviceEndpoint+"/pet/"+petId, Pet.class);
    logger.info(pet.getVisits().toString());
    return pet.getVisits();
}
 
开发者ID:awslabs,项目名称:amazon-ecs-java-microservices,代码行数:8,代码来源:OwnerController.java


示例15: initCreationForm

import org.springframework.samples.petclinic.model.Pet; //导入依赖的package包/类
@RequestMapping(value = "/pets/new", method = RequestMethod.GET)
public String initCreationForm(Owner owner, ModelMap model) {
    Pet pet = new Pet();
    owner.addPet(pet);
    model.put("pet", pet);
    return "pets/createOrUpdatePetForm";
}
 
开发者ID:PacktPublishing,项目名称:DevOps-for-Web-Development,代码行数:8,代码来源:PetController.java


示例16: processCreationForm

import org.springframework.samples.petclinic.model.Pet; //导入依赖的package包/类
@RequestMapping(value = "/pets/new", method = RequestMethod.POST)
public String processCreationForm(Owner owner, @Valid Pet pet, BindingResult result, ModelMap model) {
    if (StringUtils.hasLength(pet.getName()) && pet.isNew() && owner.getPet(pet.getName(), true) != null){
        result.rejectValue("name", "duplicate", "already exists");
    }
    if (result.hasErrors()) {
        model.put("pet", pet);
        return "pets/createOrUpdatePetForm";
    } else {
        owner.addPet(pet);
        this.clinicService.savePet(pet);
        return "redirect:/owners/{ownerId}";
    }
}
 
开发者ID:PacktPublishing,项目名称:DevOps-for-Web-Development,代码行数:15,代码来源:PetController.java


示例17: processUpdateForm

import org.springframework.samples.petclinic.model.Pet; //导入依赖的package包/类
@RequestMapping(value = "/pets/{petId}/edit", method = RequestMethod.POST)
public String processUpdateForm(@Valid Pet pet, BindingResult result, Owner owner, ModelMap model) {
    if (result.hasErrors()) {
        model.put("pet", pet);
        return "pets/createOrUpdatePetForm";
    } else {
        owner.addPet(pet);
        this.clinicService.savePet(pet);
        return "redirect:/owners/{ownerId}";
    }
}
 
开发者ID:PacktPublishing,项目名称:DevOps-for-Web-Development,代码行数:12,代码来源:PetController.java


示例18: save

import org.springframework.samples.petclinic.model.Pet; //导入依赖的package包/类
@Override
public void save(Pet pet) {
    if (pet.getId() == null) {
        this.em.persist(pet);
    } else {
        this.em.merge(pet);
    }
}
 
开发者ID:PacktPublishing,项目名称:DevOps-for-Web-Development,代码行数:9,代码来源:JpaPetRepositoryImpl.java


示例19: save

import org.springframework.samples.petclinic.model.Pet; //导入依赖的package包/类
@Override
public void save(Pet pet) throws DataAccessException {
    if (pet.isNew()) {
        Number newKey = this.insertPet.executeAndReturnKey(
            createPetParameterSource(pet));
        pet.setId(newKey.intValue());
    } else {
        this.namedParameterJdbcTemplate.update(
            "UPDATE pets SET name=:name, birth_date=:birth_date, type_id=:type_id, " +
                "owner_id=:owner_id WHERE id=:id",
            createPetParameterSource(pet));
    }
}
 
开发者ID:PacktPublishing,项目名称:DevOps-for-Web-Development,代码行数:14,代码来源:JdbcPetRepositoryImpl.java


示例20: createPetParameterSource

import org.springframework.samples.petclinic.model.Pet; //导入依赖的package包/类
/**
 * Creates a {@link MapSqlParameterSource} based on data values from the supplied {@link Pet} instance.
 */
private MapSqlParameterSource createPetParameterSource(Pet pet) {
    return new MapSqlParameterSource()
        .addValue("id", pet.getId())
        .addValue("name", pet.getName())
        .addValue("birth_date", pet.getBirthDate().toDate())
        .addValue("type_id", pet.getType().getId())
        .addValue("owner_id", pet.getOwner().getId());
}
 
开发者ID:PacktPublishing,项目名称:DevOps-for-Web-Development,代码行数:12,代码来源:JdbcPetRepositoryImpl.java



注:本文中的org.springframework.samples.petclinic.model.Pet类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java NewParticipantEvent类代码示例发布时间:2022-05-22
下一篇:
Java Augmentation类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap