diff --git a/springboot/pom.xml b/springboot/pom.xml index 4586b9a..5944d35 100644 --- a/springboot/pom.xml +++ b/springboot/pom.xml @@ -60,6 +60,17 @@ spring-boot-starter-test test + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + 3.0.3 + + + mysql + mysql-connector-java + 8.0.25 + diff --git a/springboot/src/main/java/com/zhangzihao/springboot/springboot/Controllor/PersonController.java b/springboot/src/main/java/com/zhangzihao/springboot/springboot/Controllor/PersonController.java new file mode 100644 index 0000000..57cada3 --- /dev/null +++ b/springboot/src/main/java/com/zhangzihao/springboot/springboot/Controllor/PersonController.java @@ -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 getPersons(){ + return personService.getPersons(); + }; + + @RequestMapping("personlist") + public String personlist(Model model){ + model.addAttribute("personlist",personService.getPersons()); + return "personlist.html"; + } + + +} diff --git a/springboot/src/main/java/com/zhangzihao/springboot/springboot/dao/PersonMapper.java b/springboot/src/main/java/com/zhangzihao/springboot/springboot/dao/PersonMapper.java new file mode 100644 index 0000000..c34f7d0 --- /dev/null +++ b/springboot/src/main/java/com/zhangzihao/springboot/springboot/dao/PersonMapper.java @@ -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 getPersons(); + + +} diff --git a/springboot/src/main/java/com/zhangzihao/springboot/springboot/model/Person.java b/springboot/src/main/java/com/zhangzihao/springboot/springboot/model/Person.java new file mode 100644 index 0000000..5e626d2 --- /dev/null +++ b/springboot/src/main/java/com/zhangzihao/springboot/springboot/model/Person.java @@ -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; +} diff --git a/springboot/src/main/java/com/zhangzihao/springboot/springboot/service/PersonService.java b/springboot/src/main/java/com/zhangzihao/springboot/springboot/service/PersonService.java new file mode 100644 index 0000000..0ddb6a9 --- /dev/null +++ b/springboot/src/main/java/com/zhangzihao/springboot/springboot/service/PersonService.java @@ -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 getPersons(); +} diff --git a/springboot/src/main/java/com/zhangzihao/springboot/springboot/service/impl/PersonServiceimpl.java b/springboot/src/main/java/com/zhangzihao/springboot/springboot/service/impl/PersonServiceimpl.java new file mode 100644 index 0000000..e639c49 --- /dev/null +++ b/springboot/src/main/java/com/zhangzihao/springboot/springboot/service/impl/PersonServiceimpl.java @@ -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 getPersons(){ + return personMapper.getPersons(); + } +} diff --git a/springboot/src/main/resources/application.properties b/springboot/src/main/resources/application.properties index d0bceb4..b590996 100644 --- a/springboot/src/main/resources/application.properties +++ b/springboot/src/main/resources/application.properties @@ -1,4 +1,21 @@ spring.application.name=springboot #server.port=80 #server.servlet.context-path=springboot -spring.web.resources.static-locations=classpath:/static/ \ No newline at end of file +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 \ No newline at end of file diff --git a/springboot/src/main/resources/mapper/PersonMapper.xml b/springboot/src/main/resources/mapper/PersonMapper.xml new file mode 100644 index 0000000..054727f --- /dev/null +++ b/springboot/src/main/resources/mapper/PersonMapper.xml @@ -0,0 +1,10 @@ + + + + + + + + \ No newline at end of file diff --git a/springboot/src/main/resources/templates/personlist.html b/springboot/src/main/resources/templates/personlist.html new file mode 100644 index 0000000..99ced0d --- /dev/null +++ b/springboot/src/main/resources/templates/personlist.html @@ -0,0 +1,24 @@ + + + + + Title + + +

人员列表页面

+ + + + + + + + + + + + +
id姓名年龄
+ + + \ No newline at end of file