第六次课提交

This commit is contained in:
zz 2024-09-11 16:01:12 +08:00
parent 09aacf0082
commit b5e9732b2c
8 changed files with 70 additions and 1 deletions

View File

@ -0,0 +1,6 @@
package com.zhangzihao.springboot.springboot.dao;
public interface IdcardMapper {
public IdCard getIdCard(int id);
public int deleteIdCard(int id);
}

View File

@ -0,0 +1,10 @@
package com.zhangzihao.springboot.springboot.dao;
import com.zhangzihao.springboot.springboot.model.Person;
import java.util.List;
public interface PersonidcardMapper {
public List<Person> getAllPersons();
public List<Person> getAllPersons1();
}

View File

@ -7,4 +7,5 @@ public class Person {
private String name;
private int age;
private int id;
private IdCard idCard;
}

View File

@ -0,0 +1,4 @@
package com.zhangzihao.springboot.springboot.model;
public class idCard {
}

View File

@ -1,6 +1,7 @@
package com.zhangzihao.springboot.springboot.service.impl;
import com.zhangzihao.springboot.springboot.dao.PersonMapper;
import com.zhangzihao.springboot.springboot.dao.PersonidcardMapper;
import com.zhangzihao.springboot.springboot.model.Person;
import com.zhangzihao.springboot.springboot.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
@ -14,6 +15,14 @@ public class PersonServiceimpl implements PersonService {
@Autowired
private PersonMapper personMapper;
@Autowired
private PersonidcardMapper personIdcardMapper;
@Override
public List<Person> getPersons(){
return personIdcardMapper.getAllPersons1();
}
@Override
public List<Person> getPersons(){
return personMapper.getPersons();

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zhangzihao.springboot.springboot.dao.PersonidcardMapper">
<select id="getIdcard" resultType="com.zhangzihao.springboot.springboot.dao.PersonidcardMapper"
select * from idcard where id=#{id};
</select>
<delete id="deleteIdcard" parameterType="Integer">
delete from idcard where id = #{id};
</delete>
</mapper>

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zhangzihao.springboot.springboot.dao.PersonidcardMapper">
<select id="getAllPersons1" resultMap="PersonMap1">
select * from person
</select>
<resultMap id="PersonMap1" type="com.zhangzihao.springboot.springboot.model.Person">
<id column="id" property="id"/>
<result column="name" property="name"/>
<result column="age" property="age"/>
<association property="idCard"
column="idcardid"
select="com.zhangzihao.springboot.springboot.model.idCard"
javaType="com.zhangzihao.springboot.springboot.model.idCard">
</association>
</resultMap>
</mapper>

View File

@ -18,14 +18,20 @@
<td>id</td>
<td>姓名</td>
<td>年龄</td>
<td>学号</td>
<td>班级</td>
<td>删除操作</td>
<td>更新操作</td>
</tr>
<tr th:each="person:${persons}">
<td th:text="${persons.id}"></td>
<td th:text="${persons.name}"></td>
<td th:text="${persons.age}"></td>
<td th:text="${persons.idCard.stuid}"></td>
<td th:text="${persons.idCard.className}"></td>
<td>
<a th:href="@{'/deleteperson?id='+${persons.id}}">删除</a>
<a th:href="@{/deleteperson(id=${persons.id},idcardid=${person.idCard.id})}">删除</a>
</td>
<td>
<a th:href="@{/updatepersonpage(id=${persons.id},age=${person.age},name=${person.name})}">更新</a>