Add update/delete to the web-ui sample

Closes gh-4735
See gh-4733
pull/4703/merge
kozazz 9 years ago committed by Phillip Webb
parent ffbdfc586b
commit 0de4b6ce63

@ -50,4 +50,9 @@ public class InMemoryMessageRepository implements MessageRepository {
return this.messages.get(id);
}
@Override
public void deleteMessage(Long id) {
this.messages.remove(id);
}
}

@ -24,4 +24,6 @@ public interface MessageRepository {
Message findMessage(Long id);
void deleteMessage(Long id);
}

@ -30,6 +30,7 @@ import org.springframework.web.servlet.mvc.support.RedirectAttributes;
/**
* @author Rob Winch
* @author Doo-Hwan Kwak
*/
@Controller
@RequestMapping("/")
@ -73,4 +74,16 @@ public class MessageController {
throw new RuntimeException("Expected exception in controller");
}
@RequestMapping(value = "delete/{id}")
public ModelAndView delete(@PathVariable("id") Long id) {
this.messageRepository.deleteMessage(id);
Iterable<Message> messages = this.messageRepository.findAll();
return new ModelAndView("messages/list", "messages", messages);
}
@RequestMapping(value = "modify/{id}", method = RequestMethod.GET)
public ModelAndView modifyForm(@PathVariable("id") Message message) {
return new ModelAndView("messages/form", "message", message);
}
}

@ -26,6 +26,10 @@
Messages
</a>
</div>
<input type="hidden"
th:field="*{id}"
th:class="${#fields.hasErrors('id')} ? 'field-error'"
/>
<label for="summary">Summary</label>
<input type="text"
th:field="*{summary}"
@ -35,7 +39,7 @@
th:field="*{text}"
th:class="${#fields.hasErrors('text')} ? 'field-error'"></textarea>
<div class="form-actions">
<input type="submit" value="Create"/>
<input type="submit" value="Save"/>
</div>
</form>
</div>

@ -37,6 +37,17 @@
A detailed message that is longer than the summary.
</dd>
</dl>
<div class="pull-left">
<a href="messages"
th:href="@{'/delete/' + ${message.id}}">
delete
</a>
|
<a href="form.html"
th:href="@{'/modify/' + ${message.id}}">
modify
</a>
</div>
</div>
</body>
</html>
Loading…
Cancel
Save