Application.ymlserver:port: 8888spring:datasource:type: com.alibaba.druid.pool.DruidDataSourcedriverClassName: com.mysql.cj.jdbc.Driverurl: jdbc:mysql://localhost:3306/mp_base?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=trueusername: rootpassword: rootredis:database: 0host: localhostport: 6379password:# 密码(默认为空)timeout: 6000ms# 连接超时时长(毫秒)lettuce:pool:max-active: 1000# 连接池最大连接数(使用负值表示没有限制)max-wait: -1ms# 连接池最大阻塞等待时间(使用负值表示没有限制)max-idle: 10# 连接池中的最大空闲连接min-idle: 5# 连接池中的最小空闲连接mysql-schemaDROP TABLE IF EXISTS user;CREATE TABLE user( id BIGINT(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID', name VARCHAR(30) DEFAULT NULL UNIQUE COMMENT '姓名', age INT(11) DEFAULT NULL COMMENT '年龄', email VARCHAR(50) DEFAULT NULL COMMENT '邮箱', PRIMARY KEY (id)) ENGINE=InnoDB DEFAULT CHARSET=utf8;generatorpublic class MysqlGenerator {/*** RUN THIS*/public static void main(String[] args) {// 代码生成器AutoGenerator mpg = new AutoGenerator();// 全局配置GlobalConfig gc = new GlobalConfig();String projectPath = System.getProperty("user.dir");gc.setOutputDir(projectPath + "/idc-mp/src/main/java");gc.setAuthor("当我遇上你");gc.setOpen(false);gc.setFileOverride(true);// 是否覆盖文件gc.setBaseResultMap(true);// XML ResultMapgc.setBaseColumnList(true);// XML columListgc.setDateType(DateType.ONLY_DATE);gc.setSwagger2(true); // 实体属性 Swagger2 注解gc.setIdType(IdType.AUTO);gc.setMapperName("%sMapper");gc.setXmlName("%sMapper");gc.setServiceName("%sService");gc.setServiceImplName("%sServiceImpl");gc.setControllerName("%sController");mpg.setGlobalConfig(gc);// 数据源配置DataSourceConfig dsc = new DataSourceConfig();dsc.setUrl("jdbc:mysql://localhost:3306/mp_base?useUnicode=true&serverTimezone=GMT&useSSL=false&characterEncoding=utf8");// dsc.setSchemaName("public");dsc.setDriverName("com.mysql.cj.jdbc.Driver");dsc.setUsername("root");dsc.setPassword("root");mpg.setDataSource(dsc);// 包配置PackageConfig pc = new PackageConfig();pc.setModuleName("mp");pc.setParent("cn.idea360.demo.modules");mpg.setPackageInfo(pc);// 自定义配置InjectionConfig cfg = new InjectionConfig() {@Overridepublic void initMap() {// to do nothing}};List<FileOutConfig> focList = new ArrayList<>();focList.add(new FileOutConfig("/templates/mapper.xml.ftl") {@Overridepublic String outputFile(TableInfo tableInfo) {// 自定义输入文件名称return projectPath + "/idc-mp/src/main/resources/mapper/" + pc.getModuleName()+ "/" + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML;}});cfg.setFileOutConfigList(focList);mpg.setCfg(cfg);mpg.setTemplate(new TemplateConfig().setXml(null));// 策略配置StrategyConfig strategy = new StrategyConfig();strategy.setNaming(NamingStrategy.underline_to_camel);strategy.setColumnNaming(NamingStrategy.underline_to_camel);//strategy.setSuperEntityClass("com.baomidou.mybatisplus.samples.generator.common.BaseEntity");strategy.setEntityLombokModel(true);//strategy.setSuperControllerClass("com.baomidou.mybatisplus.samples.generator.common.BaseController");strategy.setInclude(new String[]{"user"});strategy.setRestControllerStyle(true);strategy.setSuperEntityColumns("id");strategy.setControllerMappingHyphenStyle(true);//strategy.setTablePrefix(pc.getModuleName() + "_");mpg.setStrategy(strategy);// 选择 freemarker 引擎需要指定如下加,注意 pom 依赖必须有!mpg.setTemplateEngine(new FreemarkerTemplateEngine());mpg.execute();}}Redis@Configurationpublic class RedisConfig {@Beanpublic RedisTemplate<String, Serializable> redisTemplate(LettuceConnectionFactory connectionFactory) {RedisTemplate<String, Serializable> redisTemplate = new RedisTemplate<>();redisTemplate.setKeySerializer(new StringRedisSerializer());redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());redisTemplate.setConnectionFactory(connectionFactory);return redisTemplate;}//@Bean//public HashOperations<String, String, Object> hashOperations(RedisTemplate<String, Serializable> redisTemplate) {//return redisTemplate.opsForHash();//}////@Bean//public ValueOperations<String, Serializable> valueOperations(RedisTemplate<String, Serializable> redisTemplate) {//return redisTemplate.opsForValue();//}////@Bean//public ListOperations<String, Serializable> listOperations(RedisTemplate<String, Serializable> redisTemplate) {//return redisTemplate.opsForList();//}////@Bean//public SetOperations<String, Serializable> setOperations(RedisTemplate<String, Serializable> redisTemplate) {//return redisTemplate.opsForSet();//}////@Bean//public ZSetOperations<String, Serializable> zSetOperations(RedisTemplate<String, Serializable> redisTemplate) {//return redisTemplate.opsForZSet();//}}
推荐阅读
- 批量安装Windows系统
- Java整合微信支付、支付宝支付
- javascript中的继承与实现
- 高血压是什么原因引起的,五个导致的原因
- 南昌|一位体制内老领导的职场箴言!
- |领导常借这三件事清理门户!快来看看你的领导是不是在害你!
- 无人值守批量安装服务器
- 犀牛书作者:最该忘记的JavaScript特性
- JavaScript 如何读取本地文件
- 倡导茶匠精神,三大信阳毛尖品牌排行榜
