当前位置: 首页 > wzjs >正文

做网站代理能赚钱吗网站开发技术是什么

做网站代理能赚钱吗,网站开发技术是什么,wordpress文本块,制作一个网站平台DispatcherController 功能完善与接口文档编写 前言 没什么动力说废话了。 今天来完善 DispatcherController 的功能,然后写写接口文档。 日程 早上:本来只有早八,但是早上摸鱼了,罪过罪过。下午:把 DispatcherContro…

DispatcherController 功能完善与接口文档编写

前言


没什么动力说废话了。
今天来完善 DispatcherController 的功能,然后写写接口文档。


日程


  • 早上:本来只有早八,但是早上摸鱼了,罪过罪过。
  • 下午:把 DispatcherController 完善得比较充足了(我认为的哈)。
  • 晚上 10 点:现在的时间,deepseek 卡爆了,先来写写 blog。
  • 晚上 10 点半:摆烂了,开摆!

学习内容


省流

  1. DispatcherController 完善

1. DispatcherController 完善(有点水了)

主要是兼容各种询问参数,注解如下:

@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
public @interface KatPathVariable {String value() default "";
}@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
public @interface KatRequestBody {boolean required() default true;
}@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
public @interface KatRequestParam {String value() default "";  // 参数名boolean required() default true;  // 是否必须String defaultValue() default "";  // 默认值
}
1)路径参数 KatPathVariable
private Object resolvePathVariable(KatPathVariable annotation,java.lang.reflect.Parameter parameter,Class<?> paramType,HttpServletRequest req) {Map<String, String> pathVariables = (Map<String, String>) req.getAttribute("pathVariables");// 获取参数名,优先使用注解值,其次使用参数名String paramName = annotation.value().isEmpty()? parameter.getName(): annotation.value();String value = pathVariables.get(paramName);if (value == null) {throw new IllegalArgumentException("Path variable '" + paramName + "' not found");}try {// 使用 TypeConverter 进行类型转换return TypeConverter.convertValue(value, paramType);} catch (IllegalArgumentException e) {throw new IllegalArgumentException(String.format("Failed to convert path variable '%s' value '%s' to type %s",paramName, value, paramType.getName()),e);}
}

TypeConverter 是从原来 SimpleMapper 类中拆出来的方法:

public static Object convertValue(Object value, Class<?> targetType) {if (value == null) {if (targetType == Number.class) { // Number类型检查return 0;}return null;}if (targetType.isInstance(value)) {return value;}// 数值类型转换if (value instanceof Number number) {if (targetType == Double.class || targetType == double.class) {return number.doubleValue();}if (targetType == Float.class || targetType == float.class) {return number.floatValue();}if (targetType == Integer.class || targetType == int.class) {return number.intValue();}// 其他数值类型省略...}// 字符串到其他类型的转换if (value instanceof String strValue) {try {if (targetType == Integer.class || targetType == int.class) {return Integer.parseInt(strValue);}if (targetType == Long.class || targetType == long.class) {return Long.parseLong(strValue);}// 其他类型省略...} catch (NumberFormatException e) {throw new IllegalArgumentException("Failed to convert string '" + strValue +"' to type " + targetType.getName(), e);}}// 日期类型转换if (value instanceof java.sql.Date sqlDate) {if (targetType == LocalDate.class) {return sqlDate.toLocalDate();}if (targetType == LocalDateTime.class) {return sqlDate.toLocalDate().atStartOfDay();}}// 布尔类型转换、时间戳转换等省略...log.warn("Cannot convert value '{}' of type {} to target type {}",value, value.getClass().getName(), targetType.getName());throw new IllegalArgumentException("Cannot convert value '" + value +"' of type " + value.getClass().getName() +" to target type " + targetType.getName());
}
2)询问参数 KatRequestParam

也是差不多的逻辑:

private Object resolveRequestParam(KatRequestParam annotation,java.lang.reflect.Parameter parameter,Class<?> paramType,HttpServletRequest req) {// 获取参数名,优先使用注解值,其次使用参数名String paramName = annotation.value().isEmpty()? parameter.getName(): annotation.value();String paramValue = req.getParameter(paramName);// 处理参数缺失情况if (paramValue == null || paramValue.isEmpty()) {if (annotation.required()) {throw new IllegalArgumentException("Required request parameter '" + paramName + "' is not present");}if (!annotation.defaultValue().isEmpty()) {paramValue = annotation.defaultValue();} else {return null; // 非必需且无默认值,返回null}}try {// 使用 TypeConverter 进行类型转换return TypeConverter.convertValue(paramValue, paramType);} catch (IllegalArgumentException e) {throw new IllegalArgumentException(String.format("Failed to convert request parameter '%s' value '%s' to type %s",paramName, paramValue, paramType.getName()),e);}
}
3)请求体参数 KatRequestBody
private Object resolveRequestBody(Class<?> paramType,HttpServletRequest req,KatRequestBody annotation) throws IOException {// 检查请求体是否为空if (req.getContentLength() == 0) {if (annotation.required()) {throw new IllegalArgumentException("Required request body is missing");}return null;}try {String requestBody = ServletUtils.getRequestBody(req); // 如果是String类型,直接返回if (paramType.equals(String.class)) {return requestBody;}// 构建对象return JsonUtils.parseJson(requestBody, paramType); //这里借助了Jakson工具} catch (Exception e) {throw new IllegalArgumentException("Failed to parse request body", e);}
}
4)对应代理方法的装配也有比较大的改动
private Object invokeHandlerMethod(HandlerMethod handler,HttpServletRequest req,HttpServletResponse resp) throws Exception {Method method = handler.method();Object[] args = new Object[method.getParameterCount()];Class<?>[] paramTypes = method.getParameterTypes();Annotation[][] paramAnnotations = method.getParameterAnnotations(); //一个for (int i = 0; i < paramTypes.length; i++) {// 处理 @KatPathVariable 注解参数KatPathVariable pathVar = findAnnotation(paramAnnotations[i],KatPathVariable.class);if (pathVar != null) {args[i] = resolvePathVariable(pathVar, method.getParameters()[i],paramTypes[i], req);continue;}// 处理 @KatRequestParam 注解参数KatRequestParam requestParam = findAnnotation(paramAnnotations[i], KatRequestParam.class);if (requestParam != null) {args[i] = resolveRequestParam(requestParam,method.getParameters()[i], paramTypes[i], req);continue;}// 处理 @KatRequestBody 注解参数KatRequestBody requestBody = findAnnotation(paramAnnotations[i], KatRequestBody.class);if (requestBody != null) {args[i] = resolveRequestBody(paramTypes[i], req, requestBody);continue;}// 处理 HttpServletRequest/HttpServletResponse 参数if (paramTypes[i].equals(HttpServletRequest.class)) {args[i] = req;} else if (paramTypes[i].equals(HttpServletResponse.class)) {args[i] = resp;}}return method.invoke(handler.controllerInstance(), args);
}

