一、项目结构及依赖包
二、建库
-- phpMyAdmin SQL Dump
-- version 4.6.4
-- https://www.phpmyadmin.net/
--
-- Host: localhost
-- Generation Time: 2017-12-27 13:44:25
-- 服务器版本: 5.7.14
-- PHP Version: 5.6.26
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Database: `test`
--
-- --------------------------------------------------------
--
-- 表的结构 `t_user`
--
CREATE TABLE `t_user` (
`userId` int(11) NOT NULL,
`userName` varchar(20) DEFAULT NULL,
`password` varchar(20) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- 转存表中的数据 `t_user`
--
INSERT INTO `t_user` (`userId`, `userName`, `password`) VALUES
(1, 'wxw1', '123'),
(3, 'wxw3', '123'),
(4, 'wxw4', '4444'),
(8, 'wxw8', '1234'),
(2, '王弈伟', '123');
--
-- Indexes for dumped tables
--
--
-- Indexes for table `t_user`
--
ALTER TABLE `t_user`
ADD PRIMARY KEY (`userId`),
ADD UNIQUE KEY `userName` (`userName`,`password`);
--
-- 在导出的表使用AUTO_INCREMENT
--
--
-- 使用表AUTO_INCREMENT `t_user`
--
ALTER TABLE `t_user`
MODIFY `userId` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=9;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
三、DAO实现
实体pojo
package test.SpringMVC.model;
public class TUser {
private long userId;
private String userName;
private String password;
public long getUserId() {
return userId;
}
public void setUserId(long userId) {
this.userId = userId;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@Override
public String toString() {
return "TUser [userId=" + userId + ", userName=" + userName + ", password=" + password + "]";
}
}
接口
package test.SpringMVC.dao;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import test.SpringMVC.model.TUser;
public interface ITUserDao {