11. 顾客信息管理

79 字约 1 分钟读完642 次阅读更新于 2026/5/3

user表

CREATE TABLE `user` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID',
  `username` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '账号',
  `password` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '密码',
  `name` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '名称',
  `avatar` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '头像',
  `role` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '角色',
  `sex` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '性别',
  `phone` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '手机号',
  `account` decimal(10,2) DEFAULT '0.00' COMMENT '账户余额',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='用户信息';

404问题?
接口写错了
没重启后台

后台

UserMapper.xml

<?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.example.mapper.UserMapper">


    <insert id="insert">
        insert into user (username, password, name, avatar, role, sex, phone)
        values (#{username}, #{password}, #{name}, #{avatar}, #{role}, #{sex}, #{phone})
    </insert>


    <update id="updateById">
        update user
        <set>
            <if test="username != null"> username = #{username}, </if>
            <if test="password != null"> password = #{password}, </if>
            <if test="name != null"> name = #{name}, </if>
            <if test="avatar != null"> avatar = #{avatar}, </if>
            <if test="role != null"> role = #{role}, </if>
            <if test="sex != null"> sex = #{sex}, </if>
            <if test="phone != null"> phone = #{phone}, </if>
            <if test="account != null"> account = #{account}, </if>
        </set>
        where id = #{id}
    </update>

    <delete id="deleteById">
        delete from user where id = #{id}
    </delete>

    <select id="selectAll" resultType="com.example.entity.User">
        select * from user
        <where>
            <if test="name != null">
                name like concat('%', #{name}, '%')
            </if>
        </where>
        order by id desc
    </select>


</mapper>

UserMapper

package com.example.mapper;

import com.example.entity.User;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface UserMapper {


    @Select("select * from user where username = #{username}")
    User selectByUsername(String username);

    void insert(User user);

    void deleteById(Integer id);

    void updateById(User user);

    @Select("select * from user where id = #{id}")
    User selectById(Integer id);

    List<User> selectAll(String name);

}

UserService

UserController

前台Vue页面