我有一个基本表单,我从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
}
我的人员课程是:
@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中的类型值不会更新:(
答案 0 :(得分:0)
我刚修好它,我忘了添加一个参数:
public String accountPage(@ModelAttribute("sessionBean") SessionBean sb);