第三次提交

This commit is contained in:
zz 2024-09-05 16:20:33 +08:00
parent de24d849aa
commit 8e7e554b1b
9 changed files with 150 additions and 1 deletions

View File

@ -60,6 +60,17 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>3.0.3</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.25</version>
</dependency>
</dependencies>
<build>

View File

@ -0,0 +1,32 @@
package com.zhangzihao.springboot.springboot.Controllor;
import com.zhangzihao.springboot.springboot.model.Person;
import com.zhangzihao.springboot.springboot.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
@Controller
public class PersonController {
@Autowired
private PersonService personService;
@ResponseBody
@RequestMapping("getpersons")
public List<Person> getPersons(){
return personService.getPersons();
};
@RequestMapping("personlist")
public String personlist(Model model){
model.addAttribute("personlist",personService.getPersons());
return "personlist.html";
}
}

View File

@ -0,0 +1,15 @@
package com.zhangzihao.springboot.springboot.dao;
import com.zhangzihao.springboot.springboot.model.Person;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
//实现写配置文件中
@Mapper
public interface PersonMapper {
public List<Person> getPersons();
}

View File

@ -0,0 +1,10 @@
package com.zhangzihao.springboot.springboot.model;
import lombok.Data;
@Data
public class Person {
private String name;
private int age;
private int id;
}

View File

@ -0,0 +1,9 @@
package com.zhangzihao.springboot.springboot.service;
import com.zhangzihao.springboot.springboot.model.Person;
import java.util.List;
public interface PersonService {
public List<Person> getPersons();
}

View File

@ -0,0 +1,21 @@
package com.zhangzihao.springboot.springboot.service.impl;
import com.zhangzihao.springboot.springboot.dao.PersonMapper;
import com.zhangzihao.springboot.springboot.model.Person;
import com.zhangzihao.springboot.springboot.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class PersonServiceimpl implements PersonService {
@Autowired
private PersonMapper personMapper;
@Override
public List<Person> getPersons(){
return personMapper.getPersons();
}
}

View File

@ -1,4 +1,21 @@
spring.application.name=springboot
#server.port=80
#server.servlet.context-path=springboot
spring.web.resources.static-locations=classpath:/static/
spring.web.resources.static-locations=classpath:/static/
# ??????
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
# ?????
spring.datasource.name=defaultDataSource
# ???????
spring.datasource.url=jdbc:mysql://106.53.194.250:63306/202101080104?serverTimezone=UTC
# ??????&???
spring.datasource.username=202101080104
spring.datasource.password=@hnucm1254
#??????????MyBatis??
#??Mybatis?Mapper??
mybatis.mapper-locations=classpath:mapper/*.xml
#??Mybatis?????
mybatis.type-aliases-package=com.example.springmybatis.pojo
logging.level.com.example.springmybatis = debug

View File

@ -0,0 +1,10 @@
<?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.PersonMapper">
<select id="getPersons" resultType="com.zhangzihao.springboot.springboot.model.Person">
select * from person;
</select>
</mapper>

View File

@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1>人员列表页面</h1>
<table border="1">
<tr>
<td>id</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>
</tr>
</table>
</body>
</html>