This module is view-only. You do not have an enrolement for this module.

File operations with annotations

This tutorial is based on the bandstand example application. You might want to check out the source code and experiment with it:

https://github.com/miltonio/milton2/tree/master/examples/milton-anno-bandstand

Deleting

Lets kick things off with the simplest of all the file operations, at least to understand - deleting

Just add the @Delete annotation to a method with the first argument being the thing to delete:

    @Delete
    public void deleteImage(Image image) {
        Transaction tx = SessionManager.session().beginTransaction();
        try {
            SessionManager.session().delete(image);
            SessionManager.session().flush();
            tx.commit();
        } catch (Exception e) {
            tx.rollback();
        }        
    }

From ImagesController

Note that the transaction handling in this example app isnt anything very special, you should probably do it a bit more declaratively!