search

Home  >  Q&A  >  body text

java - spring mvc 返回值加密

项目中使用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处理,但是没成功,求高手指教。

PHPzPHPz2888 days ago574

reply all(6)I'll reply

  • PHPz

    PHPz2017-04-18 10:33:39

    Do you want to encrypt your password? ? Can be encrypted with md5

    reply
    0
  • 高洛峰

    高洛峰2017-04-18 10:33:39

    • 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

    reply
    0
  • ringa_lee

    ringa_lee2017-04-18 10:33:39

    Can the filter print records?

    reply
    0
  • 迷茫

    迷茫2017-04-18 10:33:39

    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

    reply
    0
  • 阿神

    阿神2017-04-18 10:33:39

    Just use the interceptor function that comes with spring mvc to implement it

    reply
    0
  • 迷茫

    迷茫2017-04-18 10:33:39

    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.

    reply
    0
  • Cancelreply