微服务 教程
1085个小节阅读:195.7k
C语言快速入门
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
xxxxxxxxxx
CREATE DATABASE `student`;
USE `student`;
DROP TABLE IF EXISTS `student`;
CREATE TABLE `student` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL,
`sex` varchar(10) DEFAULT NULL,
`address` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
insert into `student`(`id`,`name`,`sex`,`address`) values (1,'百战程序员','男','北京'),(2,'北京尚学堂','女','北京');
xxxxxxxxxx
public class Student {
private int id;
private String name;
private String sex;
private String address;
// 省略构造方法/getter/setter/tostring
}
xxxxxxxxxx
public interface StudentDao {
// 查询所有学生
"select * from student") (
List<Student> findAll();
// 添加学生
"insert into student values(null,#{name},#{sex},#{address})") (
void add(Student student);
}
xxxxxxxxxx
public class StudentService {
// SqlSession对象
private SqlSessionTemplate sqlSession;
// 使用SqlSession获取代理对象
public List<Student> findAllStudent(){
StudentDao studentDao = sqlSession.getMapper(StudentDao.class);
return studentDao.findAll();
}
}