首页 > 编程知识 正文

sqlplus导出csv文件,mybatis自动生成xml

时间:2023-05-06 21:05:00 阅读:20313 作者:1487

有关mybatis-plus,请访问mybatis-plus官网上的https://mp.baomidou.com/

通过Mybatis-Plus强大的自动代码生成功能,项目可以自动生成公共类。 例如,控制器、服务、dao、映射器、实体等。

在自动生成代码之前,必须创建一个表。 自动代码生成基于相关的此表生成代码。

1 .引入依赖! -这两个主要依赖项包括--dependencygroupidorg.Apache.velocity/groupidartifactidvelocity-engine-core/artifactidversion 2.2 添加的ependencydependencygroupidcom.Bao midou/groupidartifactidmybatis-plus-generator/artifactidversion3.4.0/version dependency 2.代码: publicstaticvoidmain (字符串[ ] args )//代码生成器autogeneratormpg=newautogenerator ); //全局配置全局配置GC=new全局配置(; //项目的根目录stringprojectpath=system.getproperty (' user.dir ' ); //当前项目的路径GC.set output dir (项目路径'/src/main/Java ' ); //文件输出根GC.setauthor(hongcheng ); //作者GC.setopen(false; 是否生成//代码以打开本地目录GC.setswagger2(true ); //实体属性Swagger2注释mpg.set全局配置(GC; //数据源配置datasourceconfigdsc=newdatasourceconfig (; DSC.seturl (JDBC : MySQL ://localhost :3306/my batis-plus? useUnicode=trueuseSSL=false令人愉快的苗条=utf8 ' )//DSC.setschemaname('public ); DSC.set drivername (com.MySQL.JDBC.driver ); //我的mysql是5.7版的//DSC.set drivername (' com.MySQL.CJ.JDBC/driver ' ); //这是MySQL 8.0版或更高版本的DSC.setusername('root ); DSC.setpassword(654123 ); mpg.setdatasource(DSC; //软件包配置packageconfigpc=newpackageconfig (; PC.setmodulename('cheng ' ); PC.setparent(com.Hong ); //设置父包com.hong.cheng.controller/service/Dao/entity mpg.setpackageinfo (PC ); //自定义配置injectionconfigcfg=newinjectionconfig ({ @ overridepublicvoidinitmap ) }//todonothing ); //模板引擎返回freemarker//stringtemplatepath='/templates/mapper.XML.ftl '; //模板引擎为velocitystringtemplatepath='/templates/mapper.XML.VM '; //自定义输出配置listfileoutconfigfoclist=new ArrayList (; //自定义配置为foc list.add (newfileoutconfig (模板路径) @ overridepublicstringoutputfile ) ) tableinfotableinfo )//returnprojectpath '/src/main/resources/mapper/' tableinfo.getentityname (' mapper ' stringpool.dot _ XML ); }; ); CFG.setfileoutconfiglist (foc list; mpg.setCFG(CFG; //配置模板templateconfigtemplateconfig=newtemplateconfig (; 模板配置. set XML (null; mpg.set template (模板配置; //策略配置strategyconfigstrategy=newstrategyconfig (; strategy.set naming (naming strategy.underline _ to _ camel ); //显示生成策略strategy.setcolumnnaming (naming strategy.underline _ to _ camel ); strategy.setentitylombokmodel (true; strategy.setrestcontrollerstyle (true;//控制器是否使用rest风格mpg.setstrategy(strategy ); mpg.execute (; } 3.自动生成后的目录结构

您可以看到映射器下的UserMapper.xml文件位于资源下。

生成代码后,代码中的注释显示为红色。 这是因为没有添加依赖关系。 只需在pom.xml中添加依赖关系即可使用。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。