自己写的,做一个小总结 也不知道有没有人会看完,把所有代码发出来 有任何问题评论联系
entity包实体类(节约空间getset省略)
booking挂号实体类
public class Booking {
private Integer bookingId;
private Patient patient;
private Doctor doctor;
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date bookingDate;
private String visitTime;
}
dataPage分页类
public class DataPage<T> implements Serializable {
private Integer rowCount;
private Integer pageCount;
private Integer pageNum;
private Integer pageSize;
private List<T> dataList;
}
Doctor类
public class Doctor implements Serializable {
private Integer doctorId;
private String name;
private String sex;
private Date birthday;
private String summary;
private String introduce;
private String image;
private Office office;
private Title title;
private Integer total;
}
Office科室类
public class Office implements Serializable {
private Integer officeId;
private String officeName;
}
患者类用于登录
public class Patient {
private Integer patientId;
private String username;
private String password;
private String name;
private String sex;
private Date birthday;
}
TItle类 头衔类
public class Title implements Serializable {
private Integer titleId;
private String titleName;
}
mapper层(接口省略)
bookingMapper
<?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="cn.kgc.mapper.BookingMapper">
<resultMap id="patientMap" type="Booking">
<id property="bookingId" column="bookingId"/>
<association property="doctor" column="doctorId" select="cn.kgc.mapper.DoctorMapper.selectDoctorById"/>
</resultMap>
<resultMap id="doctorMap" type="Booking">
<id property="bookingId" column="bookingId"/>
<association property="patient" column="patientId" select="cn.kgc.mapper.PatientMapper.selectPatientById"/>
</resultMap>
<!--date()为取时间的日期,忽略时分秒-->
<select id="selectBookingCount" resultType="Map">
select doctorId, count(*) as count from booking where bookingDate=date(#{
bookingDate}) and doctorId in
<foreach collection="doctorList" open="(" close=")" separator="," item="doctorId">
#{
doctorId}
</foreach>
group by doctorId
</select>
<select id="selectCountByPatient" resultType="Integer">
select count(*) from booking where patientId = #{
patientId} and bookingDate = date(#{
bookingDate})
</select>
<select id="selectBookingsByPatient" parameterType="Integer" resultMap="patientMap">
select * from booking where patientId = #{
patientId} and bookingDate >= date(now())
</select>
<delete id="deleteOneBooking" parameterType="Integer">
delete from booking where bookingId = #{
bookingId}
</delete>
</mapper>
DoctorMapper
<?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="cn.kgc.mapper.DoctorMapper">
<resultMap id="doctorMap" type="Doctor">
<id property="doctorId" column="doctorId"/>
<association property="office" column="officeId"
select="cn.kgc.mapper.OfficeMapper.selectOfficeById"/>
<association property="title" column="titleId"
select="cn.kgc.mapper.TitleMapper.selectTitleById"/>
</resultMap>
<select id="selectAllDoctors" resultMap="doctorMap">
select * from doctor
<!--
1、where会自动去掉条件语句前的and/or等关键词
2、若条件语句为空,where关键词会自动删除
-->
<where>
<if test="officeId != null and officeId != 0">
officeId = #{
officeId}
</if>
<if test="titleId != null and titleId != 0">
and titleId = #{
titleId}
</if>
</where>
</select>
<select id="selectDoctorsByList" parameterType="List" resultType="Doctor">
select * from doctor where doctorId in
<foreach collection="list" item="doctorId" open="(" close=")" separator=",">
#{
doctorId}
</foreach>
</select>
<select id="selectDoctorById" parameterType="Integer" resultMap="doctorMap">
select * from doctor where doctorId = #{
doctorId}
</select>
</mapper>
officeMapper
<?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="cn.kgc.mapper.OfficeMapper">
<select id="selectAllOffices" resultType="Office">
select * from office
</select>
<select id="selectOfficeById" parameterType="Integer" resultType="Office">
select * from office where officeId = #{
officeId}
</select>
</mapper>
PatientMapper
<?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="cn.kgc.mapper.PatientMapper">
<select id="selectByUsername" parameterType="String" resultType="Patient">
select * from patient where username = #{
username}
</select>
<select id="selectPatientById" parameterType="Integer" resultType="Patient">
select * from patient where patientId = #{
patientId}
</select>
</mapper>
TittleMapper
<?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="cn.kgc.mapper.TitleMapper">
<select id="selectAllTitles" resultType="Title">
select * from title
</select>
<select id="selectTitleById" parameterType="Integer" resultType="Title">
select * from title where titleId = #{
titleId}
</select>
</mapper>
dao层实体类省略
CacheDaoImpl
package cn.kgc.dao;
import cn.kgc.entity.DataPage;
import cn.kgc.entity.Doctor;
import cn.kgc.entity.Office;
import cn.kgc.entity.Title;
import cn.kgc.mapper.DoctorMapper;
import cn.kgc.mapper.OfficeMapper;
import cn.kgc.mapper.TitleMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Repository;
import javax.annotation.Resource;
import java.util.List;
/**
* Created by Tiler on 2021/1/6
*/
@Repository
public class CacheDaoImpl implements CacheDao {
@Resource
private DoctorMapper doctorMapper;
@Autowired
private OfficeMapper officeMapper;
@Autowired
private TitleMapper titleMapper;
//Cacheable:执行此函数前先在缓存中到数据,若缓存中不存在则执行此函数,并将此函数的执行结果缓存起来。
//key为一个表达式,#p0表示第0个参数。redis中的键名为value::key
@Override
@Cacheable(value = "doctor-page", key = "#p0+':'+#p1+':'+#p2")
public DataPage<Doctor> getAllDoctors(Integer officeId, Integer titleId, Integer pageNum, Integer pageSize) {
//分页
PageHelper.startPage(pageNum, pageSize);
System.out.println(officeId);
System.out.println(titleId);
List<Doctor> doctors = doctorMapper.selectAllDoctors(officeId, titleId);
PageInfo<Doctor> pageInfo = new PageInfo<>(doctors);
//返回数据
DataPage<Doctor> dataPage = new DataPage<>();
dataPage.setDataList(pageInfo.getList());
dataPage.setRowCount((int)pageInfo.getTotal());
dataPage.setPageCount(pageInfo.getPages());
dataPage.setPageNum(pageNum);
dataPage.setPageSize(pageSize);
return dataPage;
}
@Override
@Cacheable(value = "offices", key = "'list'")
public List<Office> getAllOffices() {
return officeMapper.selectAllOffices();
}
@Override
@Cacheable(value = "titles", key = "'list'")
public List<Title> getAllTitles() {
return titleMapper.selectAllTitles();
}
@Override
@Cacheable(value = "doctor", key = "#p0")
public Doctor getDoctorById(Integer doctorId) {
return doctorMapper.selectDoctorById(doctorId);
}
}
RedisDaoIMpl
package cn.kgc.dao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Repository;
import java.util.Map;
/**
* Created by Tiler on 2021/1/6
*/
@Repository
public class RedisDaoImpl implements RedisDao {
@Autowired
private StringRedisTemplate redisTemplate;
@Override
public Integer listRpush(String key, String value) {
return redisTemplate.opsForList().rightPush(key, value).intValue();
}
@Override
public Integer listLen(String key) {
return redisTemplate.opsForList(