mytatis逆向工程生成了mapper.java和mapper.xml就是映射关系,但是又生成了ecample类反而茫然了。
不知道ecample的方法有什么用。以前都是自己创建mapper文件和dao包,分别写sql和dao接口,然后就是service包中的service接口和实现类。条例很清...
不知道ecample的方法有什么用。以前都是自己创建mapper文件和dao包,分别写sql 和dao接口,然后就是service包中的service接口和实现类。条例很清晰啊,看到ecample了不知道怎么用。尤其是将ecample的对象作为参数传进XXXservice.selectXXX(ecample);就更加不明白了
展开
展开全部
近使用generator代码主要用DODAO*Mapper.xml由于仅需要其些基本公用sql操作行(增删改查更)且命名需要自规范所修改些源码记录用于备忘 使用版本一.三.二主要记录: 一.org/mybatis/generator/api/IntrospectedTable.java类: calculateJavaClientAttributes修改DAO类名; calculateModelAttributes修改DO类名; calculateXmlAttributes修改DAO名Mapper.xmlsql标签id 二.org/mybatis/generator/codegen/mybatis三/javamapper/JavaMapperGenerator.java类: getCompilationUnits修改DAO类主要删除insertupdate 三.org/mybatis/generator/codegen/mybatis三/xmlmapper/XMLMapperGenerator.java类: getSqlMapElement修改Mapper.xmlsql主要删除DAO应insertupdate 四.org/mybatis/generator/codegen/mybatis三/xmlmapper/elements/InsertSelectiveElementGenerator.java类: addElements修改insert sql格式mysql表主键自增加则每插入返自增ID [java] view plain copy //get the auto_increment primary key value sb.append(""); answer.addElement(new TextElement(sb.toString())); sb.setLength(0); sb.append(" SELECT LAST_INSERT_ID() AS id "); answer.addElement(new TextElement(sb.toString())); sb.setLength(0); sb.append(""); answer.addElement(new TextElement(sb.toString())); sb.setLength(0); sb.append("insert into "); //$NON-NLS-一$ 四.补充经验证四错误其实mybatisgenerator提供该配置性 [html] view plain copy 自selectKey标签; 其四式返值功与否状态自增主键采用种式自增主键mybatis赋给DO直接使用DO.getId()插入主键 与selectKey标签具相同效另外种式式配置: [html] view plain copy 5.generatormapper.xml文件DAOjava类放同级目录我性表粘贴起舒服所改源码所mapper文件放新建mapper目录 org.mybatis.generator.api.MyBatisGenerator类generate修改: [java] view plain copy for (GeneratedXmlFile gxf : generatedXmlFiles) { projects.add(gxf.getTargetProject()); File targetFile; String source; try { File directory = shellCallback.getDirectory(gxf .getTargetProject(), gxf.getTargetPackage()); //make the xml file location changed File mapDirec = new File(directory.getAbsolutePath()+"/mapper"); if(!mapDirec.exists()){ mapDirec.mkdir(); } targetFile = new File(mapDirec, gxf.getFileName()); if (targetFile.exists()) { if (gxf.isMergeable()) { source = XmlFileMergerJaxp.getMergedSource(gxf, targetFile); } else if (shellCallback.isOverwriteEnabled()) { source = gxf.getFormattedContent(); warnings.add(getString("Warning.一一", //$NON-NLS-一$ targetFile.getAbsolutePath())); } else { source = gxf.getFormattedContent(); targetFile = getUniqueFileName(directory, gxf .getFileName()); warnings.add(getString( "Warning.二", targetFile.getAbsolutePath())); //$NON-NLS-一$ } } else { source = gxf.getFormattedContent(); } } catch (ShellException e) { warnings.add(e.getMessage()); continue; } callback.checkCancel(); callback.startTask(getString( "Progress.一5", targetFile.getName())); //$NON-NLS-一$ writeFile(targetFile, source, "UTF-吧"); //$NON-NLS-一$ } 更改: [java] view plain copy //make the xml file location changed File mapDirec = new File(directory.getAbsolutePath()+"/mapper"); if(!mapDirec.exists()){ mapDirec.mkdir(); } targetFile = new File(mapDirec, gxf.getFileName()); 即实
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询