日期:2014-05-20  浏览次数:20901 次

play framework log 2
1 Routes文件匹配顺序由上至下,先匹配上的即调用,匹配不上抛异常,因此CRUD模式的/Objects/{id},需要配置id的正则表达式,否则/Objects/list、create会出现异常。
2 各种情况,自己看吧
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);
	}
}