日期:2014-05-20 浏览次数:20883 次
package controllers; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.util.List; import models.User; import play.data.binding.As; import play.mvc.Controller; public class Users extends Controller { public static void show(Long id) { User user = User.findById(id); render(user); } public static void create() { render(); } public static void create2File() { render(); } public static void save(User user) { user.save(); render(); } public static void upload(User user,File file) { user.save(); file.renameTo(new File("e:/abc.pdf")); render(); } public static void list() { // int page=0 ,int size=2 List users = (List) User.find("id>0 order by id desc").fetch(); // List users = (List) User.find("id>0 order by id desc").fetch(page,size); render(users); } public static void delete(Long id) { User user = User.findById(id); user.delete(); render("Users/save.html");//跳转到指定的view } public static void showJson(Long id) { User user = User.findById(id); renderJSON(user); } public static void download() { java.io.InputStream binaryData=null; try { binaryData = new FileInputStream("e:/abc.pdf"); } catch (FileNotFoundException e) { e.printStackTrace(); } renderBinary(binaryData); } }