In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the knowledge about "how to use mybatis-plus-gennertor code generator to generate code + paging plug-in" in spring. In the actual case operation process, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!
code generator
1 Import the required jar package
com.baomidou mybatis-plus 2.3 junit junit 4.12 log4j log4j 1.2.17 com.mchange c3p0 0.9.5.2 mysql mysql-connector-java 5.1.37 org.springframework spring-context 4.3.10.RELEASE org.springframework spring-orm 4.3.10.RELEASE org.apache.velocity velocity-engine-core 2.0 org.slf4j slf4j-api 1.7.7 org.slf4j slf4j-log4j12 1.7.7
2 Configure applicationContext.xml
3 Database configuration
jdbc.driver=com.mysql.jdbc.Driverjdbc.url=jdbc:mysql://192.168.69.11:3306/shihaifengjdbc.username= username jdbc.password= password
4 Generating code
package com.shi.test;import com.baomidou.mybatisplus.enums.IdType;import com.baomidou.mybatisplus.generator.AutoGenerator;import com.baomidou.mybatisplus.generator.config.DataSourceConfig;import com.baomidou.mybatisplus.generator.config.GlobalConfig;import com.baomidou.mybatisplus.generator.config.PackageConfig;import com.baomidou.mybatisplus.generator.config.StrategyConfig;import com.baomidou.mybatisplus.generator.config.rules.DbType;import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;import org.junit.Test;/** * @author shfeng * @create 2019-07-18 16:59 * My Code Generator */public class MyGeneratorTest { @Test public void myGenerator(){ //1 Global Configuration GlobalConfig globalConfig = new GlobalConfig(); globalConfig.setActiveRecord(false) //Whether AR mode is supported .setAuthor("shiye") //Author .setOutputDir("D:\\project\\shiTest\\shi_Mybatis_Plus\\src\\main\\java") //Set generation path .setFileOverride(true) //file override .setIdType(IdType.AUTO) //Primary key policy auto-increment .setServiceName("%sService") //Set the name of the generated servo interface to remove the initial I .setBaseResultMap(true) //generate sql mapper mapping file .setBaseColumnList(true); //2 Database Configuration DataSourceConfig dataSourceConfig = new DataSourceConfig(); dataSourceConfig.setDbType(DbType.MYSQL) //Set database type .setDriverName("com.mysql.jdbc.Driver") //Set data driver .setUrl("jdbc:mysql://192.168.69.11:3306/shihaifeng") //Set database url .setUsername("") //Set user name .setPassword(""); //Set password //3 Policy Configuration StrategyConfig strategyConfig = new StrategyConfig(); strategyConfig.setCapitalMode(true) //global upper case naming .setDbColumnUnderline(true) //Specifies whether the table name field name is underlined .setNaming(NamingStrategy.underline_to_camel) //Naming method for mapping database tables to entities: hump naming method .setTablePrefix("") //Table prefix .setInclude("machine_item"); //table to be generated //4 Package Name Policy Configuration PackageConfig packageConfig = new PackageConfig(); packageConfig.setParent("com.shi") //global parent package .setController("controller") .setService("service") .setServiceImpl("service.impl") .setMapper("dao") //dao interface .setXml("dao") //mapper mapping file .setEntity("entity"); //5 Integrated Configuration AutoGenerator autoGenerator = new AutoGenerator(); autoGenerator.setGlobalConfig(globalConfig) .setDataSource(dataSourceConfig) .setStrategy(strategyConfig) .setPackageInfo(packageConfig); //6 Implementation autoGenerator.execute(); }}
paging plug-in
1. add configuration
(Method 1: mybatis-config.xml)
(Method 2: applicationContext.xml)
2. test
/** * Add pagination plug-ins Pagination using physical pagination * SELECT id AS id,name_cn AS nameCn,name_us AS nameUs,`desc`,created,creater,updater,updated * FROM machine_item LIMIT 0,1 */ @Test public void testQueryByPage(){ Page page = new Page(1,2); List list = machineItemMapper.selectPage(page, null); System.out.println(list); System.out.println("*************** System.out.println("Total ="+page.getTotal()); System.out.println("current page ="+page.getCurrent()); System.out.println("#of pages ="+page.getSize()); System.out.println("Total Pages ="+page.getPages()); page.setRecords(list); System.out.println("Total Records ="+page.getRecords()); }"Spring how to use mybatis-plus-gennetretor code generator to generate code + paging plug-in" content is introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.