如何根据我选择的选项在三个不同的实体中保存我的表单数据

时间:2016-04-12 08:39:21

标签: playframework playframework-2.0

我是使用Play框架的新手,我希望根据我选择的选项在三个不同的实体中发送我的表单数据。您的帮助将不胜感激。

@main("Add form"){
   @if(flash.containsKey("Success")){
       @flash.get("success");
   }
   @if(flash.containsKey("error")){
       @flash.get("error");
   }
    <form action="@routes.Application.saveAirtel()" method="post">
        Phone number :<input type="text" name="phoneNumber" class="form-control"><br />
            <select type="text" name="user" class="form-control"> <option>A</option>
                <option>B</option>
                <option>C</option></select>

        <button type="submit">Save aitel</button </form>}

这是我的模特:

@Entity 公共类Customer_one扩展了Model {

@Id
public Long id;

@Required
public int phoneNumber;

@Required
public String user ;


java.util.Date date= new java.util.Date();

public static Finder<Long, Customer_one> find = new Finder(Long.class, Customer_one.class);

public static String save(Customer_one customer) {
    try {
        Customer_one customer1 = new Customer_one();

        customer1.user = customer.user;

        customer1.save();
        return Message.saveSuccess;
    } catch (Exception e) {
      return Message.saveError;
    }
}

控制器:

public static Result sell_airtime() {


    Form<Customer_one> formData_one = Form.form(Customer_one.class).bindFromRequest();

   if (selectedOption = A){

  Do something ....


  }
  }

1 个答案:

答案 0 :(得分:0)

您的Twirl模板需要进行一些更正:

改变这个:

<select type="text" name="user" class="form-control">
    <option>A</option>
    <option>B</option>
    <option>C</option>
</select>

对此:

<select name="user" class="form-control">
    <option value="A">A</option>
    <option value="B">B</option>
    <option value="C">C</option>
</select>

没有为HTML type tag定义<select>属性。您还必须指定发送到服务器的value标记的<option>