java result是什么?让我们一起来了解一下吧!
java result是表示数据库结果集的数据表。它的完整英文名称是javax.servlet.jsp.jstl.sql.Result。如果要获得Result,我们应该先要获得Result,接着ResultSupport.toResult(rs)转化。
下面是如何得到result的具体步骤:
Statement stmt = con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = stmt.executeQuery("SELECT a, b FROM TABLE2"); Result rst = ResultSupport.toResult(rs);
预定义的Result比如:
1.dispatcher
它属于是实现类ServletDispatcherResult。在它的ResultType的实现中,调用了javax.servlet.RequestDispatcher类里面的forward(),
所以它的作用是跳转页面,同时通过它的跳转可以储存原来页面中request的数据信息。
2.redirect
它也是用来实现跳转到下一个页面的,与dispatcher不一样的是,它的特点是全新的请求,因此其数据信息是不同的。
实战演练,具体步骤如下:
import org.apache.commons.lang.StringUtils; import java.io.Serializable; import java.util.HashMap; import java.util.Map; public class Result extends BaseDomain implements Serializable { private String code; private String msg; private T data; private Result() { this.code = UnifyStrErrorCode.SUCCESS.getCode(); this.msg = UnifyStrErrorCode.SUCCESS.getMsg(); } private Result(T data) { this.code = UnifyStrErrorCode.SUCCESS.getCode(); this.msg = UnifyStrErrorCode.SUCCESS.getMsg(); this.setData(data); } private Result(String code, String msg) { this.code = UnifyStrErrorCode.SUCCESS.getCode(); this.msg = UnifyStrErrorCode.SUCCESS.getMsg(); this.setCode(code); this.setMsg(msg); } private Result(String code, String msg, T data) { this.code = UnifyStrErrorCode.SUCCESS.getCode(); this.msg = UnifyStrErrorCode.SUCCESS.getMsg(); this.setCode(code); this.setMsg(msg); this.setData(data); } public Result setError(String code, String msg) { this.setCode(code); this.setMsg(msg); return this; } public Result setError(UnifyStrErrorCode errorCode) { this.setCode(errorCode.getCode()); this.setMsg(errorCode.getMsg()); return this; } public boolean isSuccess() { return StringUtils.equals(this.getCode(), UnifyStrErrorCode.SUCCESS.getCode()); } public static Result instance() { return new Result(); } public static Result instance(T data) { return new Result(data); } public static Result instance(String code, String msg) { return new Result(code, msg); } public static Result instance(String code, String msg, T data) { return new Result(code, msg, data); } public String getCode() { return this.code; } public void setCode(String code) { this.code = code; } public String getMsg() { return this.msg; } public void setMsg(String msg) { this.msg = msg; } public T getData() { return this.data; } public void setData(T data) { this.data = data; } public Map toJsonMap(){ Map map = new HashMap<>(); map.put("data",this.data); map.put("msg",this.msg); map.put("code",this.code); return map; } }
以上就是小编今天的分享了,希望可以帮助到大家。