From cb797fe4f92982c64d920e467344a68acf573932 Mon Sep 17 00:00:00 2001 From: liujiaxin <3056600683@qq.com> Date: Tue, 21 Nov 2023 19:57:55 +0800 Subject: [PATCH] mybatis-plus --- .../com/february/system/domain/Tadmin.java | 5 +- .../domain/{TCarType.java => TcarType.java} | 2 +- february-merchant-mybatis-plus/pom.xml | 20 ++++- .../com/february/mybatisplus/CarApply.java | 13 +++ .../controller/AdminController.java | 28 +++++++ .../mybatisplus/controller/CarController.java | 28 ++++--- .../controller/UserController.java | 28 +++++++ .../com/february/mybatisplus/demo/Tadmin.java | 28 +++++++ .../com/february/mybatisplus/demo/Tuser.java | 28 +++++++ .../mybatisplus/mapper/AdminMapper.java | 7 ++ .../mybatisplus/mapper/CarMapper.java | 1 + .../mybatisplus/mapper/UserMapper.java | 7 ++ .../mybatisplus/service/AdminService.java | 10 +++ .../mybatisplus/service/CarService.java | 16 ++++ .../mybatisplus/service/UserService.java | 8 ++ .../service/impl/AdminServiceImpl.java | 18 +++++ .../service/impl/UserServiceImpl.java | 18 +++++ .../src/main/resources/bootstrap.yml | 25 ++++++ february-merchant-server/pom.xml | 79 +++++++++++-------- 19 files changed, 318 insertions(+), 51 deletions(-) rename february-merchant-common/src/main/java/com/february/system/domain/{TCarType.java => TcarType.java} (91%) create mode 100644 february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/CarApply.java create mode 100644 february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/controller/AdminController.java create mode 100644 february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/controller/UserController.java create mode 100644 february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/demo/Tadmin.java create mode 100644 february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/demo/Tuser.java create mode 100644 february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/mapper/AdminMapper.java create mode 100644 february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/mapper/UserMapper.java create mode 100644 february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/service/AdminService.java create mode 100644 february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/service/CarService.java create mode 100644 february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/service/UserService.java create mode 100644 february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/service/impl/AdminServiceImpl.java create mode 100644 february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/service/impl/UserServiceImpl.java create mode 100644 february-merchant-mybatis-plus/src/main/resources/bootstrap.yml diff --git a/february-merchant-common/src/main/java/com/february/system/domain/Tadmin.java b/february-merchant-common/src/main/java/com/february/system/domain/Tadmin.java index d2a2648..dfeb1d8 100644 --- a/february-merchant-common/src/main/java/com/february/system/domain/Tadmin.java +++ b/february-merchant-common/src/main/java/com/february/system/domain/Tadmin.java @@ -1,6 +1,7 @@ package com.february.system.domain; import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.models.auth.In; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -18,7 +19,5 @@ public class Tadmin { private String adminName; private String adminPhone; private String adminPassword; - @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") - @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") - private Date adminRole; + private Integer adminRole; } diff --git a/february-merchant-common/src/main/java/com/february/system/domain/TCarType.java b/february-merchant-common/src/main/java/com/february/system/domain/TcarType.java similarity index 91% rename from february-merchant-common/src/main/java/com/february/system/domain/TCarType.java rename to february-merchant-common/src/main/java/com/february/system/domain/TcarType.java index 0d5b595..e434326 100644 --- a/february-merchant-common/src/main/java/com/february/system/domain/TCarType.java +++ b/february-merchant-common/src/main/java/com/february/system/domain/TcarType.java @@ -10,7 +10,7 @@ import lombok.NoArgsConstructor; @AllArgsConstructor @NoArgsConstructor -public class TCarType { +public class TcarType { private Integer carTypeId; private String carTypeName; } diff --git a/february-merchant-mybatis-plus/pom.xml b/february-merchant-mybatis-plus/pom.xml index cdb07b6..0d97f98 100644 --- a/february-merchant-mybatis-plus/pom.xml +++ b/february-merchant-mybatis-plus/pom.xml @@ -105,7 +105,11 @@ spring-boot-starter-amqp - + + org.springframework + spring-context + 5.3.29 + org.springframework.kafka spring-kafka @@ -119,5 +123,19 @@ mybatis-plus-boot-starter 3.0.5 + + com.february + february-common-core + + + org.springframework.boot + spring-boot-starter-web + + + com.h2database + h2 + runtime + + diff --git a/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/CarApply.java b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/CarApply.java new file mode 100644 index 0000000..b08694e --- /dev/null +++ b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/CarApply.java @@ -0,0 +1,13 @@ +package com.february.mybatisplus; + +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +@MapperScan("com.february.mybatisplus.mapper") +public class CarApply { + public static void main(String[] args) { + SpringApplication.run(CarApply.class); + } +} diff --git a/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/controller/AdminController.java b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/controller/AdminController.java new file mode 100644 index 0000000..b3d3324 --- /dev/null +++ b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/controller/AdminController.java @@ -0,0 +1,28 @@ +package com.february.mybatisplus.controller; + +import com.february.mybatisplus.demo.Tadmin; +import com.february.mybatisplus.service.AdminService; +import lombok.extern.log4j.Log4j2; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/login") +@Log4j2 +public class AdminController { + @Autowired + private AdminService adminService; + + @PostMapping("/loginAdmin") + public String loginAdmin(@RequestParam("adminName")String adminName,@RequestParam("adminPassword")String adminPassword){ + Tadmin tadmin=adminService.loginAdmin(adminName,adminPassword); + if (tadmin!=null){ + return "登陆成功"; + }else { + return "登录失败"; + } + } +} diff --git a/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/controller/CarController.java b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/controller/CarController.java index 5c693d9..62524e5 100644 --- a/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/controller/CarController.java +++ b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/controller/CarController.java @@ -1,32 +1,36 @@ package com.february.mybatisplus.controller; -import cn.hutool.http.server.HttpServerRequest; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; + + import com.february.mybatisplus.demo.Tcar; +import com.february.mybatisplus.service.CarService; import lombok.extern.log4j.Log4j2; -import org.apache.http.impl.nio.bootstrap.HttpServer; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; 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; -import javax.xml.transform.Result; @RestController @RequestMapping("car") @Log4j2 public class CarController { + @Autowired - private HttpServerRequest request; + private CarService carService; - @PostMapping("add") - public Result aad(@RequestBody Tcar tcar){ - log.info("功能名称:添加,请求URI:{},请求方式:{},请求参数:{}" - ,request.getParams(),request.getParams(), JSONObject.toJSONString(tcar)); - - return null; + /** + * 企业入驻 + * @param tcar + * @return + */ + @PostMapping + public ResponseEntity add(@RequestBody Tcar tcar){ + carService.add(tcar); + return ResponseEntity.ok().build(); } + } diff --git a/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/controller/UserController.java b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/controller/UserController.java new file mode 100644 index 0000000..da205a5 --- /dev/null +++ b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/controller/UserController.java @@ -0,0 +1,28 @@ +package com.february.mybatisplus.controller; + +import com.february.mybatisplus.demo.Tuser; +import com.february.mybatisplus.service.UserService; +import lombok.extern.log4j.Log4j2; +import org.apache.poi.ss.formula.functions.T; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/userLogin") +@Log4j2 +public class UserController { + @Autowired + private UserService userService; + @PostMapping("/loginUser") + public String loginUser(@RequestParam("userName")String userName,@RequestParam("userPassword")String userPassword){ + Tuser tuser=userService.loginUser(userName,userPassword); + if (tuser!=null){ + return "登陆成功"; + }else { + return "登录失败"; + } + } +} diff --git a/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/demo/Tadmin.java b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/demo/Tadmin.java new file mode 100644 index 0000000..904c271 --- /dev/null +++ b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/demo/Tadmin.java @@ -0,0 +1,28 @@ +package com.february.mybatisplus.demo; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +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.util.Date; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@TableName("t_admin") +public class Tadmin { + @TableId(value = "admin_id",type = IdType.AUTO) + private Integer adminId; + @TableField("admin_name") + private String adminName; + @TableField("admin_password") + private String adminPassword; + @TableField("admin_role") + private Integer adminRole; +} diff --git a/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/demo/Tuser.java b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/demo/Tuser.java new file mode 100644 index 0000000..337c100 --- /dev/null +++ b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/demo/Tuser.java @@ -0,0 +1,28 @@ +package com.february.mybatisplus.demo; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@TableName("t_user") +public class Tuser { + @TableId(value = "user_id",type = IdType.AUTO) + private Integer userId; + @TableField("user_name") + private String userName; + @TableField("user_phone") + private String userPhone; + @TableField("user_password") + private String userPassword; + @TableField("car_vin") + private String carVin; +} diff --git a/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/mapper/AdminMapper.java b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/mapper/AdminMapper.java new file mode 100644 index 0000000..a54e1da --- /dev/null +++ b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/mapper/AdminMapper.java @@ -0,0 +1,7 @@ +package com.february.mybatisplus.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.february.mybatisplus.demo.Tadmin; + +public interface AdminMapper extends BaseMapper { +} diff --git a/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/mapper/CarMapper.java b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/mapper/CarMapper.java index 86e9527..0c80dcc 100644 --- a/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/mapper/CarMapper.java +++ b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/mapper/CarMapper.java @@ -5,4 +5,5 @@ import com.february.mybatisplus.demo.Tcar; public interface CarMapper extends BaseMapper { + void add(Tcar tcar); } diff --git a/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/mapper/UserMapper.java b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/mapper/UserMapper.java new file mode 100644 index 0000000..5d3dc97 --- /dev/null +++ b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/mapper/UserMapper.java @@ -0,0 +1,7 @@ +package com.february.mybatisplus.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.february.mybatisplus.demo.Tuser; + +public interface UserMapper extends BaseMapper { +} diff --git a/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/service/AdminService.java b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/service/AdminService.java new file mode 100644 index 0000000..e3ca8a3 --- /dev/null +++ b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/service/AdminService.java @@ -0,0 +1,10 @@ +package com.february.mybatisplus.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.february.mybatisplus.demo.Tadmin; + +public interface AdminService extends IService { + + Tadmin loginAdmin(String adminName, String adminPassword); + +} diff --git a/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/service/CarService.java b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/service/CarService.java new file mode 100644 index 0000000..db2fda3 --- /dev/null +++ b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/service/CarService.java @@ -0,0 +1,16 @@ +package com.february.mybatisplus.service; + +import com.february.mybatisplus.demo.Tcar; +import com.february.mybatisplus.mapper.CarMapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class CarService { + @Autowired + private CarMapper carMapper; + public void add(Tcar tcar){ + carMapper.add(tcar); + } + +} diff --git a/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/service/UserService.java b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/service/UserService.java new file mode 100644 index 0000000..667f737 --- /dev/null +++ b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/service/UserService.java @@ -0,0 +1,8 @@ +package com.february.mybatisplus.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.february.mybatisplus.demo.Tuser; + +public interface UserService extends IService { + Tuser loginUser(String userName, String userPassword); +} diff --git a/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/service/impl/AdminServiceImpl.java b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/service/impl/AdminServiceImpl.java new file mode 100644 index 0000000..35105b7 --- /dev/null +++ b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/service/impl/AdminServiceImpl.java @@ -0,0 +1,18 @@ +package com.february.mybatisplus.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.february.mybatisplus.demo.Tadmin; +import com.february.mybatisplus.mapper.AdminMapper; +import com.february.mybatisplus.service.AdminService; +import org.springframework.stereotype.Service; + +@Service +public class AdminServiceImpl extends ServiceImpl implements AdminService { + @Override + public Tadmin loginAdmin(String adminName, String adminPassword) { + QueryWrapper queryWrapper=new QueryWrapper<>(); + queryWrapper.lambda().eq(Tadmin::getAdminName,adminName).eq(Tadmin::getAdminPassword,adminPassword); + return this.getOne(queryWrapper); + } +} diff --git a/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/service/impl/UserServiceImpl.java b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/service/impl/UserServiceImpl.java new file mode 100644 index 0000000..5be1b10 --- /dev/null +++ b/february-merchant-mybatis-plus/src/main/java/com/february/mybatisplus/service/impl/UserServiceImpl.java @@ -0,0 +1,18 @@ +package com.february.mybatisplus.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.february.mybatisplus.demo.Tuser; +import com.february.mybatisplus.mapper.UserMapper; +import com.february.mybatisplus.service.UserService; +import org.springframework.stereotype.Service; + +@Service +public class UserServiceImpl extends ServiceImpl implements UserService { + @Override + public Tuser loginUser(String userName, String userPassword) { + QueryWrapper tuserQueryWrapper = new QueryWrapper<>(); + tuserQueryWrapper.lambda().eq(Tuser::getUserName,userName).eq(Tuser::getUserPassword,userPassword); + return this.getOne(tuserQueryWrapper); + } +} diff --git a/february-merchant-mybatis-plus/src/main/resources/bootstrap.yml b/february-merchant-mybatis-plus/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..7870ed2 --- /dev/null +++ b/february-merchant-mybatis-plus/src/main/resources/bootstrap.yml @@ -0,0 +1,25 @@ +# Tomcat +server: + port: 9222 + +# Spring +spring: + application: + # 应用名称 + name: merchant-settlement + profiles: + # 环境配置 + active: dev + cloud: + nacos: + discovery: + # 服务注册地址 + server-addr: 10.100.1.4:8848 + config: + # 配置中心地址 + server-addr: 10.100.1.4:8848 + # 配置文件格式 + file-extension: yml + # 共享配置 + shared-configs: + - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} diff --git a/february-merchant-server/pom.xml b/february-merchant-server/pom.xml index f7a2022..73df278 100644 --- a/february-merchant-server/pom.xml +++ b/february-merchant-server/pom.xml @@ -48,41 +48,52 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + org.springframework.boot + spring-boot-starter-web + + + + com.alibaba + druid-spring-boot-starter + 1.2.8 + + + + mysql + mysql-connector-java + 8.0.27 + + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + 2.2.2 + + + + com.github.pagehelper + pagehelper-spring-boot-starter + 1.4.1 + + + + + com.github.tobato + fastdfs-client + 1.26.5 + + + + org.springframework.boot + spring-boot-starter-jetty + + + org.springframework.boot + spring-boot-starter-undertow + - - - - - -