新
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
package org.dromara.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.dromara.common.Result;
|
||||
import org.dromara.common.core.domain.R;
|
||||
import org.dromara.domain.Cls;
|
||||
import org.dromara.domain.Cls;
|
||||
import org.dromara.service.IClsService;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -65,4 +68,12 @@ public class ClsController {
|
||||
clsService.deleteById(id);
|
||||
return Result.success();
|
||||
}
|
||||
/**
|
||||
* 分页查询
|
||||
*/
|
||||
@PostMapping("/selectPage")
|
||||
public R<IPage<Cls>> selectPage(@RequestBody Cls cls) {
|
||||
IPage<Cls> list = clsService.selectPage(cls);
|
||||
return R.ok(list);
|
||||
}
|
||||
}
|
||||
|
@@ -6,5 +6,8 @@ import lombok.Data;
|
||||
public class Cls {
|
||||
private Integer id;
|
||||
private String name;
|
||||
private Integer num;
|
||||
private Integer pageNum;
|
||||
private Integer pageSize;
|
||||
|
||||
}
|
||||
|
@@ -15,7 +15,7 @@ public class Student {
|
||||
private Integer clsId;
|
||||
private Integer courseId;
|
||||
private String clsName;
|
||||
|
||||
private String avatar;
|
||||
private Integer pageNum;
|
||||
private Integer pageSize;
|
||||
}
|
||||
|
@@ -1,9 +1,12 @@
|
||||
package org.dromara.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.dromara.domain.Cls;
|
||||
import org.dromara.domain.Cls;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -11,13 +14,12 @@ public interface ClsMapper extends BaseMapper<Cls> {
|
||||
List<Cls> selectAll(Cls cls);
|
||||
@Select("select * from cls where id = #{id}")
|
||||
Cls selectById(Integer id);
|
||||
|
||||
int insert(Cls cls);
|
||||
|
||||
int updateById(Cls cls);
|
||||
|
||||
@Delete("delete from `cls` where id = #{id}")
|
||||
void deleteById(Integer id);
|
||||
@Select("select * from cls where username = #{username}")
|
||||
Cls selectByUsername(String username);
|
||||
|
||||
IPage<Cls> selectPage(@Param("cls") Cls cls, IPage<Cls> page);
|
||||
}
|
||||
|
@@ -1,7 +1,10 @@
|
||||
package org.dromara.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.dromara.domain.Cls;
|
||||
import org.dromara.domain.Cls;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -22,4 +25,5 @@ public interface IClsService extends IService<Cls> {
|
||||
|
||||
Cls selectById( Integer id);
|
||||
|
||||
IPage<Cls> selectPage(Cls cls);
|
||||
}
|
||||
|
@@ -1,20 +1,18 @@
|
||||
package org.dromara.service.impl;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.dromara.domain.Cls;
|
||||
import org.dromara.domain.Student;
|
||||
import org.dromara.mapper.ClsMapper;
|
||||
import org.dromara.mapper.StudentMapper;
|
||||
import org.dromara.service.IClsService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class ClsService extends ServiceImpl<ClsMapper, Cls> implements IClsService {
|
||||
@@ -48,6 +46,12 @@ public class ClsService extends ServiceImpl<ClsMapper, Cls> implements IClsServi
|
||||
public Cls selectById(Integer id) {
|
||||
return clsMapper.selectById(id);
|
||||
}
|
||||
@Override
|
||||
public IPage<Cls> selectPage(Cls cls) {
|
||||
IPage<Cls> page = new Page<>(cls.getPageNum(), cls.getPageSize());
|
||||
return clsMapper.selectPage(cls,page);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@@ -1,6 +1,5 @@
|
||||
package org.dromara.service.impl;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import jakarta.annotation.Resource;
|
||||
@@ -11,6 +10,7 @@ import org.dromara.service.IStudentService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
@Service
|
||||
public class StudentService implements IStudentService {
|
||||
|
@@ -4,12 +4,14 @@
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="org.dromara.mapper.ClsMapper">
|
||||
<select id="selectAll" resultType="org.dromara.domain.Cls" parameterType="org.dromara.domain.Cls">
|
||||
select *
|
||||
select cls.id, cls.name,count(s.id) num
|
||||
from cls
|
||||
left join student s on cls.id = s.cls_id
|
||||
<where>
|
||||
<if test="name != null">name like concat('%', #{name}, '%')</if>
|
||||
<if test="name != null">cls.name like concat('%', #{name}, '%')</if>
|
||||
</where>
|
||||
order by id desc
|
||||
group by cls.id,cls.name
|
||||
order by cls.id desc
|
||||
</select>
|
||||
<insert id="insert" parameterType="org.dromara.domain.Cls">
|
||||
insert into `cls` (name)
|
||||
@@ -21,4 +23,17 @@
|
||||
set name= #{name}
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<select id="selectPage" resultType="org.dromara.domain.Cls">
|
||||
select c.id,
|
||||
c.name,
|
||||
count(1) num
|
||||
from cls as c
|
||||
left join student as s on s.cls_id = c.id
|
||||
<where>
|
||||
<if test="cls.name != null">c.name like concat('%', #{cls.name}, '%')</if>
|
||||
</where>
|
||||
group by c.id ,c.name
|
||||
order by c.id desc
|
||||
</select>
|
||||
</mapper>
|
||||
|
@@ -48,8 +48,8 @@
|
||||
</select>
|
||||
|
||||
<insert id="insert" parameterType="org.dromara.domain.Student">
|
||||
insert into `student` (username, password, role, name, age, sex, address, cls_id, course_id)
|
||||
values (#{username}, #{password}, #{role}, #{name}, #{age}, #{sex}, #{address}, #{clsId}, #{courseId})
|
||||
insert into `student` (username, password, role, name, age, sex, avatar,address, cls_id, course_id)
|
||||
values (#{username}, #{password}, #{role}, #{name}, #{age}, #{sex},#{avatar}, #{address}, #{clsId}, #{courseId})
|
||||
</insert>
|
||||
|
||||
<update id="updateById" parameterType="org.dromara.domain.Student">
|
||||
@@ -60,6 +60,7 @@
|
||||
name= #{name},
|
||||
age= #{age},
|
||||
sex= #{sex},
|
||||
avatar= #{avatar},
|
||||
address= #{address},
|
||||
cls_id= #{clsId},
|
||||
course_id= #{courseId}
|
||||
|
Reference in New Issue
Block a user