初学play框架遇到问题,求大神指教

向往那一亩绿叶田 2016-07-17 06:58:15
Application类
package controllers;

import model.Task;
import play.data.Form;
import play.mvc.*;

public class Application extends Controller {

static Form<Task> taskForm = Form.form(Task.class);

public static Result index() {
//return ok(index.render("Your new application is ready."));
return redirect(routes.Application.tasks());
}


public static Result tasks(){
return ok(views.html.index.render(Task.all(),taskForm));
}

public static Result newTask(){
Form<Task> filledForm = taskForm.bindFromRequest();
if(filledForm.hasErrors()){
return badRequest(
views.html.index.render(Task.all(),filledForm)
);
}else{
Task.create(filledForm.get());
return redirect(routes.Application.tasks());
}
}

public static Result deleteTask(Integer id){
Task.delete(id);
return redirect(routes.Application.tasks());
}
}


Task类
package model;

import java.util.List;
import javax.persistence.*;
import play.data.validation.Constraints.*;
import play.db.ebean.*;

@Entity
@Table(name="task")
public class Task extends Model{

private static final long serialVersionUID = 1L;
@Id
public Integer id;
@Required
public String label;

public static Finder<Integer,Task> find = new Finder<Integer,Task>(Integer.class,Task.class);

public static List<Task> all(){
return find.all();
}

public static void create(Task task){
task.save();
}

public static void delete(Integer id){
find.ref(id).delete();
}
}


routes文件内容
# Routes
# This file defines all application routes (Higher priority routes first)
# ~~~~

# Home page
GET / controllers.Application.index()

# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.at(path="/public", file)


# Tasks
GET /tasks controllers.Application.tasks()
POST /tasks controllers.Application.newTask()
POST /tasks/:id/delete controllers.Application.deleteTask(id: Integer)


application.conf文件内容
# This is the main configuration file for the application.
# ~~~~~

# Secret key
# ~~~~~
# The secret key is used to secure cryptographics functions.
# If you deploy your application to several instances be sure to use the same key!
application.secret="Xte]]5>ggfU1@MCpV9]HP7yhB?@OwH4yU>ZkosmNgyEnLr18lGIl2::@3;rpraYM"

# The application languages
# ~~~~~
application.langs="en"

# Global object class
# ~~~~~
# Define the Global object class for this application.
# Default to Global in the root package.
# application.global=Global

# Router
# ~~~~~
# Define the Router object to use for this application.
# This router will be looked up first when the application is starting up,
# so make sure this is the entry point.
# Furthermore, it's assumed your route file is named properly.
# So for an application router like `conf/my.application.Router`,
# you may need to define a router file `my.application.routes`.
# Default to Routes in the root package (and `conf/routes`)
# application.router=my.application.Routes

# Database configuration
# ~~~~~
# You can declare as many datasources as you want.
# By convention, the default datasource is named `default`
#
db.default.driver=com.mysql.jdbc.Driver
db.default.url="jdbc:mysql://127.0.0.1:3306/play"
db.default.user=root
db.default.password="123456"
#
# You can expose this datasource via JNDI if needed (Useful for JPA)
# db.default.jndiName=DefaultDS

# Evolutions
# ~~~~~
# You can disable evolutions if needed
evolutionplugin=disabled

# Ebean configuration
# ~~~~~
# You can declare as many Ebean servers as you want.
# By convention, the default server is named `default`
#
ebean.default="models.*"

# Logger
# ~~~~~
# You can also configure logback (http://logback.qos.ch/),
# by providing an application-logger.xml file in the conf directory.

# Root logger:
logger.root=ERROR

# Logger used by the framework:
logger.play=INFO

# Logger provided to your application:
logger.application=DEBUG



index.scala.html 内容

@(tasks: List[model.Task] , taskForm: Form[model.Task])

@import helper._
@main("Welcome to Play") {

<h1>@tasks.size() task(s)</h1>
<ul>
@for(task <- tasks){
<li>
@task.label
@form(routes.Application.deleteTask(task.id)){
<input type="submit" value= "删除"/>
}
</li>
}
</ul>


<h2>增加一个内容</h2>

@form(routes.Application.newTask()){
@inputText(taskForm("label"))

<input type="submit" value="创建"/>
}

}

出现下面错误,



明明加了@Entity 为什么还出现这个问题,求解
...全文
438 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
lrjin_csdn 2016-08-10
  • 打赏
  • 举报
回复
Task 需对应数据库字段
  • 打赏
  • 举报
回复
啊啊啊怎么没人回答
  • 打赏
  • 举报
回复
在线等啊
DM平台,不仅仅是一个netcore后台开发框架,他也是一个企业级快速开发解决方案。只用拖拉和编写一些简单的JavaScript即可实现业务功能创建和复杂的逻辑关系,能让初学者更快的入门并投入到团队的项目开发中去。让开发者注重专注业务,其余有平台来封装技术细节,降低技术难度,从而节省人力成本,缩短项目周期,提高软件安全质量。DM平台是作者和自己的开发团队结合了多年开发经验,以及各方面的应用案例,把多个开源框架的优势和特殊功能集中进行优中选优,进行了二次开发后,完成了一次全部重构,也纳入很多新的思想。不管是从开发者模式、底层架构、逻辑处理还是到用户界面,用户交互体验上都有了与众不同、独竖一帜的表现,集百家之长成自家之源。努力为大中小微企业打造全方位企业级快速开发解决方案。零代码开发是指开发简单功能模块时可一键生成无须代码,如果开发复杂模块只需学习DM平台的插件功能,书写JavaScript代码调用相关Api函数即可实现,对程序初学者可快速入门并参与项目开发。在表单设计、视图设计、审批流程等方面DM平台采用可视化操作,所见即所得;平台采用NetCore框架开源,支持前后端分离,具有可运行在国外国内系统的跨平台性;平台支持多语言、多币种,可以后台直接配置即可;

3,422

社区成员

发帖
与我相关
我的任务
社区描述
其他开发语言 其他开发语言
社区管理员
  • 其他开发语言社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