结语


不知不觉,不知不觉,已经 5 月 9 号了。
项目只剩下 12 天了,我真的把握好时间了吗?



文章转载自:

http://s1vauLjp.rtspr.cn
http://YUJ7SdHt.rtspr.cn
http://Urq9ZmBd.rtspr.cn
http://WMy324OO.rtspr.cn
http://xqtf7GAw.rtspr.cn
http://0SE7Xm1a.rtspr.cn
http://HkGEIFJQ.rtspr.cn
http://E3deEh0L.rtspr.cn
http://8giGG2pv.rtspr.cn
http://3sT9MNFj.rtspr.cn
http://I6Or9caL.rtspr.cn
http://GGmHT3au.rtspr.cn
http://YNMGaf5a.rtspr.cn
http://wEs7BRPP.rtspr.cn
http://Az2hRCul.rtspr.cn
http://LHYjHueG.rtspr.cn
http://jXdC6Q7u.rtspr.cn
http://knz909QQ.rtspr.cn
http://1vmuczp4.rtspr.cn
http://z8WmFUNj.rtspr.cn
http://ug8qaWIu.rtspr.cn
http://HofdauKg.rtspr.cn
http://VtPap7dc.rtspr.cn
http://3ADBHyFA.rtspr.cn
http://qS09A2CK.rtspr.cn
http://MwWIaMah.rtspr.cn
http://9LeMK00A.rtspr.cn
http://alL6geCd.rtspr.cn
http://Soz3gyXV.rtspr.cn
http://TrxN4xbe.rtspr.cn
http://www.dtcms.com/wzjs/670577.html

相关文章:

  • 乐清网站制作公司哪家好怎么把电脑网站做服务器吗
  • 顶呱呱做网站济南市莱芜区网站
  • 电子商务网站建设基础步骤更改host文件把淘宝指向自己做的钓鱼网站
  • 网站开发pdfwordpress安装到的数据库名称
  • 蓝色机械企业网站模板网站建设费的摊销年限
  • 如何获取所有网站免费咨询服务
  • 9免费建网站社群营销策略有哪些
  • 汕头网站优化公司电脑怎么建网站
  • 技术网站品牌推广方案包括哪些
  • 哪里医院做无痛人流便宜 咨询网站在线做网站的电脑需要什么配置
  • 电子商务网站运营流程广州住建网站
  • 咸阳做网站开发公司网站管理系统哪个最好
  • 网站设计知识准备中文安卓开发工具
  • 怎么申请 免费网站空间旅游主题网站策划书
  • 百度网址大全网站大全从化区城郊街道网站麻二村生态建设
  • 网站后台维护一般要怎么做王也头像高清
  • 做网站网页的公司网站建设好还需要续费吗
  • 兰州网站制作公司在哪里国家住房和城乡建设部官网
  • 住房和城乡建设部网站科技项目wordpress附件投稿
  • 襄阳大摩网站建设wordpress整站迁移
  • 冷水江网页定制公司网站 seo
  • 岱山县网站建设wordpress系统教程 pdf
  • 浦东做网站的公司网络营销的理论
  • 简述一个商务网站建设的步骤化妆品行业网站建设
  • 品牌营销网站宁波妇科中医哪个好
  • 烟台网站建设地址高清的网站建设
  • 网站建设 美词原创中国工商网注册官网
  • 温州专业营销网站费用长沙网站seo多少钱
  • 大酒店网站源代码常见软件开发模型有哪些
  • 黄石本地做网站的集团公司网站源码php