所花时间(包括上课): |
2h |
代码量(行): |
150左右 |
搏客量(篇): |
1 |
了解到的知识点: |
mybits |
备注(其他): |
private
static
SqlSessionFactory sqlSessionFactory;
static
{
try
{
String resource =
"mybatis-config.xml"
;
InputStream inputStream = Resources.getResourceAsStream(resource);
sqlSessionFactory =
new
SqlSessionFactoryBuilder().build(inputStream);
}
catch
(IOException e) {
throw
new
RuntimeException(e);
}
}
public
static
SqlSession getSqlSession()
{
return
sqlSessionFactory.openSession();
}
private
int
id;
private
String StudentName;
private
String gender;
private
int
age;
public
Student() {
}
public
Student(
int
id, String studentName, String gender,
int
age) {
this
.id = id;
StudentName = studentName;
this
.gender = gender;
this
.age = age;
}
public
int
getId() {
return
id;
}
public
void
setId(
int
id) {
this
.id = id;
}
public
String getStudentName() {
return
StudentName;
}
public
void
setStudentName(String studentName) {
StudentName = studentName;
}
public
String getGender() {
return
gender;
}
public
void
setGender(String gender) {
this
.gender = gender;
}
public
int
getAge() {
return
age;
}
public
void
setAge(
int
age) {
this
.age = age;
}
@Override
public
String toString() {
return
"Student{"
+
"id="
+ id +
", StudentName='"
+ StudentName + '\
''
+
", gender='"
+ gender + '\
''
+
", age="
+ age +
'}'
;
}
package com.xx.dao;
import com.xx.pojo.Student;
import java.util.List;
public interface studentMapper {
//查询全部学生
List<Student> getAllStudents();
//根据学号查找学生
Student getStudentById(int id);
//添加学生
int addStudent(Student stu);
//修改信息
int updateStudent(Student stu);
//删除学生信息
int deleteStudent(int id);
}
<?xml version="1.0" encoding="UTF-8" ?>标签:学习,String,int,gender,age,id,mybits,public From: https://www.cnblogs.com/pinganxile/p/18256808
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.xx.dao.studentMapper">
<select id="getAllStudents" resultType="com.xx.pojo.Student" >
select * from db_stu.student
</select>
<select id="getStudentById" resultType="com.xx.pojo.Student" parameterType="int">
select * from db_stu.student where id =#{id}
</select>
<insert id="addStudent" parameterType="com.xx.pojo.Student">
insert into db_stu.student(id,StudentName,gender,age) values(#{id},#{StudentName},#{gender},#{age})
</insert>
<update id="updateStudent" parameterType="com.xx.pojo.Student">
update db_stu.student set StudentName=#{StudentName},gender=#{gender},age=#{age} where id=#{id};
</update>
<delete id="deleteStudent" parameterType="int">
delete from db_stu.student where id =#{id};
</delete>
</mapper>