SpringBoot+Vue3 项目实战,打造企业级在线办公系统【升级版16章】
视频课程分享——SpringBoot+Vue3 项目实战,打造企业级在线办公系统,最新升级版16章,附源码+电子书下载。
在线办公系统的开发主要包括前端开发和后端开发,应根据系统需求分配相应的工作量和任务。
1. 前端开发。 在线办公系统采用的是前后端分离模式。前端应用层使用React、Vue或Angular等框架开发,实现交互设计和页面开发。
2. 后端开发。采用Spring Boot、Spring Cloud、Docker等技术,实现应用逻辑和数据操作。
3. 代码开发规范。代码开发规范非常重要,可采用团队组建的方法,提高团队的协作效率及代码的质量。
在开发项目的过程中,很多人都喜欢自定义异常,处理异常的时候可以根据异常的类型,判断出哪些是Java语言异常,哪些是业务异常。在本项目中,我们也是需要自定义异常类的。
package com.example.hospital.api.exception;
import lombok.Data;
@Data
public class HospitalException extends RuntimeException {
private String msg;
private int code = 500;
public HospitalException(Exception e) {
super(e);
this.msg = "执行异常";
this.code = 500;
}
public HospitalException(String msg) {
super(msg);
this.msg = msg;
}
public HospitalException(String msg, Throwable e) {
super(msg, e);
this.msg = msg;
}
public HospitalException(String msg, int code) {
super(msg);
this.msg = msg;
this.code = code;
}
public HospitalException(String msg, int code, Throwable e) {
super(msg, e);
this.msg = msg;
this.code = code;
}
}
因为SpringBoot Data中默认的RedisTemplate因为序列化机制的问题,往Redis里面保存Hash类型数据通常是乱码的,为了解决这个问题,我们需要定义配置类,修改RedisTemplate使用的序列化机制。
package com.example.hospital.api.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
@Configuration
public class RedisTemplateConfig {
@Bean
public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory factory) {
RedisTemplate<Object, Object> template = new RedisTemplate<>();
template.setKeySerializer(new StringRedisSerializer());
template.setHashKeySerializer(new StringRedisSerializer());
template.setHashValueSerializer(new GenericJackson2JsonRedisSerializer());
template.setConnectionFactory(factory);
return template;
}
}
查询分页数据需要用到两条SQL语句,一个查询记录总数的,另一个是查询某页记录的。在DoctorDao.xml文件中,声明这两条SQL语句。
<select id="searchByPage" parameterType="Map" resultType="HashMap">
SELECT d."id" AS "id",
d."name" AS "name",
d."sex" AS "sex",
d."tel" AS "tel",
d."school" AS "school",
d."degree" AS "degree",
d."job" AS "job",
md."name" AS "deptName",
ds."name" AS "subName",
d."recommended" AS "recommended",
d."status" AS "status"
FROM HOSPITAL.DOCTOR d
JOIN HOSPITAL.MEDICAL_DEPT_SUB_AND_DOCTOR sd ON sd."doctor_id" = d."id"
JOIN HOSPITAL.MEDICAL_DEPT_SUB ds ON sd."dept_sub_id" = ds."id"
JOIN HOSPITAL.MEDICAL_DEPT md ON ds."dept_id" = md."id"
WHERE 1=1
<if test="name!=null">
AND d."name" LIKE '%${name}%'
</if>
<if test="deptId!=null">
AND md."id" = ${deptId}
</if>
<if test="degree!=null">
AND d."degree" = #{degree}
</if>
<if test="job!=null">
AND d."job" = #{job}
</if>
<if test="recommended!=null">
AND d."recommended" = ${recommended}
</if>
AND d."status" = ${status}
<if test="order!=null">
ORDER BY md."id" ${order}
</if>
LIMIT ${length} OFFSET #{start}
</select>
<select id="searchCount" parameterType="Map" resultType="long">
SELECT COUNT(*)
FROM HOSPITAL.DOCTOR d
JOIN HOSPITAL.MEDICAL_DEPT_SUB_AND_DOCTOR sd ON sd."doctor_id" = d."id"
JOIN HOSPITAL.MEDICAL_DEPT_SUB ds ON sd."dept_sub_id" = ds."id"
JOIN HOSPITAL.MEDICAL_DEPT md ON ds."dept_id" = md."id"
WHERE 1=1
<if test="name!=null">
AND d."name" LIKE '%${name}%'
</if>
<if test="deptId!=null">
AND md."id" = ${deptId}
</if>
<if test="degree!=null">
AND d."degree" = #{degree}
</if>
<if test="job!=null">
AND d."job" = #{job}
</if>
<if test="recommended!=null">
AND d."recommended" = ${recommended}
</if>
AND d."status" = ${status}
</select>
![QQ截图20231225111839.png](https://static.golangjob.cn/231225/b13e2361455789e35eb981f6057cb522.png)
有疑问加站长微信联系(非本文作者)