第五次课

This commit is contained in:
zz 2024-09-11 10:15:17 +08:00
parent e10c1139c2
commit 09aacf0082
8 changed files with 122 additions and 0 deletions

View File

@ -28,5 +28,24 @@ public class PersonController {
return "personlist.html";
}
@RequestMapping("addpersonpage")
public String addPersonPage(){
return "addperson.html";
}
@RequestMapping
public String addPerson(Person person){
personService.addPerson(person);
return "redirect:personlist";
}
@RequestMapping("deleteperson")
public String deletePerson(int id){
personService.deletePerson(id);
return "redirect:personlist";
}
}

View File

@ -10,6 +10,10 @@ import java.util.List;
@Mapper
public interface PersonMapper {
public List<Person> getPersons();
public int addPerson(Person person);
public int deletePerson(int id);
public int updatePerson(Person person);
List<Person> searchPersonsbyName(String name);
}

View File

@ -6,4 +6,13 @@ import java.util.List;
public interface PersonService {
public List<Person> getPersons();
int addPerson(Person person);
int deletePerson(int id);
int updatePerson(Person person);
List<Person> searchPersonbyName(String name);
List<Person> searchPerson(String name);
}

View File

@ -18,4 +18,29 @@ public class PersonServiceimpl implements PersonService {
public List<Person> getPersons(){
return personMapper.getPersons();
}
@Override
public int addPerson(Person person){
return personMapper.addPerson(person);
}
@Override
public int deletePerson(int id){
return personMapper.deletePerson(id);
}
@Override
public int updatePerson(Person person){
return personMapper.updatePerson(person);
}
@Override
public List<Person> searchPersonbyName(String name) {
return List.of();
}
@Override
public List<Person> searchPerson(String name){
return personMapper.searchPersonsbyName(name);
}
}

View File

@ -6,5 +6,21 @@
select * from person;
</select>
<insert id="addPerson" parameterType="com.zhangzihao.springboot.springboot.model.Person">
insert into person(name,age) values(#{name},#{age});
</insert>
<delete id="deletePerson" parameterType="Integer">
delete from person where id=#{id};
</delete>
<update id="updatePerson" parameterType="com.zhangzihao.springboot.springboot.model.Person">
update person set name=#{name},age=#{age} where id=#{id};
</update>
<select id="searchPersonsbyName" parameterType="String" resultType="com.zhangzihao.springboot.springboot.model.Person">
select * from person where name like '%${name}%';
</select>
</mapper>

View File

@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1>添加人员信息</h1>
<from th:action="@{/addperson}" method="post">
<input type="text" name="name" placeholder="姓名"><br/>
<input type="text" name="age" placeholder="年龄"><br/>
<input type="submit" value="增加用户"></input>
</input>
</from>
</body>
</html>

View File

@ -6,6 +6,13 @@
</head>
<body>
<h1>人员列表页面</h1>
<form action="@{/personlist}"> method="post">
<input type="text" name="name" placeholder="请输入用户名字">
<input type="submit" value="搜索"></input>
</form>
<a th:href="@{/addpersonpage}">添加Person</a>
<table border="1">
<tr>
<td>id</td>
@ -17,6 +24,12 @@
<td th:text="${persons.id}"></td>
<td th:text="${persons.name}"></td>
<td th:text="${persons.age}"></td>
<td>
<a th:href="@{'/deleteperson?id='+${persons.id}}">删除</a>
</td>
<td>
<a th:href="@{/updatepersonpage(id=${persons.id},age=${person.age},name=${person.name})}">更新</a>
</td>
</tr>
</table>

View File

@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1>更新人员页面</h1>
<form th:action="@{/updateperson}" method="post">
<input type="id" th:name="id" th:value="${person.id}" hidden="hidden"><br/>
<input type="text" th:name="name" placeholder="姓名" th:value="${person.name}"><br>
<input type="text" th:name="age" placeholder=" 年龄" th:value="${person.age}"><br>
<input type="submit" value="更新用户"></input>
</br>
</br>
</input>
</form>
</body>
</html>