Mybatisplus+spring+springmvc

本文介绍了如何使用Mybatisplus的逆向工程工具CodeGenerator生成代码,配合Spring和SpringMVC实现数据操作。配置了jdbc.properties以连接数据库,同时展示了log4j.properties的日志配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Mybatisplus 逆向工程生成类

CodeGenerator.java

import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.baomidou.mybatisplus.exceptions.MybatisPlusException;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.InjectionConfig;
import com.baomidou.mybatisplus.generator.config.*;
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.baomidou.mybatisplus.toolkit.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class CodeGenerator {

public static void main(String[] args) {
    // ================= 必须修改的配置 start =================

    // 数据源配置
    String jdbcUrl = "jdbc:mysql://127.0.0.1:3306/travel?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai";
    String jdbcDriver = "com.mysql.cj.jdbc.Driver";
    String jdbcUsername = "root";
    String jdbcPassword = "root";

    // 父级包名配置
    String parentPackage = "com.travel";

    // 生成代码的 @author 值
    String author = "zxj";

    // 要生成代码的表名配置
    String[] tables = {
            "tab_category",
            "tab_favorite",
            "tab_route",
            "tab_route_img",
            "tab_seller",
            "tab_user"
    };

    // ================= 必须修改的配置 end =================




    AutoGenerator mpg = new AutoGenerator();
    // 全局配置
    GlobalConfig gc = new GlobalConfig();
    String projectPath = System.getProperty("user.dir");
    gc.setOutputDir(projectPath + "/src/main/java");
    gc.setAuthor(author);
    gc.setBaseResultMap(true);
    gc.setBaseColumnList(true);
    // 生成完毕后是否打开输出目录
    gc.setOpen(false);
    // 为true时生成entity将继承Model类,单类即可完成基于单表的业务逻辑操作,按需开启
    gc.setActiveRecord(true);
    mpg.setGlobalConfig(gc);

    // 数据源配置
    DataSourceConfig dsc = new DataSourceConfig();
    dsc.setUrl(jdbcUrl);
    dsc.setDriverName(jdbcDriver);
    dsc.setUsername(jdbcUsername);
    dsc.setPassword(jdbcPassword);
    mpg.setDataSource(dsc);

    // 包配置
    PackageConfig pc = new PackageConfig();
    // 父级包名,按需修改
    pc.setParent(parentPackage);
    // 设置模块名, 会在parent包下生成一个指定的模块包
    pc.setModuleName(null);
    mpg.setPackageInfo(pc);


    // 策略配置
    StrategyConfig strategy = new StrategyConfig();
    strategy.setNaming(NamingStrategy.underline_to_camel);
    strategy.setColumnNaming(NamingStrategy.underline_to_camel);
    strategy.setRestControllerStyle(true);
    strategy.setSuperEntityClass("com.baomidou.mybatisplus.activerecord.Model");
    strategy.setInclude(tables);
    strategy.setSuperEntityColumns("id");
    // Controller驼峰连字符,如开启,则requestMapping由 helloWorld 变为 hello-world 默认false
    strategy.setControllerMappingHyphenStyle(false);
    strategy.setTablePrefix(pc.getModuleName() + "_");
    // 开启后将使用lombok注解代替set-get方法,false则生成set-get方法
    strategy.setEntityLombokModel(true);
    // 在实体类中移除is前缀
    strategy.setEntityBooleanColumnRemoveIsPrefix(true);
    mpg.setStrategy(strategy);
    //mpg.setTemplateEngine(new FreemarkerTemplateEngine());
    mpg.execute();
}

}

mybatisplus+spring+springmvc

pom.xml

junit junit 4.11 test com.baomidou myb
项目描述 在上家公司自己集成的一套系统,用了两个多月的时间完成的:Springboot+Mybatis-plus+ SpringMvc+Shiro+Redis企业级开发系统 Springboot作为容器,使用mybatis作为持久层框架 使用官方推荐的thymeleaf做为模板引擎,shiro作为安全框架,主流技术 几乎零XML,极简配置 两套UI实现(bootstrap+layer ui),可以自由切换 报表后端采用技术: SpringBoot整合SSM(Spring+Mybatis-plus+ SpringMvc),spring security 全注解式的权限管理和JWT方式禁用Session,采用redis存储token及权限信息 报表前端采用Bootstrap框架,结合Jquery Ajax,整合前端Layer.js(提供弹窗)+Bootstrap-table(数据列表展示)+ Bootstrap-Export(各种报表导出SQL,Excel,pdf等)框架,整合Echars,各类图表的展示(折线图,饼图,直方图等),使用了layui的弹出层、菜单、文件上传、富文本编辑、日历、选项卡、数据表格等 Oracle关系型数据库以及非关系型数据库(Redis),Oracle 性能调优(PL/SQL语言,SQL查询优化,存储过程等),用Redis做中间缓存,缓存数据 实现异步处理,定时任务,整合Quartz Job以及Spring Task 邮件管理功能, 整合spring-boot-starter-mail发送邮件等, 数据源:druid 用户管理,菜单管理,角色管理,代码生成 运行环境 jdk8+oracle+redis+IntelliJ IDEA+maven 项目技术(必填) Springboot+Mybatis-plus+ SpringMvc+Shiro+Redis 数据库文件 压缩包内 jar包文件 maven搭建 Springboot+Mybatis-plus+ SpringMvc+Shiro+Redis企业级报表后台管理系统 http://localhost:/8080/login admin admin Springboot+Mybatis-plus+ SpringMvc+Shiro+Redis企业级报表后台管理系统Springboot+Mybatis-plus+ SpringMvc+Shiro+Redis企业级报表后台管理系统Springboot+Mybatis-plus+ SpringMvc+Shiro+Redis企业级报表后台管理系统Springboot+Mybatis-plus+ SpringMvc+Shiro+Redis企业级报表后台管理系统Springboot+Mybatis-plus+ SpringMvc+Shiro+Redis企业级报表后台管理系统
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值