正しい JSON 応答を提供するモデル駆動型 Struts2 アクションがあります。アクションを再構成すると、空の JSON 応答が返されます。Struts2 のモデル駆動型アクションで継承を行っている人はいますか?
Struts config に include プロパティを明示的に設定しようとしました:
<結果名="json" タイプ="json"> <param name="includeProperties"> jsonResponse </param> </結果>
以下のすべてのアクションのコード - 実際に使用されているコードではありません - わかりやすくするために編集して削除しました。
前もって感謝します。
正しい応答を提供するアクション:
public class Bike extends ActionSupport implement ModelDriven, Preparable { @Autowired プライベート サービス bikeService; プライベート JsonResponse jsonResponse; プライベート com.ets.model.Vehicle バイク; プライベート int id; 公共バイク() { jsonResponse = new JsonResponse("バイク"); } @オーバーライド public void prepare() は例外をスローします { もし (id == 0) { 自転車 = 新しい com.ets.model.Bike(); } そうしないと { 自転車 = 自転車サービス.find(id); } } @オーバーライド public Object getModel() { 自転車を返す; } public void setId(int id) { this.id = id; } public void setBikeService(@Qualifier("bikeService") Service bikeService) { this.bikeService = bikeService; } public JsonResponse getJsonResponse() { jsonResponse を返します。 } パブリック文字列の削除(){ 試す { bike.setDeleted(new Date(System.currentTimeMillis())); bikeService.updateOrSave(バイク); jsonResponse.addActionedId(id); jsonResponse.setAction("削除"); jsonResponse.setValid(真); } catch (例外例外) { jsonResponse.setMessage(exception.toString()); } 「json」を返します。 } }
正しくない応答を提供する再構成されたアクション:
public abstract class Vehicle extends ActionSupport implement ModelDriven { @Autowired 保護されたサービス @Autowired 保護されたサービス carService; 保護された JsonResponse jsonResponse; 保護された com.ets.model.Vehicle 車両; 保護された int id; 保護された抽象サービス service(); @オーバーライド public Object getModel() { 自転車を返す; } public void setId(int id) { this.id = id; } public void setBikeService(@Qualifier("bikeService") Service bikeService) { this.bikeService = bikeService; } public void setCarService(@Qualifier("carService") Service carService) { this.carService = carService; } public JsonResponse getJsonResponse() { jsonResponse を返します。 } パブリック文字列の削除(){ 試す { vehicle.setDeleted(new Date(System.currentTimeMillis())); service().updateOrSave(車両); jsonResponse.addActionedId(id); jsonResponse.setAction("削除"); jsonResponse.setValid(真); } catch (例外例外) { jsonResponse.setMessage(exception.toString()); } 「json」を返します。 } } public class Bike extends Vehicle implements Preparable { 公共バイク() { jsonResponse = new JsonResponse("バイク"); } @オーバーライド public void prepare() は例外をスローします { もし (id == 0) { 車両 = 新しい com.ets.model.Bike(); } そうしないと { vehicle = bikeService.find(id); } } @オーバーライド 保護されたサービス service() { 返却自転車サービス; } } public class Car extends Vehicle implements Preparable { 公共の車() { jsonResponse = new JsonResponse("車"); } @オーバーライド public void prepare() は例外をスローします { もし (id == 0) { 車両 = 新しい com.ets.model.Car(); } そうしないと { 車両 = carService.find(id); } } @オーバーライド 保護されたサービス service() { 帰りの車サービス; } }