use of com.blade.mvc.http.Request in project tale by otale.
the class Theme method articles.
/**
* 分页
*
* @param limit
* @return
*/
public static Page<Contents> articles(int limit) {
Request request = WebContext.request();
Integer page = request.attribute("page_num");
page = null == page ? request.queryInt("page", 1) : page;
page = page < 0 || page > TaleConst.MAX_PAGE ? 1 : page;
Page<Contents> articles = select().from(Contents.class).where(Contents::getType, Types.ARTICLE).and("status", Types.PUBLISH).order(Contents::getCreated, OrderBy.DESC).page(page, limit);
request.attribute("articles", articles);
if (page > 1) {
WebContext.request().attribute("title", "第" + page + "页");
}
request.attribute("is_home", true);
request.attribute("page_prefix", "/page");
return articles;
}
use of com.blade.mvc.http.Request in project blade by biezhi.
the class RouteActionArguments method getQueryParam.
private static Object getQueryParam(ParamStruct paramStruct) {
Param param = paramStruct.param;
String paramName = paramStruct.paramName;
Type argType = paramStruct.argType;
Request request = paramStruct.request;
if (null == param) {
return null;
}
String name = StringKit.isBlank(param.name()) ? paramName : param.name();
if (ReflectKit.isBasicType(argType) || argType.equals(Date.class) || argType.equals(BigDecimal.class) || argType.equals(LocalDate.class) || argType.equals(LocalDateTime.class) || (argType instanceof Class && ((Class) argType).isEnum())) {
String value = request.query(name).orElseGet(() -> getDefaultValue(param.defaultValue(), argType));
return ReflectKit.convert(argType, value);
} else {
if (ParameterizedType.class.isInstance(argType)) {
List<String> values = request.parameters().get(param.name());
return getParameterizedTypeValues(values, argType);
}
return parseModel(ReflectKit.typeToClass(argType), request, param.name());
}
}
use of com.blade.mvc.http.Request in project blade by biezhi.
the class RouteActionArguments method getBodyParam.
private static Object getBodyParam(ParamStruct paramStruct) {
Type argType = paramStruct.argType;
Request request = paramStruct.request;
if (ReflectKit.isPrimitive(argType)) {
return ReflectKit.convert(argType, request.bodyToString());
} else {
String json = request.bodyToString();
return StringKit.isNotEmpty(json) ? JsonKit.formJson(json, argType) : null;
}
}
use of com.blade.mvc.http.Request in project blade by biezhi.
the class RouteActionArguments method getPathParam.
private static Object getPathParam(ParamStruct paramStruct) {
Type argType = paramStruct.argType;
PathParam pathParam = paramStruct.pathParam;
String paramName = paramStruct.paramName;
Request request = paramStruct.request;
String name = StringKit.isEmpty(pathParam.name()) ? paramName : pathParam.name();
String val = request.pathString(name);
if (StringKit.isBlank(val)) {
val = pathParam.defaultValue();
}
return ReflectKit.convert(argType, val);
}
use of com.blade.mvc.http.Request in project blade by biezhi.
the class RouteActionArguments method getCookie.
private static Object getCookie(ParamStruct paramStruct) throws BladeException {
Type argType = paramStruct.argType;
CookieParam cookieParam = paramStruct.cookieParam;
String paramName = paramStruct.paramName;
Request request = paramStruct.request;
String cookieName = StringKit.isEmpty(cookieParam.value()) ? paramName : cookieParam.value();
String val = request.cookie(cookieName);
if (null == val) {
val = cookieParam.defaultValue();
}
return ReflectKit.convert(argType, val);
}
Aggregations