第八次课
This commit is contained in:
parent
0e1642448b
commit
6b28804ac2
|
@ -60,12 +60,23 @@
|
|||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</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.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
<version>3.0.3</version>
|
||||
<groupId>org.freemarker</groupId>
|
||||
<artifactId>freemarker</artifactId>
|
||||
<version>2.3.31</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
package com.raohanghui.springboot.springboot.Controllor;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
@Controller
|
||||
public class NewsController {
|
||||
@RequestMapping("/news/{newsid}")
|
||||
public String news(@PathVariable("newsid") String newsid, Model model){
|
||||
// todo 根据newsid去数据库查询新闻内容 新闻内容返回页面
|
||||
model.addAttribute("newsid",newsid);
|
||||
return "news.html";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package com.raohanghui.springboot.springboot.Controllor;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.raohanghui.springboot.springboot.model.Student;
|
||||
import com.raohanghui.springboot.springboot.service.IStudentService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author 张三
|
||||
* @since 2024-09-12
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("/student")
|
||||
public class StudentController {
|
||||
|
||||
// 增删改查方法
|
||||
@Autowired
|
||||
IStudentService studentService;
|
||||
|
||||
@RequestMapping("studentlist")
|
||||
public String getStudent(Model model){
|
||||
Page<Student> page = new Page<>(4,5);
|
||||
model.addAttribute("studentlist",studentService.page(page).getRecords());
|
||||
// QueryWrapper<Student> queryWrapper = new QueryWrapper<>();
|
||||
// queryWrapper.like("name","test");
|
||||
// model.addAttribute("studentlist"
|
||||
// ,studentService.getBaseMapper().selectList(queryWrapper));
|
||||
|
||||
// Vue
|
||||
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.setName(name);
|
||||
student.setAge(age);
|
||||
student.setClassname(classname);
|
||||
studentService.save(student);
|
||||
return "redirect:/student/studentlist";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package com.raohanghui.springboot.springboot
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
FastAutoGenerator.create("jdbc:mysql://106.53.194.250:63306/202101080104?serverTimezone=UTC", "202001080141", "@hnucm1254")
|
||||
.globalConfig(builder -> builder
|
||||
.author("raohanghui")
|
||||
.outputDir(Paths.get(System.getProperty("user.dir")) + "/src/main/java")
|
||||
.commentDate("yyyy-MM-dd")
|
||||
)
|
||||
.packageConfig(builder -> builder
|
||||
.parent("com.raohanghui.springboot.springboot")
|
||||
.entity("entity")
|
||||
.mapper("dao")
|
||||
.service("service")
|
||||
.serviceImpl("service.impl")
|
||||
.xml("mapper.xml")
|
||||
)
|
||||
.strategyConfig(builder -> builder
|
||||
.entityBuilder()
|
||||
.enableLombok()
|
||||
)
|
||||
.templateEngine(new FreemarkerTemplateEngine())
|
||||
.execute();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package com.raohanghui.springboot.springboot.dao;
|
||||
|
||||
import com.raohanghui.springboot.springboot.model.Person;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ProductMapper {
|
||||
public List<Product> getProductByOrderId();
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package com.raohanghui.springboot.springboot.dao;
|
||||
|
||||
import com.raohanghui.springboot.springboot.model.Student;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author 张三
|
||||
* @since 2024-09-12
|
||||
*/
|
||||
@Mapper
|
||||
public interface StudentMapper extends BaseMapper<Student> {
|
||||
|
||||
}
|
|
@ -7,4 +7,5 @@ public class Order {
|
|||
private int userid;
|
||||
private int orderprice;
|
||||
private String orderinfo;
|
||||
private List<Product> productList;
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package com.raohanghui.springboot.springboot.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
public class Product {
|
||||
private int id;
|
||||
private int price;
|
||||
private String productname;
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package com.raohanghui.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,16 @@
|
|||
package com.raohanghui.springboot.springboot.service;
|
||||
|
||||
import com.raohanghui.springboot.springboot.model.Student;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author 张三
|
||||
* @since 2024-09-12
|
||||
*/
|
||||
public interface IStudentService extends IService<Student> {
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package com.raohanghui.springboot.springboot.service.impl;
|
||||
|
||||
import com.roahanghui.springboot.springboot.model.Student;
|
||||
import com.raohanghui.springboot.springboot.dao.StudentMapper;
|
||||
import com.raohanghui.springboot.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 {
|
||||
|
||||
}
|
|
@ -8,14 +8,14 @@ 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.url=jdbc:mysql://106.53.194.250:63306/202001080141?serverTimezone=UTC
|
||||
# ??????&???
|
||||
spring.datasource.username=202101080104
|
||||
spring.datasource.username=202001080141
|
||||
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.pojo
|
||||
|
||||
logging.level.com.example.springmybatis = debug
|
|
@ -3,8 +3,21 @@
|
|||
<mapper namespace="com.raohanghui.springboot.springboot.dao.OrderMapper">
|
||||
|
||||
<select id="getOrderById" parameterType="Integer"
|
||||
resultType="com.raohanghui.springboot.springboot.model.Order">
|
||||
resultType="com.raohanghui.springboot.springboot.model.Order"
|
||||
resultMap="OrderMap">
|
||||
select * from orders where userid=#{id}
|
||||
</select>
|
||||
|
||||
<resultMap id="OrderMap" type="com.raohanghui.springboot.springboot.model.Order">
|
||||
<id column="id" property="id" />
|
||||
<result column="userid" property="userid" />
|
||||
<result column="orderprice" property="orderprice" />
|
||||
<result column="orderinfo" property="orderinfo" />
|
||||
<collection property="productList"
|
||||
ofType="com.raohanghui.springboot.springboot.model.Product">
|
||||
select="com.raohanghui.springboot.springboot.dao.ProductMapper.getProductByOrderId"
|
||||
column="id"
|
||||
</collection>
|
||||
|
||||
</resultMap>
|
||||
</mapper>
|
|
@ -0,0 +1,9 @@
|
|||
<?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.raohanghui.springboot.springboot.dao.ProductMapper">
|
||||
<select id="getProductByOrderId" resultType="com.raohanghui.springboot.springboot.model.Product"
|
||||
select * from product where id in (
|
||||
select productid from order_product where orde_id = #{id}
|
||||
)
|
||||
)
|
||||
</mapper>
|
|
@ -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.raohanghui.springboot.springboot.dao.StudentMapper">
|
||||
|
||||
</mapper>
|
|
@ -0,0 +1,18 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Title</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>添加人员页面</h1>
|
||||
|
||||
<form 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>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,13 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Title</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>新闻内容****************</h1>
|
||||
<div th:text="${newsid}"> </div>
|
||||
<img th:src="@{/123.png}" alt="">
|
||||
<video th:src="@{/123.png}"></video>
|
||||
</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.age}"></td>
|
||||
<td th:text="${student.name}"></td>
|
||||
<td th:text="${student.classname}"></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue