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

Java学习日记_廖万忠

Java学习日记_廖万忠

关联关系(双向关联,前向关联:多对一较多,看表中的字段,页面的数据关联的情况)

实体的类型尽量用包装类型,防止nll赋值出现异常,基本类型一般用在运算中,效率高。    

13. 有用的工具:自定义通用工具,用在不用框架的web开发

CommonUtils:

public class CommonUtils

/返回32位通用唯一标识符,是去掉其中的4个_的

public static String uuid()

return UUID.randomUUID().toString().replace("_","");

/把map转换为clazz型的bean

public static <T> T toBean(Map map,Class<T> clazz)

try

/通过clazz穿件实例化bean

T bean=clazz.newInstance();

/字符串到日期的转换

ConvertUtils.register(new DateConverter(),java.util.Date.class);

/构成bean,把map中的数据封装到bean中

BeanUtils.populate(bean,map);

return bean;

catch(Exception e)

throw new RuntimeException();

public class DateConverter implements Converter

@Override

public Object convert(Class type,Object value)

/如果要转换的值为空指针,那么直接返回Null

if(value==null)

return null;

/如果要转换的值不为字符串,那么就不转换了,直接返回对象value

if(!(value instanceof String))

return value;

SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");

try

return sdf.parse(value);

catch(ParseException e)

throw new RuntimeException();

2015/8/20

1. HttpServlet:doGet(),doPost(),service();

2. 父类转子类:父类转子类是向下转型,需要强转,原则:父类型的引用指向的是哪个子类的实例,就能转向哪个子类的引用。

3. 通用工具类:使用

/用来作为其他Servlet的父类,Struts的Action很像

public class BaseServlet extends HttpServlet throws ServletException,IOException

/覆写service方法,调用用户想要调用的方法

@Override

public void service(HttpServletRequest request,HttpServletResponse response)

/设置相应编码

response.setContentType("text/html;charset=utf-8");

/获取method参数,它是用户想调用的方法

String methodName=request.getMethod("method");

/方法对象

Method method=null;

/通过方法名获取方法对象

try

method=this.getClass.getMethod(methodName,HttpServletRequest.class

HttpServletResponse.class);

catch(Exception e)

/编译时异常转化为运行时异常,不要一味地抛异常,会增加复杂度

throw new RuntimeException(e);

try

/调用用户的方法之后的返回值,这里是字符串:("f:goods/UserServlet")

String result=method.invoke(this,request,response);    

/根据返回结果,决定是否转发还是重定向,默认为转发

if(result!=null & !result.isEmpty())

/

int index=result.indexOf(":");

/如果没有返回值,就默认转发

if(index=-1)

request.getRequestDispather(result).forward(request,response);

else

/拆分字符串,分割出前缀

String start=result.356lo9095/(0,index);

/要转发或重定向的路径

String path=result.substring(index+1);

if("f".equals(start))

/前缀为f",表示转发

request.getReqeustDispather(path).forward(request,response);

else if("r".equals(start))

/前缀为r",表示重定向

respose.sendRedirect(this.getServletContext+path);

catch(Exception e)

throw new RuntimeException(e);

4. 自定义JdbcUtils

5. JQuery插件:

JQuery_validate

JQuery_complete

JQuery_treeview

fckeditor:富文本编辑器

6. 结构化数据(数据库) 半结构化数据(xml,html)

7. 验证码:防止恶意攻击,机器人注册,暴力破解。

Java:一处编译,到处运行。

×自定义;用AWT(Abstract Window Toolkits,依赖本地的类库,平台依赖性)实现,有点费劲

用例:VerifyCode

/验证码:实体类

public class VerifyCode()

/验证码矩形宽高

private int width=70;

private int hight=35;

/随机数,下面有用

private Random random=new Random();

/验证码中的字体类型

private String[] fontNames={};

/矩形框背景色,默认为白色

private Color bgColor=new Color(255,255,255);

http://www.xdnf.cn/news/16234.html

相关文章:

  • 支持OCR和AI解释的Web PDF阅读器:解决大文档阅读难题
  • uni-appDay02
  • #来昇腾学AI 【十天成长计划】大模型LLM Prompt初级班
  • Java学习----工厂方法模式
  • 深入理解 eMMC RPMB 与 OP-TEE 在 Linux 系统中的应用开发
  • day62-可观测性建设-全链路监控zabbix+grafana
  • 爬虫算法原理解析
  • Windows环境下 Go项目迁移至Ubuntu(WSL) 以部署filebeat为例
  • MinIO 版本管理实践指南(附完整 Go 示例)
  • MySQL深度理解-MySQL索引优化
  • 二分查找----5.寻找旋转排序数组中的最小值
  • Android Activity与Fragment生命周期变化
  • 谈谈ArrayList与Vector的理解?
  • NOTEPAD!NPCommand函数分析之comdlg32!GetSaveFileNameW--windows记事本源代码分析
  • TechGPT3部署
  • 【STM32】FreeRTOS 任务的创建(二)
  • 深入理解大语言模型生成参数:temperature、top\_k、top\_p 等全解析
  • EasyExcel 模板导出数据 + 自定义策略(合并单元格)
  • vue 项目中 components 和 views 包下的组件功能区别对比,示例演示
  • AudioLLM 开源项目了解学习
  • 网络编程——聊天程序实现
  • 基于arduino uno r3主控的环境监测系统设计-2
  • 后端分页接口实现
  • SpringBoot框架简介
  • PHP 与 Vue.js 结合的前后端分离架构
  • Qwen3-Coder实现中国象棋游戏的尝试
  • DRF - 博客列表API
  • 【C++】类和对象(中)
  • Eureka-服务注册,服务发现
  • 办公自动化入门:如何高效将图片整合为PDF文档