202201080136 qijun

This commit is contained in:
qijun202201080136 2024-10-11 10:59:51 +08:00
parent a692fcf6c3
commit 7bfcfc22df
7 changed files with 29 additions and 22 deletions

View File

@ -4,10 +4,11 @@ import edu.qijun.pojo.Account;
import java.util.List;
import edu.qijun.pojo.Student;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@Mapper
public interface AccountMapper {
List<Student>getStudents();
void insertAccount(Account account);
List<Student> getStudents();
void insertAccount(Account account); // 添加了 @Param 注解
}

View File

@ -10,6 +10,6 @@ public interface ScoreMapper {
void deleteById(Integer id); // 修正了方法名
void deleteByIds(@Param("ids") List<Integer> ids);
void deleteByIds(List<Integer> ids);
// 假设你想要删除多个ID通常复数形式更合适
}

View File

@ -3,7 +3,7 @@ package edu.qijun.mapper;
import edu.qijun.pojo.Student;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@ -13,10 +13,10 @@ public interface StudentMapper {
List<Student> getAll();
Student getById(String id);
Student getById(Integer id);
Student getByCondition(Integer len,Integer gender);
List<Student> getByCondition(Integer len,Integer gender);
void insertStudent(Student student);

View File

@ -12,6 +12,7 @@ public class Student extends BaseEntity{
private String name;
private Integer gender;
private LocalDate birthday;
//private Integer createBy;
private LocalDateTime updateTime;

View File

@ -6,11 +6,12 @@
<select id="selectAccount" resultType="Account">
SELECT * FROM account WHERE id = #{id}
</select>
<insert id="insertAccount" useGeneratedKeys="true" keyProperty="id" parameterType="edu.qijun.pojo.Account">
<insert id="insertAccount" useGeneratedKeys="true" keyProperty="id">
insert into account(account, password, role, create_by, create_time)
values(#{account}, #{password}, #{role}, #{createBy}, #{createTime})
</insert>
<select id="getStudents" resultType="edu.qijun.pojo.Student">
SELECT id, name, age, create_by, create_time
FROM student

View File

@ -8,10 +8,8 @@
values(#{studentId}, #{courseId}, #{score}, #{createBy}, #{createTime})
</insert>
<insert id="insertStudent" useGeneratedKeys="true" keyProperty="id">
insert into student (name, gender, birthday, create_by, create_time)
values (#{name}, #{gender}, #{birthday}, #{createBy}, #{createTime})
</insert>
<delete id="deleteById">
@ -21,7 +19,7 @@
<delete id="deleteByIds">
DELETE FROM score WHERE id IN
<foreach collection="ids" item="id" open="(" separator="," close=")">
#{ids}
#{id}
</foreach>
</delete>
</mapper>

View File

@ -9,15 +9,18 @@
<update id="update">
update student
<set>
<if test="name!=null">name=#{name},</if>
<if test="gender!=null">gender=#{gender},</if>
<if test="birthday!=null">birthday=#{birthday},</if>
<if test="updateBy!=null">update_by=#{updateBy},</if>
<if test="updateTime!=null">update_time=#{updateTime}</if>
<if test="name != null">name=#{name},</if>
<if test="gender != null">gender=#{gender},</if>
<if test="birthday != null">birthday=#{birthday},</if>
<if test="updateBy != null">update_by=#{updateBy},</if>
<if test="updateTime != null">update_time=#{updateTime}</if>
</set>
where id=#{id}
<where>
id=#{id}
</where>
</update>
<select id="getAll" resultType="edu.qijun.pojo.Student">
<include refid="commonSelect"></include>
@ -31,16 +34,19 @@
<select id="getByCondition" resultType="edu.qijun.pojo.Student">
<include refid="commonSelect"></include>
<where>
<if test="len!=null">CHAR_LENGTH(student.name)=#{len}</if>
<if test="gender!=null">and gender =#{gender}</if>
<if test="len!=null">CHAR_LENGTH(student.name)=#{len}</if>
<if test="gender!=null">and gender =#{gender}</if>
</where>
</select>
<insert id="insertStudent">
insert into student (id, name, gender, birthday, create_by, create_time)
values (#{id}, #{name}, #{gender}, #{birthday}, #{createBy}, #{createTime})
insert into student(id, name, gender, birthday, create_by, create_time)
values(#{id}, #{name}, #{gender}, #{birthday}, #{createBy}, #{createTime})
</insert>
</mapper>