idea maven first mybatis program

Idea: Build a database -> create a maven project -> import mybatis -> write code -> test

Build a database

CREATE DATABASE `mybatis`;

USE `mybatis`;

CREATE TABLE `user`(
  `id` INT(20) NOT NULL PRIMARY KEY,
  `name` VARCHAR(30) DEFAULT NULL,
  `pwd` VARCHAR(30) DEFAULT NULL
)ENGINE=INNODB DEFAULT CHARSET=utf8;

INSERT INTO `user`(`id`,`name`,`pwd`) VALUES 
(1,'狂神','123456'),
(2,'张三','123456'),
(3,'李四','123890')

Create a normal maven project

  • new project—>next
    Insert picture description here
    name: project name
    location: project directory
  • finish
  • file----->setting
  • Insert picture description here
    Insert picture description here
    Insert picture description here

Delete src

Insert picture description here

Import maven dependencies

Insert picture description here

new module

Insert picture description here

  • Write core configuration files
    Insert picture description here
  • Write mybatis tool class
    Insert picture description here
  • Writing entity classes
    Insert picture description here
  • dao interface
    Insert picture description here
  • Interface implementation class
    Insert picture description here
  • The mapper is registered
    in the core configuration file
    Insert picture description here

test

  • junit test
    Insert picture description here

Insert picture description here
Insert picture description here

Finally successfully found the data

Insert picture description here

Guess you like

Origin blog.csdn.net/qq_45618376/article/details/114730442