add:依赖mybatisplus
This commit is contained in:
@@ -4,6 +4,7 @@ import cn.dev33.satoken.annotation.SaIgnore;
|
||||
import com.alicp.jetcache.anno.config.EnableCreateCacheAnnotation;
|
||||
import com.alicp.jetcache.anno.config.EnableMethodCache;
|
||||
import io.swagger.annotations.Api;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.nl.modules.wql.util.SpringContextHolder;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
@@ -35,6 +36,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@EnableTransactionManagement
|
||||
@EnableMethodCache(basePackages = "org.nl")
|
||||
@EnableCreateCacheAnnotation
|
||||
@MapperScan("org.nl.service.*.mapper")
|
||||
public class AppRun {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
package org.nl.config.mybatis;
|
||||
|
||||
import com.baomidou.mybatisplus.core.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 org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class CodeGenerator {
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 读取控制台内容
|
||||
* </p>
|
||||
*/
|
||||
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.isEmpty(ipt)) {
|
||||
return ipt;
|
||||
}
|
||||
}
|
||||
throw new MybatisPlusException("请输入正确的" + tip + "!");
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
String moduleName = scanner("请输入模块名称");
|
||||
// Mybatis代码生成器
|
||||
AutoGenerator mpg = new AutoGenerator();
|
||||
|
||||
// 全局配置
|
||||
GlobalConfig gc = new GlobalConfig();
|
||||
// 默认不覆盖
|
||||
gc.setFileOverride(false);
|
||||
String projectPath = System.getProperty("user.dir");
|
||||
gc.setOutputDir(projectPath + "/src/main/java/");
|
||||
gc.setAuthor("generator");
|
||||
gc.setOpen(false);
|
||||
// gc.setSwagger2(true);
|
||||
gc.setEntityName("%sDO");
|
||||
gc.setServiceName("I%sService");
|
||||
gc.setServiceImplName("%sServiceImpl");
|
||||
mpg.setGlobalConfig(gc);
|
||||
// 数据源配置
|
||||
DataSourceConfig dsc = new DataSourceConfig();
|
||||
dsc.setUrl("jdbc:mysql://192.168.81.252:3306/nl-sso-server?setUnicode=true&characterEncoding=utf8");
|
||||
dsc.setDriverName("com.mysql.cj.jdbc.Driver");
|
||||
dsc.setUsername("root");
|
||||
dsc.setPassword("Root.123456");
|
||||
mpg.setDataSource(dsc);
|
||||
// 包配置
|
||||
PackageConfig pc = new PackageConfig();
|
||||
// pc.setModuleName("");
|
||||
pc.setParent("org.nl.generator");
|
||||
pc.setController("controller." + moduleName);
|
||||
pc.setMapper("dao.mapper." + moduleName);
|
||||
pc.setService("service." + moduleName);
|
||||
pc.setServiceImpl("service." + moduleName + ".impl");
|
||||
pc.setEntity("dao.entity." + moduleName);
|
||||
// pc.setXml("dao.mapper.xml");
|
||||
mpg.setPackageInfo(pc);
|
||||
// // 自定义配置
|
||||
InjectionConfig cfg = new InjectionConfig() {
|
||||
@Override
|
||||
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);
|
||||
// 关闭默认 xml 生成,调整生成 至 根目录
|
||||
TemplateConfig tc = new TemplateConfig();
|
||||
tc.setXml(null);
|
||||
mpg.setTemplate(tc);
|
||||
// 策略配置
|
||||
StrategyConfig strategy = new StrategyConfig();
|
||||
strategy.setNaming(NamingStrategy.underline_to_camel);
|
||||
strategy.setColumnNaming(NamingStrategy.underline_to_camel);
|
||||
// strategy.setSuperEntityClass("你自己的父类实体,没有就不用设置!");
|
||||
strategy.setEntityLombokModel(true);
|
||||
strategy.setRestControllerStyle(true);
|
||||
// 公共父类
|
||||
// strategy.setSuperControllerClass("你自己的父类控制器,没有就不用设置!");
|
||||
// 写于父类中的公共字段
|
||||
// strategy.setSuperEntityColumns("id");
|
||||
strategy.setInclude(scanner("表名,多个英文逗号分割").split(","));
|
||||
strategy.setControllerMappingHyphenStyle(true);
|
||||
strategy.setTablePrefix("dc_");
|
||||
mpg.setStrategy(strategy);
|
||||
// mpg.setTemplateEngine(new FreemarkerTemplateEngine());
|
||||
mpg.execute();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package org.nl.config.mybatis;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.DbType;
|
||||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
@EnableTransactionManagement
|
||||
@Configuration
|
||||
public class MybatisPlusConfig {
|
||||
|
||||
/**
|
||||
* 新的分页插件,一缓和二缓遵循mybatis的规则,需要设置 MybatisConfiguration#useDeprecatedExecutor = false 避免缓存出现问题(该属性会在旧插件移除后一同移除)
|
||||
添加自增插件
|
||||
*/
|
||||
@Bean
|
||||
public MybatisPlusInterceptor mybatisPlusInterceptor() {
|
||||
|
||||
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
||||
// 分页插件
|
||||
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
|
||||
//乐观锁插件
|
||||
interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
|
||||
|
||||
return interceptor;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package org.nl.config.saconfig;
|
||||
import cn.dev33.satoken.config.SaSsoConfig;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
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) ;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.nl.modules.common.utils.dto;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import lombok.Data;
|
||||
import org.nl.modules.system.domain.User;
|
||||
import org.nl.modules.system.service.dto.UserDto;
|
||||
|
||||
import java.io.Serializable;
|
||||
@@ -25,7 +26,7 @@ public class CurrentUser implements Serializable {
|
||||
private String preson_name;
|
||||
|
||||
//用户详细信息
|
||||
private UserDto user;
|
||||
private User user;
|
||||
|
||||
private List<String> permissions = new ArrayList<>();
|
||||
}
|
||||
|
||||
@@ -113,8 +113,8 @@ public class AuthorizationController {
|
||||
CurrentUser user = new CurrentUser();
|
||||
user.setId(userInfo.getLong("user_id"));
|
||||
user.setUsername(userInfo.getString("username"));
|
||||
user.setPermissions(Lists.newArrayList(userInfo.getString("person_name")));
|
||||
user.setUser(this.getById(userInfo.getLong("user_id")));
|
||||
user.setPreson_name((userInfo.getString("person_name")));
|
||||
user.setUser(userService.findById(userInfo.getLong("user_id")));
|
||||
user.setPermissions(permissionList);
|
||||
|
||||
// SaLoginModel 配置登录相关参数
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.nl.service.user;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.nl.service.user.dto.SysUserDO;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用户表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author generator
|
||||
* @since 2022-12-14
|
||||
*/
|
||||
public interface ISysUserService extends IService<SysUserDO> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
package org.nl.service.user.dto;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用户表
|
||||
* </p>
|
||||
*
|
||||
* @author generator
|
||||
* @since 2022-12-14
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("sys_user")
|
||||
public class SysUserDO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 用户标识
|
||||
*/
|
||||
@TableId(value = "user_id", type = IdType.AUTO)
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 登录账号
|
||||
*/
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 姓名
|
||||
*/
|
||||
private String personName;
|
||||
|
||||
/**
|
||||
* 性别
|
||||
*/
|
||||
private String gender;
|
||||
|
||||
/**
|
||||
* 电话
|
||||
*/
|
||||
private String phone;
|
||||
|
||||
/**
|
||||
* 电子邮箱
|
||||
*/
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* 头像地址
|
||||
*/
|
||||
private String avatarName;
|
||||
|
||||
/**
|
||||
* 头像真实路径
|
||||
*/
|
||||
private String avatarPath;
|
||||
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 是否为admin账号
|
||||
*/
|
||||
private String isAdmin;
|
||||
|
||||
/**
|
||||
* 是否启用
|
||||
*/
|
||||
private String isUsed;
|
||||
|
||||
/**
|
||||
* 密码重置者
|
||||
*/
|
||||
private String pwdResetUserId;
|
||||
|
||||
/**
|
||||
* 密码重置时间
|
||||
*/
|
||||
private String pwdResetTime;
|
||||
|
||||
/**
|
||||
* 创建人标识
|
||||
*/
|
||||
private Long createId;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private String createName;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private String createTime;
|
||||
|
||||
/**
|
||||
* 修改人标识
|
||||
*/
|
||||
private Long updateOptid;
|
||||
|
||||
/**
|
||||
* 修改人
|
||||
*/
|
||||
private String updateOptname;
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
private String updateTime;
|
||||
|
||||
/**
|
||||
* 外部人员标识
|
||||
*/
|
||||
private String extpersonId;
|
||||
|
||||
/**
|
||||
* 外部用户标识
|
||||
*/
|
||||
private String extuserId;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
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 {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
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> {
|
||||
|
||||
}
|
||||
@@ -54,6 +54,7 @@ security:
|
||||
- /auth/login
|
||||
- /auth/code
|
||||
- /auth/logout
|
||||
- /sys-user-do/**
|
||||
# swagger
|
||||
- /swagger-ui.html
|
||||
- /swagger-resources/**
|
||||
@@ -78,3 +79,12 @@ security:
|
||||
- /api/localStorage/pictures
|
||||
# 参数
|
||||
- /api/param/getValueByCode
|
||||
mybatis-plus:
|
||||
configuration:
|
||||
map-underscore-to-camel-case: true
|
||||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
mapper-locations:
|
||||
- classpath:mapper/*.xml
|
||||
global-config:
|
||||
db-config:
|
||||
id-type: INPUT
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
<?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">
|
||||
<mapper namespace="org.nl.service.user.mapper.SysUserMapper">
|
||||
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user