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