肖凡3.24提交

server_2024_3_23_xiaofan
肖凡 2024-03-24 20:44:54 +08:00
parent 55a7ea614f
commit 4a8a60c471
9 changed files with 236 additions and 1 deletions

View File

@ -0,0 +1,17 @@
package com.muyu.test.common.domain;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
/**
* Auth :
* Date :2024-03-24 11:59:22
*/
@Data
@TableName("t_class")
public class Class {
private Integer classId;
@TableField(exist = false)
private String className;
}

View File

@ -0,0 +1,25 @@
package com.muyu.test.common.domain;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.util.Date;
/**
* Auth :
* Date :2024-03-24 09:53:41
*/
@Data
@TableName("t_student")
public class Student extends Class{
@TableId("student_id")
private Integer studentId;
private String studentName;
private String studentSex;
private Integer studentAge;
private String studentPhone;
private Date studentTime;
private String studentImg;
private Integer classId;
}

View File

@ -85,6 +85,13 @@
<artifactId>muyu-common-swagger</artifactId> <artifactId>muyu-common-swagger</artifactId>
</dependency> </dependency>
<!-- mybatis plus -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.1</version>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -1,8 +1,9 @@
package com.muyu; package com.muyu.test.server;
import com.muyu.common.security.annotation.EnableCustomConfig; import com.muyu.common.security.annotation.EnableCustomConfig;
import com.muyu.common.security.annotation.EnableMyFeignClients; import com.muyu.common.security.annotation.EnableMyFeignClients;
import com.muyu.common.swagger.annotation.EnableCustomSwagger2; import com.muyu.common.swagger.annotation.EnableCustomSwagger2;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
@ -10,6 +11,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
@EnableCustomSwagger2 @EnableCustomSwagger2
@EnableMyFeignClients @EnableMyFeignClients
@SpringBootApplication @SpringBootApplication
@MapperScan(basePackages = "com.muyu.test.server.mapper")
public class MuYuTestApplication { public class MuYuTestApplication {
public static void main (String[] args) { public static void main (String[] args) {
SpringApplication.run(MuYuTestApplication.class, args); SpringApplication.run(MuYuTestApplication.class, args);

View File

@ -0,0 +1,65 @@
package com.muyu.test.server.controller;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.web.page.TableDataInfo;
import com.muyu.test.common.domain.Student;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.test.server.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* Auth :
* Date :2024-03-24 09:59:30
*/
@RestController
@Slf4j
public class StudentController extends BaseController{
@Autowired
private StudentService studentService;
// @GetMapping("/list")
// public List<Student> list(Student student){
// List<Student> list=studentService.selectList(student);
// return list;
// }
@GetMapping("/list")
public Result<TableDataInfo<Student>> list(Student student){
startPage();
List<Student> list=studentService.selectList(student);
return getDataTable(list);
}
@PostMapping("/add")
public Result add(@RequestBody Student student){
int i=studentService.add(student);
return Result.success(i);
}
@PostMapping("/update")
public Result update(@RequestBody Student student){
int i=studentService.updateByIdTwo(student);
return Result.success(i);
}
@PostMapping("/del/{studentId}")
public Result del(@PathVariable Integer studentId){
int i=studentService.del(studentId);
return Result.success(i);
}
}

View File

@ -0,0 +1,24 @@
package com.muyu.test.server.mapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.muyu.test.common.domain.Student;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import java.util.List;
/**
* Auth :
* Date :2024-03-24 10:00:03
*/
@Mapper
public interface StudentMapper extends BaseMapper<Student> {
List<Student> selectList1(Student student);
// @Select("SELECT t_student.student_id,t_student.student_name,t_student.student_sex,t_student.student_age,t_student.student_phone,t_student.student_time,t_student.student_img,t_class.class_id,t_class.class_name FROM t_student LEFT JOIN t_class ON t_student.class_id = t_class.class_id")
// List<Student> selectList1(LambdaQueryWrapper<Student> queryWrapper);
}

View File

@ -0,0 +1,25 @@
package com.muyu.test.server.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.muyu.test.common.domain.Student;
import java.util.List;
/**
* Auth :
* Date :2024-03-24 09:59:40
*/
public interface StudentService extends IService<Student> {
List<Student> selectList(Student student);
int add(Student student);
int updateByIdTwo(Student student);
int del(Integer studentId);
}

View File

@ -0,0 +1,46 @@
package com.muyu.test.server.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.common.core.utils.StringUtils;
import com.muyu.test.common.domain.Student;
import com.muyu.test.server.mapper.StudentMapper;
import com.muyu.test.server.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* Auth :
* Date :2024-03-24 09:59:54
*/
@Service
public class StudentServiceimpl extends ServiceImpl<StudentMapper, Student> implements StudentService {
@Autowired
private StudentMapper studentMapper;
@Override
public List<Student> selectList(Student student) {
return studentMapper.selectList1(student);
}
@Override
public int add(Student student) {
return studentMapper.insert(student);
}
@Override
public int updateByIdTwo(Student student) {
return studentMapper.updateById(student);
}
@Override
public int del(Integer studentId) {
return studentMapper.deleteById(studentId);
}
}

View File

@ -0,0 +1,24 @@
<?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.muyu.test.server.mapper.StudentMapper">
<select id="selectList1" resultType="com.muyu.test.common.domain.Student">
SELECT t_student.student_id,t_student.student_name,t_student.student_sex,t_student.student_age,t_student.student_phone,t_student.student_time,t_student.student_img,t_class.class_id,t_class.class_name FROM t_student
LEFT JOIN t_class ON t_student.class_id = t_class.class_id
<where>
<if test="studentName != null and studentName != ''">
AND t_student.student_name like concat('%', #{studentName}, '%')
</if>
<if test="studentSex != null and studentSex != ''">
AND t_student.student_sex = #{studentSex}
</if>
<if test="studentAge != null and studentAge != ''">
AND t_student.student_age = #{studentAge}
</if>
</where>
</select>
</mapper>