add:依赖mybatisplus2

This commit is contained in:
zhangzhiqiang
2022-12-14 16:42:59 +08:00
parent 3dc5a67ddf
commit b168be746c
12 changed files with 76 additions and 113 deletions

View File

@@ -36,7 +36,7 @@ import org.springframework.web.bind.annotation.RestController;
@EnableTransactionManagement @EnableTransactionManagement
@EnableMethodCache(basePackages = "org.nl") @EnableMethodCache(basePackages = "org.nl")
@EnableCreateCacheAnnotation @EnableCreateCacheAnnotation
@MapperScan("org.nl.service.*.mapper") @MapperScan("org.nl.service.*.dao.mapper")
public class AppRun { public class AppRun {
public static void main(String[] args) { public static void main(String[] args) {

View File

@@ -35,6 +35,7 @@ public class CodeGenerator {
public static void main(String[] args) { public static void main(String[] args) {
String menusName = scanner("请输入对应菜单名称");
String moduleName = scanner("请输入模块名称"); String moduleName = scanner("请输入模块名称");
// Mybatis代码生成器 // Mybatis代码生成器
AutoGenerator mpg = new AutoGenerator(); AutoGenerator mpg = new AutoGenerator();
@@ -48,9 +49,9 @@ public class CodeGenerator {
gc.setAuthor("generator"); gc.setAuthor("generator");
gc.setOpen(false); gc.setOpen(false);
// gc.setSwagger2(true); // gc.setSwagger2(true);
gc.setEntityName("%sDO"); gc.setEntityName("%s");
gc.setServiceName("I%sService"); gc.setServiceName("%sService");
gc.setServiceImplName("%sServiceImpl"); gc.setServiceImplName("%ServiceImpl");
mpg.setGlobalConfig(gc); mpg.setGlobalConfig(gc);
// 数据源配置 // 数据源配置
DataSourceConfig dsc = new DataSourceConfig(); DataSourceConfig dsc = new DataSourceConfig();
@@ -62,13 +63,13 @@ public class CodeGenerator {
// 包配置 // 包配置
PackageConfig pc = new PackageConfig(); PackageConfig pc = new PackageConfig();
// pc.setModuleName(""); // pc.setModuleName("");
pc.setParent("org.nl.generator"); pc.setParent("org.nl."+menusName);
pc.setController("controller." + moduleName); pc.setController("controller." + moduleName);
pc.setMapper("dao.mapper." + moduleName); pc.setMapper("service."+moduleName+".dao.mapper");
pc.setService("service." + moduleName); pc.setService("service." + moduleName);
pc.setServiceImpl("service." + moduleName + ".impl"); pc.setServiceImpl("service." + moduleName + ".impl");
pc.setEntity("dao.entity." + moduleName); pc.setEntity("service." + moduleName + ".dao");
// pc.setXml("dao.mapper.xml"); pc.setXml("service." + moduleName + ".dao.mapper");
mpg.setPackageInfo(pc); mpg.setPackageInfo(pc);
// // 自定义配置 // // 自定义配置
InjectionConfig cfg = new InjectionConfig() { InjectionConfig cfg = new InjectionConfig() {
@@ -76,20 +77,7 @@ public class CodeGenerator {
public void initMap() { public void initMap() {
} }
}; };
List<FileOutConfig> focList = new ArrayList<>();
// 调整 xml 生成目录演示
focList.add(new FileOutConfig("/templates/mapper.xml.vm") {
@Override
public String outputFile(TableInfo tableInfo) {
return projectPath + "/src/main/resources/mapper/" + moduleName + "/" + tableInfo.getEntityName() + "Mapper.xml";
}
});
cfg.setFileOutConfigList(focList);
mpg.setCfg(cfg); mpg.setCfg(cfg);
// 关闭默认 xml 生成,调整生成 至 根目录
TemplateConfig tc = new TemplateConfig();
tc.setXml(null);
mpg.setTemplate(tc);
// 策略配置 // 策略配置
StrategyConfig strategy = new StrategyConfig(); StrategyConfig strategy = new StrategyConfig();
strategy.setNaming(NamingStrategy.underline_to_camel); strategy.setNaming(NamingStrategy.underline_to_camel);
@@ -102,8 +90,7 @@ public class CodeGenerator {
// 写于父类中的公共字段 // 写于父类中的公共字段
// strategy.setSuperEntityColumns("id"); // strategy.setSuperEntityColumns("id");
strategy.setInclude(scanner("表名,多个英文逗号分割").split(",")); strategy.setInclude(scanner("表名,多个英文逗号分割").split(","));
strategy.setControllerMappingHyphenStyle(true); strategy.setControllerMappingHyphenStyle(false);
strategy.setTablePrefix("dc_");
mpg.setStrategy(strategy); mpg.setStrategy(strategy);
// mpg.setTemplateEngine(new FreemarkerTemplateEngine()); // mpg.setTemplateEngine(new FreemarkerTemplateEngine());
mpg.execute(); mpg.execute();

View File

@@ -1,41 +0,0 @@
package org.nl.controller;
import com.alibaba.fastjson.JSON;
import org.nl.service.user.ISysUserService;
import org.nl.service.user.dto.SysUserDO;
import org.nl.service.user.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
/**
* <p>
* 用户表 前端控制器
* </p>
*
* @author generator
* @since 2022-12-14
*/
@RestController
@RequestMapping("/sys-user-do")
public class SysUserController {
@Autowired
ISysUserService iSysUserService;
@Autowired
SysUserMapper sysUserMapper;
@RequestMapping("/1")
public String getDemo(){
List<SysUserDO> list = iSysUserService.list();
return JSON.toJSONString(list) ;
}
}

View File

@@ -1,20 +0,0 @@
package org.nl.service.user.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.nl.service.user.ISysUserService;
import org.nl.service.user.dto.SysUserDO;
import org.nl.service.user.mapper.SysUserMapper;
import org.springframework.stereotype.Service;
/**
* <p>
* 用户表 服务实现类
* </p>
*
* @author generator
* @since 2022-12-14
*/
@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUserDO> implements ISysUserService {
}

View File

@@ -1,18 +0,0 @@
package org.nl.service.user.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.nl.service.user.dto.SysUserDO;
/**
* <p>
* 用户表 Mapper 接口
* </p>
*
* @author generator
* @since 2022-12-14
*/
public interface SysUserMapper extends BaseMapper<SysUserDO> {
}

View File

@@ -0,0 +1,21 @@
package org.nl.system.controller.user;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* <p>
* 用户表 前端控制器
* </p>
*
* @author generator
* @since 2022-12-14
*/
@RestController
@RequestMapping("/sysUser")
public class SysUserController {
}

View File

@@ -1,7 +1,7 @@
package org.nl.service.user; package org.nl.system.service.user;
import org.nl.system.service.user.dao.SysUser;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import org.nl.service.user.dto.SysUserDO;
/** /**
* <p> * <p>
@@ -11,6 +11,6 @@ import org.nl.service.user.dto.SysUserDO;
* @author generator * @author generator
* @since 2022-12-14 * @since 2022-12-14
*/ */
public interface ISysUserService extends IService<SysUserDO> { public interface SysUserService extends IService<SysUser> {
} }

View File

@@ -1,13 +1,12 @@
package org.nl.service.user.dto; package org.nl.system.service.user.dao;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import java.io.Serializable;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import java.io.Serializable;
/** /**
* <p> * <p>
* 用户表 * 用户表
@@ -19,7 +18,7 @@ import java.io.Serializable;
@Data @Data
@EqualsAndHashCode(callSuper = false) @EqualsAndHashCode(callSuper = false)
@TableName("sys_user") @TableName("sys_user")
public class SysUserDO implements Serializable { public class SysUser implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;

View File

@@ -0,0 +1,16 @@
package org.nl.system.service.user.dao.mapper;
import org.nl.system.service.user.dao.SysUser;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* <p>
* 用户表 Mapper 接口
* </p>
*
* @author generator
* @since 2022-12-14
*/
public interface SysUserMapper extends BaseMapper<SysUser> {
}

View File

@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.nl.service.user.mapper.SysUserMapper"> <mapper namespace="org.nl.system.service.user.dao.mapper.SysUserMapper">
</mapper> </mapper>

View File

@@ -0,0 +1,20 @@
package org.nl.system.service.user.impl;
import org.nl.system.service.user.dao.SysUser;
import org.nl.system.service.user.dao.mapper.SysUserMapper;
import org.nl.system.service.user.SysUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
/**
* <p>
* 用户表 服务实现类
* </p>
*
* @author generator
* @since 2022-12-14
*/
@Service
public class SYSUSERerviceImpl extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService {
}

View File

@@ -84,7 +84,7 @@ mybatis-plus:
map-underscore-to-camel-case: true map-underscore-to-camel-case: true
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
mapper-locations: mapper-locations:
- classpath:mapper/*.xml - classpath:org.nl.*.service.*.dao.mapper/*.xml
global-config: global-config:
db-config: db-config:
id-type: INPUT id-type: INPUT