示例#1
0
  @RequestMapping(value = "/addTodo", method = RequestMethod.POST)
  public String addContact(@ModelAttribute("todoList") TodoList todoList, BindingResult result) {

    // todoList.setContents(Contents);

    // System.out.println("Contents:" + todoList.getContents() + "Emergency:" +
    // todoList.getEmergency());
    LocalTransaction tx = AppConfig.getLocalTransaction();

    tx.begin();
    Todo todoii = new Todo();
    TodoDao dao;
    dao = new TodoDaoImpl();

    System.out.println("result = " + todoList.getId());
    todoii.Id = dao.selectAll().size() + 1;
    todoii.Contents = todoList.getContents();
    System.out.println("result1 = " + todoList.getContents());
    todoii.Emergency = Integer.parseInt(todoList.getEmergency());
    todoii.Date = java.sql.Date.valueOf(todoList.getDate());
    dao.insert(todoii);
    tx.commit();

    return "redirect:todoList.html";
  }
示例#2
0
  @ModelAttribute("todoList")
  public TodoList getTodoList() {

    TodoList todoList = new TodoList();
    System.out.println(
        "Contents:" + todoList.getContents() + "Emergency:" + todoList.getEmergency());

    return todoList;
  }
示例#3
0
  @RequestMapping("/todoList")
  public ModelAndView showTodoList() {
    TodoList todolist = new TodoList();
    Date date = new Date();
    todolist.setDate(date.toString());
    todolist.setContents("test");

    LocalTransaction tx = AppConfig.getLocalTransaction();
    List<Todo> todoAll;
    Todo todoi;

    try {
      tx.begin();
      TodoDao dao;
      dao = new TodoDaoImpl();
      todoi = dao.selectById(1);
      // todoi.Version = todoi.Version + 1;
      todoAll = dao.selectAll();
      // System.out.println("ID = " + todoi.Id);
      // todoi.Contents = "setbydao2";
      // todoi.Emergency = 1;
      todoi.Date = new java.sql.Date(System.currentTimeMillis());
      // dao.update(todoi);
      tx.commit();
    } finally {
      tx.rollback();
    }

    // 複数のモデルを返したい時はMapにぶち込む
    Map map = new HashMap();
    map.put("todoAll", todoAll);
    map.put("todoi", todoi);

    ModelAndView model = new ModelAndView("todoList", "map", map);
    return model;
  }