Building an Intelligent Office System with SSM and Vue.js
System Architecture
The intelligent office system is built using a modern technology stack combining Spring Boot, Vue.js, and MyBatis-Plus. This architecture provides a robust foundation for enterprise applications with clean separation between frontend and backend components.
Backend Implementation
The Spring Boot backend handles business logic and data persistence:
@RestController
@RequestMapping("/api/auth")
public class AuthController {
@Autowired
private UserService userService;
@PostMapping("/login")
public ResponseEntity<?> authenticateUser(
@RequestParam String username,
@RequestParam String password) {
User user = userService.findByUsername(username);
if(user == null || !passwordEncoder.matches(password, user.getPassword())) {
return ResponseEntity.badRequest().body("Invalid credentials");
}
String token = tokenProvider.generateToken(user);
return ResponseEntity.ok(new AuthResponse(token));
}
}
Frontend Implementation
The Vue.js frontend provides a responsive user enterface:
<template>
<div class="login-container">
<form @submit.prevent="handleLogin">
<input v-model="username" placeholder="Username" />
<input v-model="password" type="password" placeholder="Password" />
<button type="submit">Login</button>
</form>
</div>
</template>
<script>
export default {
data() {
return {
username: '',
password: ''
}
},
methods: {
async handleLogin() {
try {
const response = await axios.post('/api/auth/login', {
username: this.username,
password: this.password
});
localStorage.setItem('token', response.data.token);
this.$router.push('/dashboard');
} catch (error) {
console.error('Login failed:', error);
}
}
}
}
</script>
Database Schema
The system uses a relational data base with tables for users, roles, and authentication tokens:
CREATE TABLE users (
id BIGINT PRIMARY KEY AUTO_INCREMENT,
username VARCHAR(50) UNIQUE NOT NULL,
password VARCHAR(100) NOT NULL,
role VARCHAR(20) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE auth_tokens (
id BIGINT PRIMARY KEY AUTO_INCREMENT,
user_id BIGINT NOT NULL,
token VARCHAR(200) UNIQUE NOT NULL,
expires_at TIMESTAMP NOT NULL,
FOREIGN KEY (user_id) REFERENCES users(id)
);
Security Implementation
The system implements JWT-based authentication with role-based access control:
@Component
public class JwtAuthFilter extends OncePerRequestFilter {
@Override
protected void doFilterInternal(HttpServletRequest request,
HttpServletResponse response,
FilterChain filterChain) throws ServletException, IOException {
String token = extractToken(request);
if (token != null && jwtUtils.validateToken(token)) {
Authentication auth = jwtUtils.getAuthentication(token);
SecurityContextHolder.getContext().setAuthentication(auth);
}
filterChain.doFilter(request, response);
}
private String extractToken(HttpServletRequest request) {
String header = request.getHeader("Authorization");
if (StringUtils.hasText(header) && header.startsWith("Bearer ")) {
return header.substring(7);
}
return null;
}
}