0
我有一個基本形式,我從sessionBean.person.xxxxx了我的價值觀(所以一切正常):映射彈簧形式會話對象
<form:form action="account" method="post" class="form-horizontal" modelAttribute="sessionBean.person">
<!-- some form input elements like -->
<label class="col-sm-3 control-label">E-mail</label><div class="col-md-4"><form:input cssClass="form-control" path="email" maxlength="64" /></div>
<!-- submit button -->
</form:form>
和控制器:
@Controller
@SessionAttributes("sessionBean")
public class AccountController {
@Autowired
private SessionBean sessionBean;
/** Display account page and process updates: password, personnal information, company, delivery and billing addresses
* @return JSP name
*/
@RequestMapping("/account")
public String accountPage(/* request params */) {
//checks not displayed
Person p=sessionBean.getPerson();
s.createQuery("UPDATE Person SET tittle=:t, firstname=:fn, lastname=:ln, phone=:p, fax=:f, email=:e WHERE id=:id")
.setParameter(":t", p.getTitle())
.setParameter(":fn", p.getFirstname())
.setParameter(":ln", p.getLastname())
.setParameter(":p", p.getPhone())
.setParameter(":f", p.getFax())
.setParameter(":e", p.getEmail())
.setParameter(":id", p.getId())
.executeUpdate();
}
}
的一個sessionBean是:
@Component
@Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
public class SessionBean implements Serializable {
private static final long serialVersionUID = 9139554982970790165L;
private final String id = UUID.randomUUID().toString();
private Person person = null;
private String redirect=null;
private Order3d order3d=new Order3d();
//getter and setters
}
我的Person類是:
@Entity
@Table (name="person")
public class Person implements Serializable {
private static final long serialVersionUID = 3005461811554821039L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column (name="id")
private int id;
@Column (name="email")
private String email;
@Column (name="company")
private String company;
@Column (name="siret")
private long siret;
@Column (name="payment")
private String payment;
@Column (name="title")
private String title;
@Column (name="firstname")
private String firstname;
@Column (name="lastname")
private String lastname;
@Column (name="password", columnDefinition="char", length=64)
private String password;
@Column (name="phone")
private String phone;
@Column (name="fax")
private String fax;
}
當我得到我的Person對象在我的控制器,不更新sessionBean.peron類型的值:(
你能填寫你傳遞給'accountPage()'的什麼值? – CodeChimp
另外,我不確定「typed values」是什麼意思。你是不是說在表單中編輯的'Person'的屬性都沒有更新? – CodeChimp