コード例 #1
0
  private void update(Employee employee) {
    String query = "update Employee set name=?, role=? where id=?";
    log.info("Executing query :: " + query);
    Object[] args = new Object[] {employee.getName(), employee.getRole(), employee.getId()};

    int out = jdbcTemplate.update(query, args);
    if (out != 0) {
      log.info("Employee updated with id=" + employee.getId());
    } else log.info("No Employee found with id=" + employee.getId());
  }
コード例 #2
0
  private void save(Employee employee) {

    String query = "insert into Employee (name, role) values (?,?)";
    log.info("Executing query :: " + query);
    Object[] args = new Object[] {employee.getName(), employee.getRole()};

    int out = jdbcTemplate.update(query, args);

    if (out != 0) {
      log.info("Employee saved with id=" + employee.getId());
    } else log.info("Employee save failed with id=" + employee.getId());
  }
コード例 #3
0
  // For add and update person both
  @RequestMapping(value = "/employee/add", method = RequestMethod.POST)
  public String addPerson(@ModelAttribute("employee") Employee p) {

    if (p.getId() == 0) {
      // new person, add it
      save(p);
    } else {
      // existing person, call update
      update(p);
    }

    return "redirect:/home";
  }