我在春天遇到动态表单的问题.在我们的表单中,我们想要指定标题,并添加一些问题.我们有一个"添加"按钮,用于使用jquery添加问题输入表单.
我们的表格在要求时有一个问题栏.每次按下"添加"按钮时,都会添加额外的字段.提交时似乎没有提交额外的字段(第一个字段是由控制器接收的).为什么没有收到额外的字段?
我大致基于这个动态绑定列表示例的代码.
我的模型包括一个"报告"类,它有一个"标题"和一个"研究问题"列表.
下面是两个模型类的简短版本.Roo照顾所有的吸气者和制定者
@Entity
@RooJavaBean
@RooEntity
public class Report{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private Long id;
@NotEmpty
private String title;
@OneToMany(mappedBy="report")
private List<Researchquestion> researchquestions;
}
@Entity
@RooJavaBean
@RooEntity
public class Researchquestion {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private Long id;
@NotEmpty
private String question;
}
Run Code Online (Sandbox Code Playgroud)
这里是表单的jspx
<div xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:form="http://www.springframework.org/tags/form"
xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:fn="http://java.sun.com/jsp/jstl/functions"
xmlns:spring="http://www.springframework.org/tags"
version="2.0">
<jsp:output omit-xml-declaration="yes"/>
<spring:url value="/admin/report/appendquestion" var="insert_url"/>
<script type="text/javascript">
$(document).ready(function() {
var questionPosition = 0;
$("#addQuestionButton").click(function() {
questionPosition++; …Run Code Online (Sandbox Code Playgroud) 考虑下面的收藏夹表对象,我们想要编写一个查询来按类型查找收藏夹(在下面定义).我们还定义了一个Typemapper,将FavoriteType映射到数据库的String
import scala.slick.driver.PostgresDriver.simple._
//Other imports have been omitted in this question
object Favorites extends Table[Favorite]("favorites") {
// Convert the favoriteTypes to strings for the database
implicit val favoriteMapping: TypeMapper[FavorietType] = MappedTypeMapper.base[FavorietType, String](
favType => FavorietType.values.find(_ == favType).get.mapping,
mapping => FavorietType.values.find(_.mapping == mapping).get
)
def favoriteType = column[FavoriteType]("type")
//other columns here
Run Code Online (Sandbox Code Playgroud)
这是我想写的查询(但是它不能编译)
def queryByFavoriteType(ftype : FavoriteType)(implicit s: Session) = {
for(
f <- Favorieten if f.favoriteType === ftype
) yield f
}
}
Run Code Online (Sandbox Code Playgroud)
在这里,我定义了不同的FavoriteType对象(这是在Favorieten对象之外)
sealed case class FavorietType(mapping: String) {
override …Run Code Online (Sandbox Code Playgroud)