项目中使用spring mvc的@ResponseBody注解返回结果,现在的需求是不改变原来的业务逻辑代码,对结果进行加密,如何处理?
@Controller @RequestMapping(value = "/crypt") public class CryptController { @ResponseBody @RequestMapping(value = "/decrypt", method = RequestMethod.GET) public String decrypt(int id, String name) { return "id=" + id + ", name=" + name; } }
本人尝试使用Filter处理,但是没成功,求高手指教。
Do you want to encrypt your password? ? Can be encrypted with md5
Don’t change the original code? Does it mean that the code is not changed? Business logic or code for the entire project?
You can try to write an encryption tool class, throw the things you want to encrypt into it before returning and then return it again
Can the filter print records?
Isn’t the purpose of the question title to ensure safety? You can use the following methods
1. Add token or session authentication to the request to prevent random calls
2. You can use the postHandle method of Spring MVC Interceptor to further process the results
Just use the interceptor function that comes with spring mvc to implement it
Isn’t it necessary to encrypt ""id=" + id + ", name=" + name"? What are they talking about upstairs... Each interface returns data encryption, decryption in the filter, using des, etc.