mybatis-plus初次引入
parent
dd68d0ab40
commit
3bd782cd38
|
@ -53,6 +53,10 @@
|
||||||
<artifactId>ruoyi-generator</artifactId>
|
<artifactId>ruoyi-generator</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.ruoyi;
|
package com.ruoyi;
|
||||||
|
|
||||||
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||||
|
@ -10,6 +11,7 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
|
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
|
||||||
|
@MapperScan("com.ruoyi.system.mapper")
|
||||||
public class RuoYiApplication {
|
public class RuoYiApplication {
|
||||||
public static void main (String[] args) {
|
public static void main (String[] args) {
|
||||||
// System.setProperty("spring.devtools.restart.enabled", "false");
|
// System.setProperty("spring.devtools.restart.enabled", "false");
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
package com.ruoyi.web.controller.system;
|
||||||
|
|
||||||
|
import com.ruoyi.common.core.domain.Result;
|
||||||
|
import com.ruoyi.system.domain.BookInfo;
|
||||||
|
import com.ruoyi.system.service.BookInfoService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author DongZl
|
||||||
|
* @description: 书籍请求控制
|
||||||
|
* @Date 2023-10-7 上午 09:37
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/book")
|
||||||
|
public class BookInfoController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private BookInfoService bookInfoService;
|
||||||
|
|
||||||
|
@PostMapping
|
||||||
|
public Result add(@RequestBody BookInfo bookInfo){
|
||||||
|
bookInfoService.save(bookInfo);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
}
|
|
@ -82,6 +82,14 @@ mybatis:
|
||||||
# 加载全局的配置文件
|
# 加载全局的配置文件
|
||||||
configLocation: classpath:mybatis/mybatis-config.xml
|
configLocation: classpath:mybatis/mybatis-config.xml
|
||||||
|
|
||||||
|
mybatis-plus:
|
||||||
|
# 搜索指定包别名
|
||||||
|
typeAliasesPackage: com.ruoyi.**.domain
|
||||||
|
# 配置mapper的扫描,找到所有的mapper.xml映射文件
|
||||||
|
mapperLocations: classpath*:mapper/**/*Mapper.xml
|
||||||
|
# 加载全局的配置文件
|
||||||
|
configLocation: classpath:mybatis/mybatis-config.xml
|
||||||
|
|
||||||
# PageHelper分页插件
|
# PageHelper分页插件
|
||||||
pagehelper:
|
pagehelper:
|
||||||
helperDialect: mysql
|
helperDialect: mysql
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
package com.myplus;
|
||||||
|
|
||||||
|
import com.ruoyi.RuoYiApplication;
|
||||||
|
import com.ruoyi.system.domain.BookInfo;
|
||||||
|
import com.ruoyi.system.mapper.BookInfoMapper;
|
||||||
|
import com.ruoyi.system.service.BookInfoService;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author DongZl
|
||||||
|
* @description: 测试类
|
||||||
|
* @Date 2023-10-8 下午 04:39
|
||||||
|
*/
|
||||||
|
@SpringBootTest(classes = RuoYiApplication.class)
|
||||||
|
public class BookTestService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private BookInfoService bookInfoService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private BookInfoMapper bookInfoMapper;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void save(){
|
||||||
|
bookInfoMapper.insert(
|
||||||
|
BookInfo.builder()
|
||||||
|
.name("水浒传")
|
||||||
|
.price(new BigDecimal("65.36"))
|
||||||
|
.create_by("zhangsan")
|
||||||
|
.create_time(new Date())
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -41,6 +41,13 @@
|
||||||
<artifactId>pagehelper-spring-boot-starter</artifactId>
|
<artifactId>pagehelper-spring-boot-starter</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- mybatis - plus 依赖 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||||
|
<version>3.5.3.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- 自定义验证注解 -->
|
<!-- 自定义验证注解 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
package com.ruoyi.system.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author DongZl
|
||||||
|
* @description: 书籍信息
|
||||||
|
* @Date 2023-10-7 上午 09:29
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@TableName("book_info")
|
||||||
|
public class BookInfo {
|
||||||
|
/**
|
||||||
|
* 主键
|
||||||
|
*/
|
||||||
|
@TableId(type = IdType.AUTO)
|
||||||
|
private Long id;
|
||||||
|
/**
|
||||||
|
* 名称
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
/**
|
||||||
|
* 价格
|
||||||
|
*/
|
||||||
|
private BigDecimal price;
|
||||||
|
/**
|
||||||
|
* 创建人
|
||||||
|
*/
|
||||||
|
private String create_by;
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
private Date create_time;
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.ruoyi.system.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.ruoyi.system.domain.BookInfo;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author DongZl
|
||||||
|
* @description: 书籍mapper层
|
||||||
|
* @Date 2023-10-7 上午 09:31
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface BookInfoMapper extends BaseMapper<BookInfo> {
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
package com.ruoyi.system.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.ruoyi.system.domain.BookInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author DongZl
|
||||||
|
* @description: 书籍业务
|
||||||
|
* @Date 2023-10-7 上午 09:35
|
||||||
|
*/
|
||||||
|
public interface BookInfoService extends IService<BookInfo> {
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
package com.ruoyi.system.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.ruoyi.system.domain.BookInfo;
|
||||||
|
import com.ruoyi.system.mapper.BookInfoMapper;
|
||||||
|
import com.ruoyi.system.service.BookInfoService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author DongZl
|
||||||
|
* @description:
|
||||||
|
* @Date 2023-10-7 下午 05:15
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class BookInfoServiceImpl extends ServiceImpl<BookInfoMapper, BookInfo> implements BookInfoService {
|
||||||
|
}
|
Loading…
Reference in New Issue