You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							79 lines
						
					
					
						
							2.7 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							79 lines
						
					
					
						
							2.7 KiB
						
					
					
				| package com.example.demo.controller; | |
| import com.example.demo.Util.JWTUtil; | |
| import com.example.demo.Util.TokenPayload; | |
| import com.example.demo.domain.entity.Admin; | |
| import com.example.demo.domain.vo.Page; | |
| import com.example.demo.domain.vo.Result; | |
| import com.example.demo.sevice.AdminService; | |
| import com.fasterxml.jackson.core.JsonProcessingException; | |
| import com.fasterxml.jackson.databind.ObjectMapper; | |
| import lombok.RequiredArgsConstructor; | |
| import lombok.extern.slf4j.Slf4j; | |
| 
 | |
| import org.springframework.security.core.userdetails.UserDetails; | |
| import org.springframework.util.ObjectUtils; | |
| import org.springframework.web.bind.annotation.*; | |
| 
 | |
| @RestController | |
| @RequestMapping("/admin") | |
| @RequiredArgsConstructor | |
| @Slf4j | |
| @CrossOrigin | |
| public class AdminController { | |
| 
 | |
| 
 | |
|     private  final AdminService adminService; | |
| 
 | |
|     @PostMapping("/search") | |
|     public Result search(@RequestBody Page page){ | |
|         if(ObjectUtils.isEmpty(page.getPageNum())){ | |
|             return Result.success(adminService.search(page.getAdmin())); | |
|         } | |
|         else { | |
|             return Result.success(adminService.searchForPage(page.getPageNum(), page.getPageSize(), page.getAdmin())); | |
|         } | |
|     } | |
| 
 | |
|     @PostMapping("/login") | |
|     public Result login(@RequestBody Admin admin){ | |
|         if(ObjectUtils.isEmpty(admin)){ | |
|             System.out.println("他是空"); | |
|         } | |
| 
 | |
|             try { | |
|                 System.out.println(admin+"*-*-*-*-*-*-*-*-*-*-1"); | |
|                 admin = adminService.login(admin); | |
|                 System.out.println(admin+"*-*-*-*-*-*-*-*-*-*-"); | |
|                 String token = JWTUtil.createJWT(admin); | |
|                 System.out.println(token+"token----------------------------------------"); | |
|                 admin.setPassword(null); | |
|                 return Result.success(token,admin); | |
|             } catch (Exception e) { | |
|                 e.printStackTrace(); | |
|                 log.error(e.getMessage()); | |
|                 return Result.error(e.getMessage()); | |
|             } | |
| 
 | |
|     } | |
|     @PostMapping("/userinfo") | |
|     public UserDetails getUserInfo(@RequestBody String requestBody) { | |
|         ObjectMapper objectMapper = new ObjectMapper(); | |
|         TokenPayload token1; | |
|         try { | |
|             token1 = objectMapper.readValue(requestBody, TokenPayload.class); | |
|         } catch (JsonProcessingException e) { | |
|             throw new RuntimeException(e); | |
|         } | |
|         String token = token1.getToken(); | |
| 
 | |
|         System.out.println("1/*/*/*/*//*-*-*-*-*-*-1" +token); | |
|         try { | |
|             System.out.println("/+/+/+/+/+/+/+//" + JWTUtil.getUserDetailsList(String.valueOf(token), Admin.class)); | |
|             return JWTUtil.getUserDetailsList(String.valueOf(token), Admin.class); | |
|         } catch (Exception e) { | |
|             throw new RuntimeException(e); | |
|         } | |
|     } | |
| 
 | |
| 
 | |
| }
 |