黑龙江省城乡和住房建设厅网站首页简述seo和sem的区别与联系

张小明 2026/1/3 10:36:21
黑龙江省城乡和住房建设厅网站首页,简述seo和sem的区别与联系,wordpress建站图片效果,网上商店是指https://www.jb51.net/program/330116r71.htm 问题场景 子类StudentResp继承父类PersonResp#xff0c;子类也拥有了父类的属性。 给子类中继承的父类属性的赋值#xff0c;但是打印了以后只会显示子类信息#xff0c;父类信息不显示。 子类#xff1a;学生类继承父类人…https://www.jb51.net/program/330116r71.htm问题场景子类StudentResp继承父类PersonResp子类也拥有了父类的属性。给子类中继承的父类属性的赋值但是打印了以后只会显示子类信息父类信息不显示。子类学生类继承父类人员类12345678910111213DatapublicclassStudentRespextendsPersonResp {/*** 学号*/privateInteger studentId;/*** 成绩*/privateInteger score;}父类人员类12345678910111213DatapublicclassPersonResp {/*** 姓名*/privateString name;/*** 年龄*/privateInteger age;}代码中给子类以及继承的父类信息赋值然后打印12345678910111213publicstaticvoidmain (String[] args) {StudentResp studentResp newStudentResp();//学生子类赋值studentResp.setStudentId(1000000000);studentResp.setScore(92);//父类赋值studentResp.setName(风清扬);studentResp.setAge(18);//打印学生子类信息System.out.println(studentResp);}打印出来只有子类自己的属性父类的属性没有出来问题分析单独获取子类中父类的信息name跟age观察打印看有没有值1234567891011121314publicstaticvoidmain (String[] args) {StudentResp studentResp newStudentResp();//学生子类赋值studentResp.setStudentId(1000000000);studentResp.setScore(92);//父类赋值studentResp.setName(风清扬);studentResp.setAge(18);//打印父类信息System.out.println(姓名 studentResp.getName());System.out.println(年龄 studentResp.getAge());}打印出来发现是有值的确认了继承本身是没有问题的继承的父类的值都可以给上也能获取到随后直接打开target对应目录下的StudentResp子类观察编译后的代码12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576publicclassStudentRespextendsPersonResp {privateInteger studentId;privateInteger score;publicStudentResp() {}publicInteger getStudentId() {returnthis.studentId;}publicInteger getScore() {returnthis.score;}publicvoidsetStudentId(finalInteger studentId) {this.studentId studentId;}publicvoidsetScore(finalInteger score) {this.score score;}publicbooleanequals(finalObject o) {if(o this) {returntrue;}elseif(!(oinstanceofStudentResp)) {returnfalse;}else{StudentResp other (StudentResp)o;if(!other.canEqual(this)) {returnfalse;}else{Objectthis$studentId this.getStudentId();Object other$studentId other.getStudentId();if(this$studentId null) {if(other$studentId !null) {returnfalse;}}elseif(!this$studentId.equals(other$studentId)) {returnfalse;}Objectthis$score this.getScore();Object other$score other.getScore();if(this$score null) {if(other$score !null) {returnfalse;}}elseif(!this$score.equals(other$score)) {returnfalse;}returntrue;}}}protectedbooleancanEqual(finalObject other) {returnotherinstanceofStudentResp;}publicinthashCode() {intPRIME true;intresult 1;Object $studentId this.getStudentId();intresult result *59 ($studentId null?43: $studentId.hashCode());Object $score this.getScore();result result *59 ($score null?43: $score.hashCode());returnresult;}publicString toString() {returnStudentResp(studentIdthis.getStudentId() , scorethis.getScore() );}}看到这里大多数同学应该已经定位到出现问题的原因了。最后的toString()方法可以明确的看到这里只取了子类本身的两个属性并没有去获取父类的属性。问题原因通过看编译后的代码可以得出Data不会打印继承的父类信息是因为该注解本身作用域的问题Data注解在编译时会自动给实体类添加SetterGetterToString等方法。但是Data注解的作用域只在当前类中所以最终打印的时候只会打印出当前类子类的信息。即使子类拥有的是全属性但是打印不会显示父类信息。解决方式本文介绍两种解决方案。第一种在子类上添加ToString(callSuper true)注解该注解会将父类的属性跟子类的属性一起生成toString第二种不使用Data注解使用SetterGetter注解在父类中重写toString()方法并用JSON的方式打印。1.子类添加ToString(callSuper true)注解1234567891011121314DataToString(callSuper true)publicclassStudentRespextendsPersonResp {/*** 学号*/privateInteger studentId;/*** 成绩*/privateInteger score;}打印子类12345678910111213publicstaticvoidmain (String[] args) {StudentResp studentResp newStudentResp();//学生子类赋值studentResp.setStudentId(1000000000);studentResp.setScore(92);//父类赋值studentResp.setName(风清扬);studentResp.setAge(18);//学生子类System.out.println(studentResp);}结果可以看到父类信息再看看target中子类编译后的代码12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576publicclassStudentRespextendsPersonResp {privateInteger studentId;privateInteger score;publicStudentResp() {}publicInteger getStudentId() {returnthis.studentId;}publicInteger getScore() {returnthis.score;}publicvoidsetStudentId(finalInteger studentId) {this.studentId studentId;}publicvoidsetScore(finalInteger score) {this.score score;}publicbooleanequals(finalObject o) {if(o this) {returntrue;}elseif(!(oinstanceofStudentResp)) {returnfalse;}else{StudentResp other (StudentResp)o;if(!other.canEqual(this)) {returnfalse;}else{Objectthis$studentId this.getStudentId();Object other$studentId other.getStudentId();if(this$studentId null) {if(other$studentId !null) {returnfalse;}}elseif(!this$studentId.equals(other$studentId)) {returnfalse;}Objectthis$score this.getScore();Object other$score other.getScore();if(this$score null) {if(other$score !null) {returnfalse;}}elseif(!this$score.equals(other$score)) {returnfalse;}returntrue;}}}protectedbooleancanEqual(finalObject other) {returnotherinstanceofStudentResp;}publicinthashCode() {intPRIME true;intresult 1;Object $studentId this.getStudentId();intresult result *59 ($studentId null?43: $studentId.hashCode());Object $score this.getScore();result result *59 ($score null?43: $score.hashCode());returnresult;}publicString toString() {returnStudentResp(supersuper.toString() , studentIdthis.getStudentId() , scorethis.getScore() );}}可以明确的看到最后的toString()方法中多了一个super.toString()方法将父类的信息打印出来2.不使用Data注解使用SetterGetter注解在父类中重写toString()方法并用JSON的方式打印。子类使用SetterGetter注解1234567891011121314GetterSetterpublicclassStudentRespextendsPersonResp {/*** 学号*/privateInteger studentId;/*** 成绩*/privateInteger score;}父类中重写toString()方法并用JSON的方式打印1234567891011121314151617181920DatapublicclassPersonResp {/*** 姓名*/privateString name;/*** 年龄*/privateInteger age;OverridepublicString toString() {returnJSON.toJSONString(this);}}打印子类12345678910111213publicstaticvoidmain (String[] args) {StudentResp studentResp newStudentResp();//学生子类赋值studentResp.setStudentId(1000000000);studentResp.setScore(92);//父类赋值studentResp.setName(风清扬);studentResp.setAge(18);//学生子类System.out.println(studentResp);}结果也可以看到父类信息总结这个问题本身不算是个大问题延伸出来更为重要的是我们解决问题的思路。因为从本质上来说属性本身都是存在的只是没打印出来。但是遇到这个问题的时候第一反应都是明明继承了父类为啥父类的值会没有从而会带偏我们去解决问题方向遇到此类问题第一我们应该先确认问题的本质到底有没有给上值确认了已经给上值就说明只是打印的问题进而去编译后的代码中查看为啥没打印出来最终定位到问题从而解决问题。
版权声明:本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!

