文档来源
官方
条件构造器
ge
QueryWrapper< Employee> wrapper = new QueryWrapper < > ( ) ;
wrapper
. isNotNull ( "last_name" )
. isNotNull ( "email" )
. ge ( "age" , 23 ) ;
employeeMapper. selectList ( wrapper) . forEach ( System. out: : println) ;
eq
QueryWrapper< Employee> wrapper = new QueryWrapper < > ( ) ;
wrapper. eq ( "last_name" , "Tom" ) ;
Employee employee = employeeMapper. selectOne ( wrapper) ;
System. out. println ( employee) ;
between
QueryWrapper< Employee> wrapper = new QueryWrapper < > ( ) ;
wrapper. between ( "age" , 18 , 24 ) ;
Integer count = employeeMapper. selectCount ( wrapper) ;
System. out. println ( count) ;
like
QueryWrapper< Employee> wrapper = new QueryWrapper < > ( ) ;
wrapper
. notLike ( "last_name" , "m" )
. likeRight ( "email" , "Aca" ) ;
List< Map< String, Object> > maps = employeeMapper. selectMaps ( wrapper) ;
maps. forEach ( System. out: : println) ;
inSql(联表)
QueryWrapper< Employee> wrapper = new QueryWrapper < > ( ) ;
wrapper. inSql ( "id" , "select id from employee where id < 4" ) ;
List< Object> objects = employeeMapper. selectObjs ( wrapper) ;
objects. forEach ( System. out: : println) ;
orderby
QueryWrapper< Employee> wrapper = new QueryWrapper < > ( ) ;
wrapper. orderByDesc ( "id" ) ;
List< Employee> employees = employeeMapper. selectList ( wrapper) ;
employees. forEach ( System. out: : println) ;
代码自动生成器
public class CodeGenerator {
public static String scanner ( String tip) {
Scanner scanner = new Scanner ( System. in) ;
StringBuilder help = new StringBuilder ( ) ;
help. append ( "请输入" + tip + ":" ) ;
System. out. println ( help. toString ( ) ) ;
if ( scanner. hasNext ( ) ) {
String ipt = scanner. next ( ) ;
if ( StringUtils. isNotEmpty ( ipt) ) {
return ipt;
}
}
throw new MybatisPlusException ( "请输入正确的" + tip + "!" ) ;
}
public static void main ( String[ ] args) {
AutoGenerator mpg = new AutoGenerator ( ) ;
GlobalConfig gc = new GlobalConfig ( ) ;
String projectPath = "D:\\projects\\Yeion\\m-business-service\\business-service" ;
gc. setOutputDir ( projectPath + "/src/main/java" ) ;
gc. setAuthor ( "BNMZY" ) ;
gc. setOpen ( false ) ;
gc. setFileOverride ( true ) ;
gc. setSwagger2 ( true ) ;
gc. setActiveRecord ( true ) ;
gc. setBaseColumnList ( true ) ;
gc. setBaseResultMap ( true ) ;
gc. setIdType ( IdType. ID_WORKER) ;
mpg. setGlobalConfig ( gc) ;
DataSourceConfig dsc = new DataSourceConfig ( ) ;
dsc. setUrl ( "jdbc:mysql://120.79.18.7:32553/yunpai?characterEncoding=utf-8" ) ;
dsc. setDriverName ( "com.mysql.jdbc.Driver" ) ;
dsc. setUsername ( "sms" ) ;
dsc. setPassword ( "Yeion#187.top" ) ;
mpg. setDataSource ( dsc) ;
PackageConfig pc = new PackageConfig ( ) ;
pc. setModuleName ( "member.business" ) ;
pc. setParent ( "com.yeion.jd" ) ;
mpg. setPackageInfo ( pc) ;
InjectionConfig cfg = new InjectionConfig ( ) {
@Override
public void initMap ( ) {
}
} ;
String templatePath = "/templates/mapper.xml.vm" ;
List< FileOutConfig> focList = new ArrayList < > ( ) ;
focList. add ( new FileOutConfig ( templatePath) {
@Override
public String outputFile ( TableInfo tableInfo) {
return projectPath + "/src/main/resources/mapper/" + pc. getModuleName ( )
+ "/" + tableInfo. getEntityName ( ) + "Mapper" + StringPool. DOT_XML;
}
} ) ;
cfg. setFileOutConfigList ( focList) ;
mpg. setCfg ( cfg) ;
TemplateConfig templateConfig = new TemplateConfig ( ) ;
templateConfig. setXml ( null) ;
mpg. setTemplate ( templateConfig) ;
StrategyConfig strategy = new StrategyConfig ( ) ;
strategy. setNaming ( NamingStrategy. underline_to_camel) ;
strategy. setColumnNaming ( NamingStrategy. underline_to_camel) ;
strategy. setEntityTableFieldAnnotationEnable ( true ) ;
strategy. setVersionFieldName ( "version" ) ;
strategy. setLogicDeleteFieldName ( "deleted" ) ;
strategy. setEntityLombokModel ( true ) ;
strategy. setRestControllerStyle ( true ) ;
strategy. setSuperControllerClass ( "com.yeion.jd.common.base.controller.BaseController" ) ;
TableFill create = new TableFill ( "gmt_create" , FieldFill. INSERT) ;
TableFill update = new TableFill ( "gmt_update" , FieldFill. INSERT_UPDATE) ;
List< TableFill> list = Arrays. asList ( create, update) ;
strategy. setTableFillList ( list) ;
strategy. setInclude ( "user_xf"
) ;
strategy. setControllerMappingHyphenStyle ( true ) ;
mpg. setStrategy ( strategy) ;
mpg. setTemplateEngine ( new VelocityTemplateEngine ( ) ) ;
mpg. execute ( ) ;
}
}
AA