Java wiki笔记 后端配置

在idea的database->console中输入语句

注意各个地方的引号

drop table if exists test;

create table test (
    id bigint not null comment 'id',
    name varchar(50) comment '名称',
    primary key (id)
) engine = innodb default charset = utf8mb4 comment = '测试';

 

增加package

domain/entity/POJO 这一层的实体类与数据库表一一对应

接口层叫mapper层 又叫DAO层 因为官方代码生成器生成的代码是xxMapper

 

在application的main方法上增加注解 表示扫描mapper类

@MapperScan("com.jiawa.wiki.mapper")

在配置文件中指定sql的位置

# 配置mybatis所有Mapper.xml所在的路径
mybatis.mapper-locations=classpath:/mapper/**/*.xml

其中classpath可以理解为resources文件夹

@Resource

注解是jdk自带的注入注解

 

 

集成Mybatis官方代码生成器可以省略简单curd的编写

新建一个表

drop table if exists `demo`
create table `demo` (
    `id` bigint not null comment 'id',
    `name` varchar(50) comment '名称',
    primary key (`id`)
) engine = innodb default charset = utf8mb4 comment = '测试';

 

在pom.xml里引入官方插件

<!-- mybatis generator 自动生成代码插件 -->
<plugin>
    <groupId>org.mybatis.generator</groupId>
    <artifactId>mybatis-generator-maven-plugin</artifactId>
    <version>1.4.0</version>
    <configuration>
        <configurationFile>src/main/resources/generator/generator-config.xml</configurationFile>
        <overwrite>true</overwrite>
        <verbose>true</verbose>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.22</version>
        </dependency>
    </dependencies>
</plugin>

从其他项目汇总复制一份generator-config.xml 放在generator文件夹下

然后新建一个maven启动项

 

 

 

问题:

1. 遇到了这个问题 其他项目里都是反划线 原理todo https://blog.csdn.net/supreme000/article/details/96142362

2. requestMapping注解里写的路径是否区分大小写  亲测区分,于是下个问题变成了怎样实现大小写不区分 枚举不现实

3. 

public class CommonResponse<T>

这个T表示泛型的原理和含义

4. mybatis中关于example类的理解

5. 服务端的收到request的参数封装成一个参数 持久层读数据库拿到的domainModel不能直接返回给前端 需要取需要的字段封装一层

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值