Springboot2模块系列:thymeleaf+Bootstrap(二)前后端结合--数据库设计及操作

本文详细介绍了一个用户信息管理系统的数据库设计,包括数据库结构的创建、实体类定义及数据库操作的增删改查。通过MyBatis的XML映射文件实现对用户信息的高效管理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1 数据库

1.0 数据库结构

CREATE DATABASE `data_repository` DEFAULT CHARACTER SET utf8;
USE `data_repository`;

DROP TABLE IF EXISTS `userinfos`;
CREATE TABLE `userinfos`(
    `id` INT(11) NOT NULL AUTO_INCREMENT,
    `username` VARCHAR(255) DEFAULT NULL,
    `password` VARCHAR(255) DEFAULT NULL,
    `email` VARCHAR(255) DEFAULT NULL,
    `sex` VARCHAR(255) DEFAULT NULL,
    `position` VARCHAR(255) DEFAULT NULL,
    `telephone_num` VARCHAR(255) DEFAULT NULL,
    PRIMARY KEY(`id`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;

1.2 实体类

package com.company.web.po;

import java.io.Serializable;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

@JsonIgnoreProperties(value={"handler"})
public class UserInfos implements Serializable{
    private Integer id;
    private String username;
    private String password;
    private String email;
    private String sex;
    private String position;
    private String telephoneNum;

    public void setId(Integer id){
        this.id = id;
    }

    public Integer getId(){
        return id;
    }
    
    public void setUsername(String username){
        this.username = username;
    }

    public String getUsername(){
        return username;
    }

    public void setPassword(String password){
        this.password = password;
    }

    public String getPassword(){
        return password;
    }

    public void setEmail(String email){
        this.email = email;
    }

    public String getEmail(){
        return email;
    }

    public void setSex(String sex){
        this.sex = sex;
    }

    public String getSex(){
        return sex;
    }

    public void setPosition(String position){
        this.position = position;
    }

    public String getPosition(){
        return position;
    }

    public void setTelephoneNum(String telephoneNum){
        this.telephoneNum = telephoneNum;
    }

    public String getTelephoneNum(){
        return telephoneNum;
    }
}

2 数据库操作

2.1 增删改查

<?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.company.web.mapper.UserInfosMapper">
    <resultMap id="userInfosMap" type="com.company.web.po.UserInfos">
        <result property="id" column="id"/>
        <result property="username" column="username"/>
        <result property="email" column="email"/>
        <result property="sex" column="sex"/>
        <result property="position" column="position"/>
        <result property="telephoneNum" column="telephone_num"/>
    </resultMap>
    <insert id="addUser" parameterType="map">
        insert into userinfos 
        (username, password, email, sex, position, telephone_num)
        values 
        (#{username}, #{password}, #{email}, #{sex}, #{position}, #{telephoneNum})
    </insert>
    <delete id="deleteUser" parameterType="integer">
        delete from userinfos where id=#{id}
    </delete>
    <update id="editUser" parameterType="map">
        update userinfos set username=#{username}, password=#{password}, email=#{email}, sex=#{sex}, position=#{position}, telephone_num=#{telephoneNum}
        where id=#{id}
    </update>
    <select id="queryUser" parameterType="map" resultMap="userInfosMap">
        select * from userinfos
        <where>
            <if test="username != ''">
                and username like "%"#{username}"%"
            </if>
        </where>
    </select>
    <select id="queryUserWithId" parameterType="integer" resultMap="userInfosMap">
        select * from userinfos where id=#{id}
    </select>
    <select id="loginByEmail" parameterType="string" resultMap="userInfosMap">
        select username, email, password from userinfos where email=#{email}
    </select>
</mapper>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

天然玩家

坚持才能做到极致

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值