AjaxResult.java 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /*
  2. * FileName:AjaxResult.java
  3. * <p>
  4. * Copyright (c) 2017-2020, <a href="http://www.webcsn.com">hermit (794890569@qq.com)</a>.
  5. * <p>
  6. * Licensed under the GNU General Public License, Version 3 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. * <p>
  10. * http://www.gnu.org/licenses/gpl-3.0.html
  11. * <p>
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. *
  18. */
  19. package cn.com.lzt.common.util;
  20. import cn.com.lzt.core.page.Page;
  21. /**
  22. * ajax返回结果对象
  23. *
  24. * @author hermit
  25. * @date 2017 -06-10 14:11:14
  26. */
  27. public class AjaxResult {
  28. /**
  29. * 成功标识:true/false
  30. */
  31. private boolean success = false;
  32. /**
  33. * 提示信息
  34. */
  35. private String msg = "";
  36. /**
  37. * 数据对象
  38. */
  39. private Object data = null;
  40. /**
  41. * 分页对象
  42. */
  43. private Page page = null;
  44. // /**
  45. // * 其他参数(map对象)
  46. // */
  47. // private Map<String, Object> attr = new HashMap<>();
  48. /**
  49. * 设置成功标识:true/false
  50. *
  51. * @param success boolean类型
  52. * @author hermit
  53. * @date 2016 -10-09 08:59:55
  54. */
  55. public void setSuccess(boolean success) {
  56. this.success = success;
  57. }
  58. /**
  59. * 设置提示信息
  60. *
  61. * @param msg string类型
  62. * @author hermit
  63. * @date 2016 -10-09 08:59:35
  64. */
  65. public void setMsg(String msg) {
  66. this.msg = msg;
  67. }
  68. /**
  69. * 设置返回数据对象
  70. *
  71. * @param data object对象
  72. * @author hermit
  73. * @date 2016 -10-09 09:00:04
  74. */
  75. public void setData(Object data) {
  76. this.data = data;
  77. }
  78. // /**
  79. // * 其他参数(map对象)
  80. // *
  81. // * @return
  82. // * @author hermit
  83. // * @date 2016 -10-09 09:03:53
  84. // */
  85. // public Map<String, Object> getAttr() {
  86. // return attr;
  87. // }
  88. /**
  89. * 信息操作成功
  90. *
  91. * @return
  92. * @author hermit
  93. * @date 2016 -12-14 14:52:39
  94. */
  95. public static AjaxResult success() {
  96. AjaxResult result = new AjaxResult();
  97. result.setSuccess(true);
  98. result.setMsg(Constants.MSG_SUCCESS);
  99. return result;
  100. }
  101. /**
  102. * 信息操作成功
  103. *
  104. * @return
  105. * @author hermit
  106. * @date 2016 -12-14 14:52:39
  107. */
  108. public static AjaxResult success(Object data) {
  109. AjaxResult result = new AjaxResult();
  110. result.setSuccess(true);
  111. result.setData(data);
  112. result.setMsg(Constants.MSG_SUCCESS);
  113. return result;
  114. }
  115. /**
  116. * 信息操作成功
  117. *
  118. * @return
  119. * @author hermit
  120. * @date 2016 -12-14 14:52:39
  121. */
  122. public static AjaxResult success(Object data, String msg) {
  123. AjaxResult result = new AjaxResult();
  124. result.setSuccess(true);
  125. result.setData(data);
  126. result.setMsg(msg);
  127. return result;
  128. }
  129. /**
  130. * 信息保存成功
  131. *
  132. * @return
  133. * @author hermit
  134. * @date 2016 -12-14 14:52:39
  135. */
  136. public static AjaxResult saveSuccess() {
  137. AjaxResult result = new AjaxResult();
  138. result.setSuccess(true);
  139. result.setMsg(Constants.MSG_SUCCESS_SAVE);
  140. return result;
  141. }
  142. /**
  143. * 信息保存成功
  144. *
  145. * @return
  146. * @author hermit
  147. * @date 2016 -12-14 14:52:39
  148. */
  149. public static AjaxResult updateSuccess() {
  150. AjaxResult result = new AjaxResult();
  151. result.setSuccess(true);
  152. result.setMsg(Constants.MSG_SUCCESS_UPDATE);
  153. return result;
  154. }
  155. /**
  156. * 信息删除成功
  157. *
  158. * @return
  159. * @author hermit
  160. * @date 2016 -12-14 14:52:39
  161. */
  162. public static AjaxResult deleteSuccess() {
  163. AjaxResult result = new AjaxResult();
  164. result.setSuccess(true);
  165. result.setMsg(Constants.MSG_SUCCESS_DELETE);
  166. return result;
  167. }
  168. /**
  169. * 处理失败
  170. *
  171. * @return
  172. */
  173. public static AjaxResult failure() {
  174. AjaxResult result = new AjaxResult();
  175. result.setSuccess(false);
  176. return result;
  177. }
  178. /**
  179. * 处理失败
  180. *
  181. * @param msg 失败消息
  182. * @return
  183. */
  184. public static AjaxResult failure(String msg) {
  185. AjaxResult result = new AjaxResult();
  186. result.setSuccess(false);
  187. result.setMsg(msg);
  188. return result;
  189. }
  190. /**
  191. * 处理失败
  192. *
  193. * @param msg 失败消息
  194. * @param data 数据
  195. * @return
  196. */
  197. public static AjaxResult failure(String msg, Object data) {
  198. AjaxResult result = new AjaxResult();
  199. result.setSuccess(false);
  200. result.setMsg(msg);
  201. result.setData(data);
  202. return result;
  203. }
  204. public Page getPage() {
  205. return page;
  206. }
  207. public void setPage(Page page) {
  208. this.page = page;
  209. }
  210. public boolean getSuccess() {
  211. return success;
  212. }
  213. public String getMsg() {
  214. return msg;
  215. }
  216. public Object getData() {
  217. return data;
  218. }
  219. }