淘宝优惠券网站用什么软件做怎么新建一个网站

Linux系统启动与运行级别全解析 1. 系统启动流程 在Linux系统启动时,会执行一系列的脚本和操作来完成初始化。首先,系统会运行 /etc/profile 这个shell脚本,为所有用户设置循环使用的变量。接着,系统会运行 /etc/profile.d 目录下与shell相关的文件。之后,系统会执行…

张小明 2026/1/1 5:26:01 网站建设

做产品网站有什么好看的网站

Obsidian与滴答清单完美同步:终极任务管理指南 【免费下载链接】obsidian-dida-sync 滴答清单同步到obsidian(ticktick sync to obsidian) 项目地址: https://gitcode.com/gh_mirrors/ob/obsidian-dida-sync 想要将滴答清单中的任务高效同步到Obsidian笔记中…

张小明 2026/1/1 5:25:59 网站建设

五莲建设监理有限公司网站微信后台网站建设

使用Dify开发会议纪要自动生成工具的技术路线 在现代企业中,一场两小时的会议结束后,往往需要专人花上一两个小时去整理录音、提炼要点、撰写纪要。这个过程不仅耗时,还容易遗漏关键决策和待办事项。更糟糕的是,不同人的写作风格差…

张小明 2026/1/1 5:25:56 网站建设

wex5做视频网站广州企业网站设计公司

Dify中JSON Schema校验功能:确保输出结构一致性 在构建企业级AI应用的今天,一个看似简单却极具挑战的问题浮出水面:我们如何让大模型“说人话”的同时,也“写对格式”? 想象这样一个场景:客服系统调用LL…

张小明 2026/1/1 7:17:09 网站建设

中山市哪家公司做网站人才网官方网站

项目管理方法案例研究案例1:丰田汽车 - 精益生产/六西格玛(亚洲-日本)项目类型:工业制造项目丰田生产系统(TPS)是精益制造的鼻祖,结合六西格玛方法持续优化生产流程。其核心是"准时制生产&…

张小明 2026/1/3 7:16:38 网站建设

免费做请帖的网站pc网站优化排名

第一章:Laravel 13的多模态事件监听概述Laravel 13 引入了对多模态事件监听的原生支持,使得开发者能够在一个统一的架构下处理来自不同输入源的事件,例如 HTTP 请求、队列任务、WebSocket 消息甚至 CLI 命令。这一特性强化了事件驱动架构的灵…

张小明 2026/1/1 7:17:04 网站建设