介绍
基于Java的社区卫生医疗管理系统(社区医院)。
🚀 软件架构
本项目为前后端分离项目,前端采用Vue,使用element-ui组件库。后端使用SpringBoot
由于使用前后端分离,就要解决跨域访问的问题,所以用JWT进行数据的传送。
菜单栏使用了redis缓存,数据库使用MySQL.
🚀 开发环境
1.系统用Java语言开发,前端用Vue,后端用Spring Boot框架;
2.开发工具:IDEA、Navicat、Postman等;
3.技术:
后端:MySQL、Redis、Spring Boot、JWT(security)
前端:Vue、ElementUI、axios等
🚀 部分界面效果图
🚀
首页
:
多角色入口:
首页的公告展示 社区管理员发布的公告 (走马灯 轮滑)
个人中心(密码修改等)
🌈 管理员(全部菜单):
公告管理 管理员发布公告 在首页轮播播放
🌈 管理员(部门、职位、角色权限、菜单等管理):
🌈 通过游客登录(限制其可见菜单 浏览该社区系统数据(权限受限)):
🚀 项目结构
🚀 代码实现:
🌈 权限认证及授权
jwt:
package com.example.api.security;
import com.example.api.model.support.ResponseResult;
import com.example.api.utils.JwtTokenUtil;
import com.example.api.utils.ResponseUtil;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
* 从Request的Authorization Header 获取Jwt
* 解析Jwt授权发放token
*/
public class JwtAuthorizationFilter extends BasicAuthenticationFilter {
public JwtAuthorizationFilter(AuthenticationManager authenticationManager) {
super(authenticationManager);
}
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
throws IOException, ServletException {
//从Request Header 取出Token
String token = request.getHeader(JwtTokenUtil.TOKEN_HEADER);
//Token为空放行
//如果接下来进入的URL不是公共的地址SpringSecurity会返回403的错误
if (!JwtTokenUtil.checkToken(token)){
chain.doFilter(request, response);
return;
}
//判断JWT Token是否过期
if (JwtTokenUtil.isExpiration(token)) {
ResponseUtil.writeJson(response, new ResponseResult<>(403, "令牌已过期, 请重新登录"));
return;
}
//解析token
String username = JwtTokenUtil.getUsername(token);
List<String> tokenRoles = JwtTokenUtil.getTokenRoles(token);
ArrayList<SimpleGrantedAuthority> roles = new ArrayList<>();
for (String role : tokenRoles) {
roles.add(new SimpleGrantedAuthority(role));
}
//向SpringSecurity的Context中加入认证信息
SecurityContextHolder.getContext().setAuthentication(
new UsernamePasswordAuthenticationToken(username,null, roles));
super.doFilterInternal(request, response, chain);
}
}
Security Config配置
package com.example.api.security;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
@Configuration
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Bean
public BCryptPasswordEncoder bCryptPasswordEncoder() {
return new BCryptPasswordEncoder();
}
/**
* HTTP验证规则
*
* @param http h
* @throws Exception e
*/
@Override
protected void configure(HttpSecurity http) throws Exception {
//开启跨域
http.csrf().disable().cors();
//禁用session
http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
//添加自定义的jwt过滤器
http.addFilter(new JwtAuthorizationFilter(authenticationManagerBean()));
}
/**
* SpringSecurity有默认的跨域配置 会无法放行RequestHeader带有"Authorization"请求
* 防止前端请求api报出cors error
*
* @return *
*/
@Bean
CorsConfigurationSource corsConfigurationSource() {
final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
final CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.addAllowedHeader("*");
corsConfiguration.addAllowedHeader("DELETE");
corsConfiguration.addAllowedMethod("*");
corsConfiguration.addAllowedOrigin("*");
source.registerCorsConfiguration("/**", corsConfiguration);
return source;
}
}
整体代码风格中规中矩;业务难度简单; 综上所述 适合毕业设计选题和选材
后面的代码就不再列举了,,
✨✨下面评论有源码及指导😜😜✨✨