gpt4 book ai didi

java - EXT JS 5/Spring MVC : How to bind ext js form to java object with spring mvc

转载 作者:行者123 更新时间:2023-12-01 12:36:47 24 4
gpt4 key购买 nike

我想将 ext js 表单与 Java 对象绑定(bind)。

现在我可以像这样单独绑定(bind)每个字段:

我的表格:

Ext.define('MyApp.view.login.Login', {
extend: 'Ext.window.Window',
alias: 'widget.login',

requires : ['Ext.form.Panel', 'Ext.layout.container.Fit'],

autoShow: true,
height: 200,
width: 400,
layout: 'fit',
iconCls: 'key',
title: "Login",
closeAction: 'hide',
closable: false,
draggable: false,
resizable: false,

items: [
{
xtype: 'form',
frame: false,
bodyPadding: 15,
layout: 'anchor',
defaults: {
anchor: '100%',
labelWidth: 100
},

defaultType: 'textfield',
items: [
{
name: 'user',
fieldLabel: "Login ",
allowBlank: false,
msgTarget: 'under',
emptyText: 'Login',
maxLength: 25
},
{
inputType: 'password',
name: 'password',
fieldLabel: "Password",
emptyText:'Password',
allowBlank: false,
msgTarget: 'under',
maxLength: 15,
enableKeyEvents: true,
id: 'login-password'
}
],

dockedItems: [
{
xtype: 'toolbar',
dock: 'bottom',
items: [
{
xtype: 'tbfill'
},
{
xtype: 'button',
itemId: 'cancel',
text: 'Cancel'
},
{
xtype: 'button',
itemId: 'submit',
formBind: true,
text: "Submit"
}
]
}
]
}
]
});

我的提交方法的一部分:

     loginForm.submit({
method : 'POST',
url: '/myapp/login/login.sp',
success: function(form, action) {
Ext.Msg.alert('Success', action.result.msg);
},
failure: function(form, action) {
switch (action.failureType) {
case Ext.form.action.Action.CLIENT_INVALID:
Ext.Msg.alert('Failure', 'Form fields may not be submitted with invalid values');
break;
case Ext.form.action.Action.CONNECT_FAILURE:
Ext.Msg.alert('Failure', 'Ajax communication failed');
break;
case Ext.form.action.Action.SERVER_INVALID:
Ext.Msg.alert('Failure', action.result.msg);
}
}

});

我的 Java Controller 登录方法:

@RequestMapping(value="login/login", method= RequestMethod.POST)
public void checkConnection(@RequestParam(value="user", required = true) String user, @RequestParam(value="password", required = true) String password) {
logger.info("LOGIN !!!");
}

我想要这样的东西:

@RequestMapping(value="login/login", method= RequestMethod.POST)
public void checkConnection(@Annotation LoginModel) {
logger.info("LOGIN !!!");
}

我的 LoginModel 会是这样的:

public class LoginModel {

/** User */
private String user;

/** Password */
private String password;

}

问候。

最佳答案

我相信@ModelAttribute就是您所需要的。它告诉 Spring 从模型中检索参数。

@RequestMapping(value="login/login", method= RequestMethod.POST)
public void checkConnection(@ModelAttribute LoginModel loginModel) {
logger.info("LOGIN !!!");
}

关于java - EXT JS 5/Spring MVC : How to bind ext js form to java object with spring mvc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25507354/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com