Browse Source

新增user表,测试开发成功

chenendian 1 month ago
parent
commit
72be7e5d20

+ 41 - 0
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/controller/TestUserController.java

@@ -0,0 +1,41 @@
+package com.siwei.apply.controller;
+
+import com.siwei.apply.domain.TestUser;
+import com.siwei.apply.service.TestUserService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+@RestController
+@RequestMapping("/testUser")
+public class TestUserController {
+    @Autowired
+    private TestUserService testUserService;
+
+    @PostMapping("/insert")
+    public int insert(@RequestBody TestUser testUser) {
+        return testUserService.insert(testUser);
+    }
+
+    @GetMapping("/{id}")
+    public TestUser selectById(@PathVariable int id) {
+        return testUserService.selectById(id);
+    }
+
+    @GetMapping("/list")
+    public List<TestUser> selectList() {
+        return testUserService.selectList();
+    }
+
+    @PostMapping("/update")
+    public int update(@RequestBody TestUser testUser) {
+        return testUserService.update(testUser);
+    }
+
+    @DeleteMapping("/{id}")
+    public int delete(@PathVariable int id) {
+        return testUserService.delete(id);
+    }
+}
+

+ 43 - 0
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/domain/TestUser.java

@@ -0,0 +1,43 @@
+package com.siwei.apply.domain;
+
+import java.time.LocalDate;
+
+public class TestUser {
+    private Integer id;
+    private String name;
+    private Boolean sex;
+    private Float age;
+    private LocalDate createDate;
+
+    public Integer getId() {
+        return id;
+    }
+    public void setId(Integer id) {
+        this.id = id;
+    }
+    public String getName() {
+        return name;
+    }
+    public void setName(String name) {
+        this.name = name;
+    }
+    public Boolean getSex() {
+        return sex;
+    }
+    public void setSex(Boolean sex) {
+        this.sex = sex;
+    }
+    public Float getAge() {
+        return age;
+    }
+    public void setAge(Float age) {
+        this.age = age;
+    }
+    public LocalDate getCreateDate() {
+        return createDate;
+    }
+    public void setCreateDate(LocalDate createDate) {
+        this.createDate = createDate;
+    }
+}
+

+ 16 - 0
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/mapper/TestUserMapper.java

@@ -0,0 +1,16 @@
+package com.siwei.apply.mapper;
+
+import com.siwei.apply.domain.TestUser;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import java.util.List;
+
+@Mapper
+public interface TestUserMapper {
+    int insert(TestUser testUser);
+    TestUser selectById(@Param("id") int id);
+    List<TestUser> selectList();
+    int update(TestUser testUser);
+    int delete(@Param("id") int id);
+}
+

+ 13 - 0
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/service/TestUserService.java

@@ -0,0 +1,13 @@
+package com.siwei.apply.service;
+
+import com.siwei.apply.domain.TestUser;
+import java.util.List;
+
+public interface TestUserService {
+    int insert(TestUser testUser);
+    TestUser selectById(int id);
+    List<TestUser> selectList();
+    int update(TestUser testUser);
+    int delete(int id);
+}
+

+ 41 - 0
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/service/impl/TestUserServiceImpl.java

@@ -0,0 +1,41 @@
+package com.siwei.apply.service.impl;
+
+import com.siwei.apply.domain.TestUser;
+import com.siwei.apply.mapper.TestUserMapper;
+import com.siwei.apply.service.TestUserService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+public class TestUserServiceImpl implements TestUserService {
+    @Autowired
+    private TestUserMapper testUserMapper;
+
+    @Override
+    public int insert(TestUser testUser) {
+        return testUserMapper.insert(testUser);
+    }
+
+    @Override
+    public TestUser selectById(int id) {
+        return testUserMapper.selectById(id);
+    }
+
+    @Override
+    public List<TestUser> selectList() {
+        return testUserMapper.selectList();
+    }
+
+    @Override
+    public int update(TestUser testUser) {
+        return testUserMapper.update(testUser);
+    }
+
+    @Override
+    public int delete(int id) {
+        return testUserMapper.delete(id);
+    }
+}
+

+ 42 - 0
siwei-modules/siwei-apply/src/main/resources/mapper/TestUserMapper.xml

@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.siwei.apply.mapper.TestUserMapper">
+    <resultMap id="testUserMap" type="com.siwei.apply.domain.TestUser">
+        <id column="id" property="id"/>
+        <result column="name" property="name"/>
+        <result column="sex" property="sex"/>
+        <result column="age" property="age"/>
+        <result column="create_date" property="createDate"/>
+    </resultMap>
+
+    <insert id="insert" parameterType="com.siwei.apply.domain.TestUser">
+        INSERT INTO t_test_user (name, sex, age, create_date)
+        VALUES (#{name}, #{sex}, #{age}, #{createDate})
+    </insert>
+
+    <select id="selectById" resultMap="testUserMap" parameterType="int">
+        SELECT * FROM t_test_user WHERE id = #{id}
+    </select>
+
+    <select id="selectList" resultMap="testUserMap">
+        SELECT * FROM t_test_user
+    </select>
+
+    <update id="update" parameterType="com.siwei.apply.domain.TestUser">
+        UPDATE t_test_user
+        <set>
+            <if test="name != null">name = #{name},</if>
+            <if test="sex != null">sex = #{sex},</if>
+            <if test="age != null">age = #{age},</if>
+            <if test="createDate != null">create_date = #{createDate},</if>
+        </set>
+        WHERE id = #{id}
+    </update>
+
+    <delete id="delete" parameterType="int">
+        DELETE FROM t_test_user WHERE id = #{id}
+    </delete>
+</mapper>
+