java实体类生成工具

╰+攻爆jí腚メ 2022-06-07 23:05 515阅读 0赞

前言

原因是这样的,eclipse有那种生成实体类的插件,可是我感觉装来装去很麻烦,于是我想,干脆自己做一个生成实体类的工具吧,说做就做,然后就自己花了两个小时左右做出来了一个,以后应该能大大提高工作效率吧。

实现方法

输入:属性个数
输入:type virableName
输出:d盘下面的example文件,该文件里面生成了实体类的代码

原理就是填充数据而已。。。根本没有难度
然后用了map模板把数据存起来了

使用截图

这里写图片描述
**这个是数据截图,CKCommand表示类,5表示有几个属性,剩下的都是数据属性
然后把这个数据复制进控制台运行就可以了**

这里写图片描述
运行截图

最后的实体类截图
这里写图片描述
注意去D盘下面找

代码

  1. #include <iostream>
  2. #include <string>
  3. #include <map>
  4. #include <fstream>
  5. using namespace std;
  6. int main()
  7. {
  8. int num; //总体的成员个数
  9. string which1, Vname,classname;
  10. map<string, string > mapStudent; //这个我服了
  11. map <string, string >::iterator m1_Iter;
  12. cin >> classname;
  13. cin >> num;
  14. for (int i = 0; i<num; i++){
  15. cin >> which1 >> Vname;
  16. mapStudent[Vname] = which1;
  17. }
  18. cout << "Congratulation that you are success!"<<endl;
  19. ofstream examplefile("d:\\example.txt");
  20. if (examplefile.is_open())
  21. {
  22. examplefile << "class "<<classname<<" implements Serializable{\n\n";
  23. for (m1_Iter = mapStudent.begin(); m1_Iter != mapStudent.end(); m1_Iter++){
  24. //cout << "diyige " << m1_Iter->first << " " << m1_Iter->second.first << " " << m1_Iter->second.second << endl;
  25. examplefile <<" private "<< m1_Iter->second << " " << m1_Iter->first <<";\n";
  26. }
  27. //first constructor
  28. examplefile << "\n//无参数的构造器\n";
  29. examplefile << " public " << classname << "(){\n";
  30. examplefile << "\n";
  31. examplefile << " }\n\n";
  32. //第二个构造器
  33. examplefile << "//有参数的构造器\n";
  34. examplefile << " public " << classname << "("; //打印到括号地方了
  35. for (m1_Iter = mapStudent.begin(); m1_Iter != mapStudent.end(); m1_Iter++){
  36. if (m1_Iter != mapStudent.end()){
  37. examplefile << m1_Iter->second << " " << m1_Iter->first << ",";
  38. }
  39. else{
  40. examplefile << m1_Iter->second << " " << m1_Iter->first;
  41. }
  42. }
  43. examplefile << "){\n";
  44. //构造函数里面的内容
  45. for (m1_Iter = mapStudent.begin(); m1_Iter != mapStudent.end(); m1_Iter++){
  46. //examplefile << m1_Iter->second.first << " " << m1_Iter->second.second << ",";
  47. examplefile << " this." << m1_Iter->first << " = " << m1_Iter->first << ";\n";
  48. }
  49. examplefile << " }\n";
  50. //----------------------------- 构造函数内容结束---------------------------------
  51. //----------------------------- get方法开始--------------------------------------
  52. examplefile << "\n//GET跟SET方法都在这里\n";
  53. for (m1_Iter = mapStudent.begin(); m1_Iter != mapStudent.end(); m1_Iter++){
  54. //examplefile << m1_Iter->second.first << " " << m1_Iter->second.second << ",";
  55. //examplefile << "this." << m1_Iter->second.second << " = " << m1_Iter->second.second << "\n";
  56. examplefile << " public " << m1_Iter->second << " Get" << m1_Iter->first << "(){\n";
  57. examplefile << " return " << m1_Iter->first << ";\n";
  58. examplefile << " }\n\n";
  59. //--------------------------------set方法继续--------------------------------
  60. examplefile << " public void Set" << m1_Iter->first << "(" << m1_Iter->second << " " << m1_Iter->first\
  61. << "){\n";
  62. examplefile << " this." << m1_Iter->first << "=" << m1_Iter->first<< ";\n";
  63. examplefile << " }\n\n";
  64. }
  65. //完结撒花
  66. examplefile << "}\n";
  67. examplefile.close();
  68. }
  69. system("pause");
  70. return 0;
  71. }

发表评论

表情:
评论列表 (有 0 条评论,515人围观)

还没有评论,来说两句吧...

相关阅读

    相关 java实体生成工具

    前言 原因是这样的,eclipse有那种生成实体类的插件,可是我感觉装来装去很麻烦,于是我想,干脆自己做一个生成实体类的工具吧,说做就做,然后就自己花了两个小时左右做出来