diff --git a/上课代码/secondweek/springboot/springboot/pom.xml b/上课代码/secondweek/springboot/springboot/pom.xml index fdd9a18..92de63c 100644 --- a/上课代码/secondweek/springboot/springboot/pom.xml +++ b/上课代码/secondweek/springboot/springboot/pom.xml @@ -60,12 +60,23 @@ spring-boot-starter-test test + + com.baomidou + mybatis-plus-spring-boot3-starter + 3.5.7 + + + com.baomidou + mybatis-plus-generator + 3.5.7 + - org.mybatis.spring.boot - mybatis-spring-boot-starter - 3.0.3 + org.freemarker + freemarker + 2.3.31 + mysql mysql-connector-java diff --git a/上课代码/secondweek/springboot/springboot/src/main/java/com/raohanghui/springboot/springboot/Controllor/NewsController.java b/上课代码/secondweek/springboot/springboot/src/main/java/com/raohanghui/springboot/springboot/Controllor/NewsController.java new file mode 100644 index 0000000..bd6a86b --- /dev/null +++ b/上课代码/secondweek/springboot/springboot/src/main/java/com/raohanghui/springboot/springboot/Controllor/NewsController.java @@ -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"; + } + +} \ No newline at end of file diff --git a/上课代码/secondweek/springboot/springboot/src/main/java/com/raohanghui/springboot/springboot/Controllor/StudentController.java b/上课代码/secondweek/springboot/springboot/src/main/java/com/raohanghui/springboot/springboot/Controllor/StudentController.java new file mode 100644 index 0000000..a247aba --- /dev/null +++ b/上课代码/secondweek/springboot/springboot/src/main/java/com/raohanghui/springboot/springboot/Controllor/StudentController.java @@ -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; + +/** + *

+ * 前端控制器 + *

