第8次课

This commit is contained in:
zhangping 2024-09-12 16:05:46 +08:00
parent 2d1b703833
commit 8757b391cb
13 changed files with 214 additions and 7 deletions

View File

@ -60,17 +60,37 @@
<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>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>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
<version>3.5.7</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId>
<version>3.5.7</version>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.31</version>
</dependency>
</dependencies>
<build>

View File

@ -0,0 +1,34 @@
package com.zp.spring.springboot;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import java.nio.file.Paths;
public class Main
{
public static void main(String[] args)
{
FastAutoGenerator.create("jdbc:mysql://106.53.194.250:63306/mybatis202101080126?serverTimezone=UTC"
, "202101080126", "@hnucm1254")
.globalConfig(builder -> builder
.author("zhangping")
.outputDir(Paths.get(System.getProperty("user.dir")) + "/src/main/java")
.commentDate("yyyy-MM-dd")
)
.packageConfig(builder -> builder
.parent("com.zp.spring.springboot")
.entity("model")
.mapper("dao")
.service("service")
.serviceImpl("service.impl")
.xml("mapper.xml")
)
.strategyConfig(builder -> builder
.entityBuilder()
.enableLombok()
)
.templateEngine(new FreemarkerTemplateEngine())
.execute();
}
}

View File

@ -10,6 +10,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
@Controller
public class PersonController {
@Autowired

View File

@ -0,0 +1,42 @@
package com.zp.spring.springboot.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zp.spring.springboot.model.Student;
import com.zp.spring.springboot.service.IStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("/student")
public class StudentController {
//增删改查方法
@Autowired
IStudentService studentService;
@RequestMapping("studentlist")
public String getStudent(Model model){
Page<Student>page=new Page<>(1,5);
model.addAttribute("studentlist",studentService.page(page).getRecords());
// QueryWrapper<Student> queryWrapper=new QueryWrapper<>();
// queryWrapper.like("name","test");
//
// model.addAttribute("studentlist",
// studentService.getBaseMapper().selectList(queryWrapper));
return "studentlist.html";
}
@RequestMapping("addstudentpage")
public String addStudentPage(){
return "addstudent.html";
}
@RequestMapping("addstudent")
public String addStudent(String name,int age,String classname){
Student student=new Student();
student.setAge(age);
student.setName(name);
student.setClassname(classname);
studentService.save(student);
return "redirect:/student/studentlist";
}
}

View File

@ -0,0 +1,17 @@
package com.zp.spring.springboot.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zp.spring.springboot.model.Student;
import org.apache.ibatis.annotations.Mapper;
/**
* <p>
* Mapper 接口
* </p>
*
* @author 张三
* @since 2024-09-12
*/
@Mapper
public interface StudentMapper extends BaseMapper<Student> {
}

View File

@ -0,0 +1,31 @@
package com.zp.spring.springboot.model;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import java.io.Serializable;
import lombok.Getter;
import lombok.Setter;
/**
* <p>
*
* </p>
*
* @author 张三
* @since 2024-09-12
*/
@Getter
@Setter
public class Student implements Serializable {
private static final long serialVersionUID = 1L;
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
private Integer age;
private String name;
private String classname;
}

View File

@ -0,0 +1,7 @@
package com.zp.spring.springboot.service;
import com.zp.spring.springboot.model.Student;
public interface IStudentService {
}

View File

@ -0,0 +1,20 @@
package com.zp.spring.springboot.service.Impl;
import com.zp.spring.springboot.model.Student;
import com.zp.spring.springboot.dao.StudentMapper;
import com.zp.spring.springboot.service.IStudentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
/**
* <p>
* 服务实现类
* </p>
*
* @author 张三
* @since 2024-09-12
*/
@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements IStudentService {
}

View File

@ -0,0 +1,5 @@
package com.zp.spring.springboot.utils;
public class MybatisPlusConfig
{
}

View File

@ -14,7 +14,7 @@ spring.datasource.username=202101080126
spring.datasource.password=@hnucm1254
mybatis.mapper-locations=classpath:mapper/*.xml
mybatis-plus.mapper-locations=classpath:mapper/*.xml
mybatis.type-aliases-package=com.zp.spring.springboot.model;

View File

@ -0,0 +1,5 @@
<?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.zp.spring.springboot.dao.StudentMapper">
</mapper>

View File

@ -30,7 +30,7 @@
<td th:text="${person.id}"></td>
<td th:text="${person.age}"></td>
<td th:text="${person.name}"></td>
<div th:text="${person.idCard}!=null">
<div th:if="${person.idCard}!=null">
<td th:text="${person.idCard.stuid}"></td>
<td th:text="${person.idCard.classname}"></td>

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>
<td>班级</td>
</tr>
<tr th:each="student:${studentlist}">
<td th:text="${student.id}"></td>
<td th:text="${student.age}"></td>
<td th:text="${student.name}"></td>
<td th:text="${student.classname}"></td>
</tr>
</table>
</body>
</html>