Mybatis(http://blog.mybatis.org/) is one fantastic ORM tool for Java, I like it very much because of its lightweight and smart way to do ORM. There is also one mybatis generatorIn official release, generator helps generating standard java code as you project's DAO layer.
This project is plugin suite for mybatis generator. What is mybatis generator, please see http://www.mybatis.org/generator/. The generator is handy to use, but there are still some not handy parts:
YourOtherDomainExample e=new YourOtherDomainExample(); e.createCriteria().andCc2Equals(1); List yourOtherDomainList = YourOtherDomainMapper.selectByExample(e); //then constructe one list of id list idList=new ArrayList(yourOtherDomainList.size()); for(YourOtherDomain d:yourOtherDomainList) idList.add(d.getCc1()); //use IdInList query YourDomainExample e1=new YourDomainExample(); e1.createCriteria().andC1In(idList); YourDomainMapper.selectByExample(e1);
<plugin type="net.sourceforge.jweb.mybatis.generator.plugins.SubqueryCriteriaPlugin"/> DO itadd this plugin to your generatorConfig.xml, then you will get
YourDomainExample{ ... protected abstract static class GeneratedCriteria { ... Criteria has andGenericSubquery(String subquery){ ... } ... } } Usage: YourDomainExample e=new YourDomainExample(); e.createCriteria().andGenericSubquery("c1 in (select cc1 as c1 from table 1 where cc2 = 10)"); mapper.selectByExample(e);
<plugin type="net.sourceforge.jweb.mybatis.generator.plugins.SelectOneByExamplePlugin"/> DO itIn your DAO/Mapper code, you will see:
/** * This method was generated by MyBatis Generator. * This method corresponds to the database table domain * * @mbggenerated */ Domain selectOneByExample(DomainExample example);
<plugin type="net.sourceforge.jweb.mybatis.generator.plugins.AdvancedWhereClausePlugin"/> DO itYou will see
YourDomainExample{ ... protected abstract static class GeneratedCriteria { ... public Criteria andDomainClumnxxxx(.....) { ...... return (Criteria) this; } public Criteria orDomainClumnxxxx(.....) { ...... return (Criteria) this; } ... } }
net.sourceforge.jweb.mybatis.generator.plugins.OptionsAnnotationPlugin net.sourceforge.jweb.mybatis.generator.plugins.CacheAnnotationPlugin net.sourceforge.jweb.mybatis.generator.plugins.ModelBuilderPlugin
<repository> <id>Sonatype OSS Snapshot Repository</id> <url>http://oss.sonatype.org/content/repositories/snapshots</url> </repository> <repository> <id>Sonatype OSS Release Repository</id> <url>https://oss.sonatype.org/service/local/staging/deploy/maven2</url> </repository> <dependency> <groupId>com.github.alexmao86</groupId> <artifactId>jweb-maven-plugin</artifactId> <version>1.0</version> </dependency>
remove warnings enhance PagePlugin to add method parameter type argument with domain type