struts 2 json転送オブジェクト
今日struts 2非同期リクエストでバックグラウンドからフロントにオブジェクトを転送するときに小さな問題に遭遇しました.今はマークを付けて、主なコードをメモに貼り付けます.
struts.xml
UserAction
systemContactor.*systemContactorがlistの場合
システムコントローラが1つのオブジェクトである場合、なぜ直接に書くことができないのか、今でもよく分かりませんが、ここにマークしてください.うん、公式のapiを見に行く必要がある
struts.xml
<action name="getSystemContactorInfo" class="userAction" method="getSystemContactorInfo">
<result type="json">
<param name="includeProperties">systemContactor\.userName,systemContactor\.cellPhone,
systemContactor\.notesMail
</param>
<!-- <param name="includeProperties">systemContactor</param> -->
<!-- <param name="includeProperties">systemContactor.*</param> -->
</result>
</action>
UserAction
public String getSystemContactorInfo() {
UserModel systemContactor = new UserModel();
systemContactor.setUserName(" ");
systemContactor.setCellPhone("13240151465");
systemContactor.setNotesMail("[email protected]");
return Action.SUCCESS;
}
UserModel public class UserModel{
private String userName;
private String cellPhone;
private String notesMail;
// get、set
}
jspページ$.ajax({
type:'post',
url: 'getSystemContactorInfo.action',
dataType: 'json',
async: true,
success: function showContent(json) {
var userInfo = json.systemContactor;
$("#userName").html(userInfo.userName);
$("#cellPhone").html(userInfo.cellPhone);
$("#notesMail").html(userInfo.notesMail);
}
});
systemContactorsystemContactorが文字列または数字である場合、このように書くことができます.systemContactor.*systemContactorがlistの場合
システムコントローラが1つのオブジェクトである場合、なぜ直接に書くことができないのか、今でもよく分かりませんが、ここにマークしてください.うん、公式のapiを見に行く必要がある