+ * + * @author 张三 + * @since 2024-09-12 + */ +@Controller +@RequestMapping("/student") +public class StudentController { + + // 增删改查方法 + @Autowired + IStudentService studentService; + + @RequestMapping("studentlist") + public String getStudent(Model model){ + Page page = new Page<>(4,5); + model.addAttribute("studentlist",studentService.page(page).getRecords()); + // QueryWrapper 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"; + } +} \ No newline at end of file diff --git a/上课代码/secondweek/springboot/springboot/src/main/java/com/raohanghui/springboot/springboot/Main.java b/上课代码/secondweek/springboot/springboot/src/main/java/com/raohanghui/springboot/springboot/Main.java new file mode 100644 index 0000000..7eb4583 --- /dev/null +++ b/上课代码/secondweek/springboot/springboot/src/main/java/com/raohanghui/springboot/springboot/Main.java @@ -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(); + } +} \ No newline at end of file diff --git a/上课代码/secondweek/springboot/springboot/src/main/java/com/raohanghui/springboot/springboot/dao/ProductMapper.java b/上课代码/secondweek/springboot/springboot/src/main/java/com/raohanghui/springboot/springboot/dao/ProductMapper.java new file mode 100644 index 0000000..1fcddda --- /dev/null +++ b/上课代码/secondweek/springboot/springboot/src/main/java/com/raohanghui/springboot/springboot/dao/ProductMapper.java @@ -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 getProductByOrderId(); +} \ No newline at end of file diff --git a/上课代码/secondweek/springboot/springboot/src/main/java/com/raohanghui/springboot/springboot/dao/StudentMapper.java b/上课代码/secondweek/springboot/springboot/src/main/java/com/raohanghui/springboot/springboot/dao/StudentMapper.java new file mode 100644 index 0000000..e1c3366 --- /dev/null +++ b/上课代码/secondweek/springboot/springboot/src/main/java/com/raohanghui/springboot/springboot/dao/StudentMapper.java @@ -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; + +/** + *

+ * Mapper 接口 + *

+ * + * @author 张三 + * @since 2024-09-12 + */ +@Mapper +public interface StudentMapper extends BaseMapper { + +} \ No newline at end of file diff --git a/上课代码/secondweek/springboot/springboot/src/main/java/com/raohanghui/springboot/springboot/model/Order.java b/上课代码/secondweek/springboot/springboot/src/main/java/com/raohanghui/springboot/springboot/model/Order.java index a53064a..7de215f 100644 --- a/上课代码/secondweek/springboot/springboot/src/main/java/com/raohanghui/springboot/springboot/model/Order.java +++ b/上课代码/secondweek/springboot/springboot/src/main/java/com/raohanghui/springboot/springboot/model/Order.java @@ -7,4 +7,5 @@ public class Order { private int userid; private int orderprice; private String orderinfo; + private List productList; } \ No newline at end of file diff --git a/上课代码/secondweek/springboot/springboot/src/main/java/com/raohanghui/springboot/springboot/model/Product.java b/上课代码/secondweek/springboot/springboot/src/main/java/com/raohanghui/springboot/springboot/model/Product.java new file mode 100644 index 0000000..ee14603 --- /dev/null +++ b/上课代码/secondweek/springboot/springboot/src/main/java/com/raohanghui/springboot/springboot/model/Product.java @@ -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; +} \ No newline at end of file diff --git a/上课代码/secondweek/springboot/springboot/src/main/java/com/raohanghui/springboot/springboot/model/Student.java b/上课代码/secondweek/springboot/springboot/src/main/java/com/raohanghui/springboot/springboot/model/Student.java new file mode 100644 index 0000000..4f44d61 --- /dev/null +++ b/上课代码/secondweek/springboot/springboot/src/main/java/com/raohanghui/springboot/springboot/model/Student.java @@ -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; + +/** + *

+ * + *

+ * + * @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; +} diff --git a/上课代码/secondweek/springboot/springboot/src/main/java/com/raohanghui/springboot/springboot/service/IStudentService.java b/上课代码/secondweek/springboot/springboot/src/main/java/com/raohanghui/springboot/springboot/service/IStudentService.java new file mode 100644 index 0000000..06923ee --- /dev/null +++ b/上课代码/secondweek/springboot/springboot/src/main/java/com/raohanghui/springboot/springboot/service/IStudentService.java @@ -0,0 +1,16 @@ +package com.raohanghui.springboot.springboot.service; + +import com.raohanghui.springboot.springboot.model.Student; +import com.baomidou.mybatisplus.extension.service.IService; + +/** + *

+ * 服务类 + *

+ * + * @author 张三 + * @since 2024-09-12 + */ +public interface IStudentService extends IService { + +} diff --git a/上课代码/secondweek/springboot/springboot/src/main/java/com/raohanghui/springboot/springboot/service/impl/StudentServiceImpl.java b/上课代码/secondweek/springboot/springboot/src/main/java/com/raohanghui/springboot/springboot/service/impl/StudentServiceImpl.java new file mode 100644 index 0000000..d1d0302 --- /dev/null +++ b/上课代码/secondweek/springboot/springboot/src/main/java/com/raohanghui/springboot/springboot/service/impl/StudentServiceImpl.java @@ -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; + +/** + *

+ * 服务实现类 + *

+ * + * @author 张三 + * @since 2024-09-12 + */ +@Service +public class StudentServiceImpl extends ServiceImpl implements IStudentService { + +} diff --git a/上课代码/secondweek/springboot/springboot/src/main/resources/application.properties b/上课代码/secondweek/springboot/springboot/src/main/resources/application.properties index b590996..f86ed23 100644 --- a/上课代码/secondweek/springboot/springboot/src/main/resources/application.properties +++ b/上课代码/secondweek/springboot/springboot/src/main/resources/application.properties @@ -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 \ No newline at end of file diff --git a/上课代码/secondweek/springboot/springboot/src/main/resources/mapper/OrderMapper.xml b/上课代码/secondweek/springboot/springboot/src/main/resources/mapper/OrderMapper.xml index 882d774..f90d0d6 100644 --- a/上课代码/secondweek/springboot/springboot/src/main/resources/mapper/OrderMapper.xml +++ b/上课代码/secondweek/springboot/springboot/src/main/resources/mapper/OrderMapper.xml @@ -3,8 +3,21 @@ + + + + + + + select="com.raohanghui.springboot.springboot.dao.ProductMapper.getProductByOrderId" + column="id" + + + \ No newline at end of file diff --git a/上课代码/secondweek/springboot/springboot/src/main/resources/mapper/ProductMapper.xml b/上课代码/secondweek/springboot/springboot/src/main/resources/mapper/ProductMapper.xml new file mode 100644 index 0000000..ae4e551 --- /dev/null +++ b/上课代码/secondweek/springboot/springboot/src/main/resources/mapper/ProductMapper.xml @@ -0,0 +1,9 @@ + + + +
+
+
+ + + + + \ No newline at end of file diff --git a/上课代码/secondweek/springboot/springboot/src/main/resources/templates/news.html b/上课代码/secondweek/springboot/springboot/src/main/resources/templates/news.html new file mode 100644 index 0000000..7b42aa4 --- /dev/null +++ b/上课代码/secondweek/springboot/springboot/src/main/resources/templates/news.html @@ -0,0 +1,13 @@ + + + + + Title + + +

新闻内容****************

+
+ + + + \ No newline at end of file diff --git a/上课代码/secondweek/springboot/springboot/src/main/resources/templates/studentlist.html b/上课代码/secondweek/springboot/springboot/src/main/resources/templates/studentlist.html new file mode 100644 index 0000000..0e9e4bf --- /dev/null +++ b/上课代码/secondweek/springboot/springboot/src/main/resources/templates/studentlist.html @@ -0,0 +1,25 @@ + + + + + Title + + +

人员列表页面

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