赞
踩
一、Mybatis和Mybatis-Plus
二、目录结构
三、pom.xml
- <?xml version="1.0" encoding="UTF-8"?>
- <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
- <parent>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-parent</artifactId>
- <version>2.3.2.RELEASE</version>
- <relativePath/> <!-- lookup parent from repository -->
- </parent>
-
- <modelVersion>4.0.0</modelVersion>
- <groupId>com.llh</groupId>
- <artifactId>spring-boot-demo</artifactId>
- <version>1.0.0</version>
- <name>spring-boot-demo</name>
- <description>springboot project description</description>
-
- <properties>
- <mybatis-spring-boot.version>2.1.4</mybatis-spring-boot.version>
- <mybatis-plus.version>3.4.2</mybatis-plus.version>
- </properties>
-
- <dependencies>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-web</artifactId>
- </dependency>
-
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-java</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.mybatis.spring.boot</groupId>
- <artifactId>mybatis-spring-boot-starter</artifactId>
- <version>${mybatis-spring-boot.version}</version>
- </dependency>
-
- <dependency>
- <groupId>com.baomidou</groupId>
- <artifactId>mybatis-plus-boot-starter</artifactId>
- <version>${mybatis-plus.version}</version>
- </dependency>
-
- </dependencies>
-
- </project>
-
四、application.properties
application.properties配置文件
- server:
- port: 8080
- spring:
- datasource:
- driver-class-name: com.mysql.cj.jdbc.Driver
- url: jdbc:mysql://localhost:3306/budongchan?serverTimezone=UTC&userUnicode=true&useSSL=false
- username: root
- password: 123456
- servlet:
- multipart:
- max-file-size: 5MB # 限制文件大小为5MB
- mvc:
- pathmatch:
- matching-strategy: ant_path_matcher
-
五、逻辑代码
SpringBootDemoApplication 类
- package com.example.budongchan;
-
- import org.mybatis.spring.annotation.MapperScan;
- import org.springframework.boot.SpringApplication;
- import org.springframework.boot.autoconfigure.SpringBootApplication;
- import org.springframework.scheduling.annotation.EnableScheduling;
- import springfox.documentation.swagger2.annotations.EnableSwagger2;
-
- @SpringBootApplication
- @MapperScan("com.example.budongchan.mapper")
- public class BudongchanApplication {
-
- public static void main(String[] args) {
- SpringApplication.run(BudongchanApplication.class, args);
- }
-
- }
实体类:OrderPosition 类
- package com.example.budongchan.po;
-
- import com.baomidou.mybatisplus.annotation.IdType;
- import com.baomidou.mybatisplus.annotation.TableId;
- import lombok.Data;
- import lombok.EqualsAndHashCode;
- import lombok.experimental.Accessors;
-
- import java.io.Serializable;
-
- /**
- * <p>
- *
- * </p>
- *
- * @author yixin
- * @since 2023-05-06
- */
- @Data
- @EqualsAndHashCode(callSuper = false)
- @Accessors(chain = true)
- public class OrderPosition implements Serializable {
-
- private static final long serialVersionUID = 1L;
-
- /**
- * 主键
- */
- @TableId(value = "id", type = IdType.AUTO)
- private Long id;
-
- /**
- * 省
- */
- private String provice;
-
- /**
- * 市
- */
- private String city;
-
- /**
- * 预约中心
- */
- private String center;
-
- /**
- * 窗口数量
- */
- private Integer windows;
-
-
- }
Mapper 类:OrderPositionMapper类(dao层基本的增删改查操作)
- package com.example.budongchan.mapper;
-
- import com.baomidou.mybatisplus.core.mapper.BaseMapper;
- import com.example.budongchan.po.OrderPosition;
-
- /**
- * <p>
- * Mapper 接口
- * </p>
- *
- * @author yixin
- * @since 2023-05-06
- */
- public interface OrderPositionMapper extends BaseMapper<OrderPosition> {
-
- }
Service 类:OrderPositionService 类
- package com.example.budongchan.service;
-
- import com.baomidou.mybatisplus.extension.service.IService;
- import com.example.budongchan.dto.PageDto;
- import com.example.budongchan.dto.Result;
- import com.example.budongchan.po.OrderPosition;
- import com.example.budongchan.po.OrderServetype;
-
- import javax.servlet.http.HttpServletRequest;
-
- /**
- * <p>
- * 服务类
- * </p>
- *
- * @author yixin
- * @since 2023-05-06
- */
- public interface OrderPositionService extends IService<OrderPosition> {
- public Result getmessage(PageDto pageDto) ;
- public Result getOneMessage(Long id);
-
-
- Result modifyCenter(OrderPosition orderPosition);
-
- }
ServiceImpl 类:OrderPositionServiceImpl 类
- package com.example.budongchan.service.impl;
-
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.metadata.IPage;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.example.budongchan.dto.PageDto;
- import com.example.budongchan.dto.Result;
- import com.example.budongchan.mapper.OrderPositionMapper;
- import com.example.budongchan.po.OrderPosition;
- import com.example.budongchan.po.OrderServetype;
- import com.example.budongchan.service.OrderPositionService;
- import com.example.budongchan.service.OrderServetypeService;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
-
- /**
- * <p>
- * 服务实现类
- * </p>
- *
- * @author yixin
- * @since 2023-05-06
- */
- @Service
- public class OrderPositionServiceImpl extends ServiceImpl<OrderPositionMapper, OrderPosition> implements OrderPositionService {
- @Autowired
- OrderServetypeService orderServetypeService;
-
- @Override
- public Result getmessage(PageDto pageDto) {
- Page<OrderPosition> page = new Page<>(pageDto.getPageNum(), pageDto.getPageSize());
- IPage<OrderPosition> pageOrder = this.page(page,null);
- System.out.println(pageOrder.getRecords());
- return Result.success("查询成功",pageOrder);
- }
-
- @Override
- public Result getOneMessage(Long id) {
- OrderPosition one = this.getOne(new LambdaQueryWrapper<OrderPosition>().eq(OrderPosition::getId, id));
- return Result.success("成功",one);
- }
-
- @Override
- public Result modifyCenter(OrderPosition orderPosition) {
- boolean update = this.update(orderPosition, new LambdaQueryWrapper<OrderPosition>().eq(OrderPosition::getId, orderPosition.getId()));
- if(update){
- return Result.success("修改成功");
- }else{
- return Result.error("修改失败");
- }
- }
-
-
- }
Controller 类:OrderPositionController 类
- package com.example.budongchan.controller;
-
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.example.budongchan.dto.PageDto;
- import com.example.budongchan.dto.Result;
- import com.example.budongchan.global.R;
- import com.example.budongchan.po.*;
- import com.example.budongchan.service.*;
- import io.swagger.annotations.Api;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.*;
-
- import javax.xml.ws.RequestWrapper;
-
- @Api(tags = "管理员")
- @RestController
- public class managetController {
- @Autowired
- OrderPositionService orderPositionService;
-
- @Autowired
- ManagerService managerService;
- @PostMapping("/getmessage")
- public Result getmessage(@RequestBody PageDto pageDto){
- return orderPositionService.getmessage(pageDto);
- }
- @GetMapping("/getonemessage/{id}")
- public Result getOneMessage(@PathVariable Long id){
-
- return orderPositionService.getOneMessage(id);
- }
- @PostMapping("/modifyCenter")
- public Result modifyCenter(@RequestBody OrderPosition orderPosition){
- return orderPositionService.modifyCenter(orderPosition);
- }
-
- @GetMapping("/getType/{position}")
- public Result getType(@PathVariable String position){
-
- return orderServetypeService.getType(position);
- }
-
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。