MyBatis工程搭建

本文介绍了如何在NetBeans中搭建MyBatis工程,包括引入MySQL依赖、JDBC数据库连接、编程式配置以及通过配置文件设置MyBatis。详细步骤包括创建项目、添加MySQL驱动依赖、数据库与表的建立、实体类与Dao接口的定义、配置mybatis-config.xml和Mapper文件,最后通过测试方法验证配置的正确性。
摘要由CSDN通过智能技术生成

引入MyBatis依赖

1.使用netbeans创建项目,选择文件->新建项目->Maven->Web应用程序;

2.打开项目目录,在依赖关系上右击->添加依赖关系->查询框输入mysql->选择mysql:mysql-connector-java->点开选择对应的mysql驱动版本.

JDBC链接及操作数据库

3.创建数据库和表

create database foretaste;
use foretaste
create table user_info(id int(11) not null primary key auto_increment,
 nickname varchar(50) not null, phone_num char(11) not null, 
 created_time timestamp not null default current_timestamp, 
 last_update_time timestamp not null default current_timestamp);

编程式配置方法

4.创建UserInfo的实体

package com.shadow.foretaste.entity;

import java.util.Date;

/**
 *
 * @author sunny
 */
public class UserInfo {
   
    private int id;
    private String nickname;
    private String phoneNum;
    private Date createdTime;
    private Date lastUpdateTime;

    public int getId() {
   
        return id;
    }

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

    public String getNickname() {
   
        return nickname;
    }

    public void setNickname(String nickname) {
   
        this.nickname = nickname;
    }

    public
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值