@RequestMapping(value = "/front/login.do", method = RequestMethod.POST)
public ModelAndView frontLogin(@ModelAttribute Users user, HttpSession session) {
ModelAndView mv = new ModelAndView("");
// ... 로직 처리
return mv;
}
데이터 처리
에러 처리
인증
라우팅
const login = async (credentials: LoginForm) => {
const response = await fetch('/front/login.do', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: new URLSearchParams(credentials)
});
if (response.redirected) {
window.location.href = response.url;
}
};
@RestController
@RequestMapping("/api")
public class LoginController {
@PostMapping("/login")
public ResponseEntity<LoginResponse> login(@RequestBody LoginRequest request) {
// ... 로직 처리
return ResponseEntity.ok(response);
}
}
API 통신
상태 관리
라우팅
// API 호출
const login = async (credentials: LoginRequest): Promise<LoginResponse> => {
const { data } = await axios.post('/api/login', credentials);
return data;
};
// 컴포넌트에서 사용
const LoginPage = () => {
const handleSubmit = async (credentials) => {
try {
const response = await login(credentials);
if (response.success) {
// 토큰 저장 및 리다이렉트
setAuthToken(response.token);
navigate('/dashboard');
}
} catch (error) {
handleError(error);
}
};
};