9月12日下午课堂提交
This commit is contained in:
parent
cad675000c
commit
811d23b778
|
@ -61,16 +61,36 @@
|
|||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<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>
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
package com.zhangzihao.springboot.springboot.Controllor;
|
||||
|
||||
import com.zhangzihao.springboot.springboot.model.Student;
|
||||
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){
|
||||
model.addAttribute("studentlist",studentService.list());
|
||||
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";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package com.zhangzihao.springboot.springboot.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.zhangzihao.springboot.springboot.model.Student;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author 张三
|
||||
* @since 2024-09-12
|
||||
*/
|
||||
@Mapper
|
||||
public interface StudentMapper extends BaseMapper<Student> {
|
||||
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package com.zhangzihao.springboot.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;
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package com.zhangzihao.springboot.springboot.service;
|
||||
|
||||
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/202101080104?serverTimezone=UTC",
|
||||
"202101080104", "@hnucm1254")
|
||||
.globalConfig(builder -> builder
|
||||
.author("Baomidou")
|
||||
.outputDir(Paths.get(System.getProperty("user.dir")) + "/src/main/java")
|
||||
.commentDate("yyyy-MM-dd")
|
||||
)
|
||||
.packageConfig(builder -> builder
|
||||
.parent("com.baomidou.mybatisplus")
|
||||
.entity("entity")
|
||||
.mapper("mapper")
|
||||
.service("service")
|
||||
.serviceImpl("service.impl")
|
||||
.xml("mapper.xml")
|
||||
)
|
||||
.strategyConfig(builder -> builder
|
||||
.entityBuilder()
|
||||
.enableLombok()
|
||||
)
|
||||
.templateEngine(new FreemarkerTemplateEngine())
|
||||
.execute();
|
||||
}
|
||||
}
|
|
@ -14,8 +14,8 @@ spring.datasource.username=202101080104
|
|||
spring.datasource.password=@hnucm1254
|
||||
#??????????MyBatis??
|
||||
#??Mybatis?Mapper??
|
||||
mybatis.mapper-locations=classpath:mapper/*.xml
|
||||
mybatis-plus.mapper-locations=classpath:mapper/*.xml
|
||||
#??Mybatis?????
|
||||
mybatis.type-aliases-package=com.example.springmybatis.pojo
|
||||
mybatis-plus.type-aliases-package=com.example.springmybatis.entity
|
||||
|
||||
logging.level.com.example.springmybatis = debug
|
|
@ -7,4 +7,16 @@
|
|||
select * from order where userid=#{id};
|
||||
</select>
|
||||
|
||||
<resultMap id="OrderMap" type="">
|
||||
<id column="id" property="id"/>
|
||||
<result column="userid" property="userid"/>
|
||||
<result column="orderprice" property="orderprice"/>
|
||||
<result column="orderinfo" property="orderinfo"/>
|
||||
<collection property="orderdetailList"
|
||||
ofType=""
|
||||
select="com.zhangzihao.springboot.springboot.dao.OrderDetailMapper.getOrderDetailByOrderId"
|
||||
column="id">
|
||||
|
||||
</collection>
|
||||
|
||||
</mapper>
|
|
@ -0,0 +1,18 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Title</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>添加人员页面</h1>
|
||||
|
||||
<from th:action="@{/student/addstudent}" method="post">
|
||||
<input type="text" name="name" placeholder="姓名"><br/>
|
||||
<input type="text" name="age" placeholder="年龄"><br/>
|
||||
<input type="text" name="classname" placeholder="班级"><br/>
|
||||
<input type="submit" value="增加用户"></input>
|
||||
</input>
|
||||
</from>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,25 @@
|
|||
<!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.name}"></td>
|
||||
<td th:text="${student.age}"></td>
|
||||
<td th:text="${student.className}"></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue