新建项目
删除无用文件
导入依赖
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.76</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
新建yml 配置数据库
spring:
datasource:
username: xxxxxx
password: xxxx
url: jdbc:mysql://192.168.6.158:3706/bioDB?serverTimezone=Asia/Shanghai&useSSL=false&useUnicode=true&characterEncoding=utf8&allowPublicKeyRetrieval=true&allowMultiQueries=true
# url: jdbc:mysql://192.168.6.158:3906/autoPCR?serverTimezone=Asia/Shanghai&useSSL=false&useUnicode=true&characterEncoding=utf8&allowPublicKeyRetrieval=true&allowMultiQueries=true
# url: jdbc:mysql://192.168.2.196:3906/autoPCR?serverTimezone=Asia/Shanghai&useSSL=false&useUnicode=true&characterEncoding=utf8&allowPublicKeyRetrieval=true&allowMultiQueries=true
# type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
server:
port: 8093
mybatis-plus:
configuration:
map-underscore-to-camel-case: true
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
MPX
安装插件
idea右侧database点击添加mysql,参数如下
添加成功后可以看到数据库参数
右键表,自动生成代码
输入参数
结束后目录文件夹结构如下
重启就可构建完毕
生成后需要在mapper文件中添加注解
controller文件的注解需要修改
MP代码使用示例
@Autowired
LungCancerDrugMapper lungCancerDrugMapper;
@GetMapping("getData")
public JSONObject getData(@RequestParam(defaultValue = "") String drugNameTherapyZh ,
@RequestParam(defaultValue = "0")Integer drugType ){
LambdaQueryWrapper<LungCancerDrug> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.like(StringUtils.isNotBlank(drugNameTherapyZh),LungCancerDrug::getDrugNameTherapyZh,drugNameTherapyZh)
.eq(LungCancerDrug::getDrugType,drugType)
// .ge(num_Begin!=null,LungCancerDrug::getDrugType,num_Begin)
// .le(num_End!=null,LungCancerDrug::getDrugType,num_End)
;
List<LungCancerDrug> lungCancerDrugList = lungCancerDrugMapper.selectList(queryWrapper);
System.out.println(lungCancerDrugList.toString());
JSONObject jsonObject = new JSONObject();
jsonObject.put("data",lungCancerDrugList);
jsonObject.put("code",200);
return jsonObject;
}
MP函数速查
MybatisX快速创建curd语句
输入
insertSelective
然后ALT+ENTER 选择此项