简体   繁体   English

RESTful服务

[英]RESTful service

I have to write a RESTful service with client but have some problems with functions because cant figure what Media Type they should @Produces. 我必须使用客户端编写RESTful服务,但功能存在一些问题,因为无法确定@Produces应该使用哪种媒体类型。

Basically I have a few operations with strings: counting words, finding the index of a substring, counting symbols and reversing a string. 基本上,我对字符串有一些操作:对单词进行计数,查找子字符串的索引,对符号进行计数以及对字符串进行反转。

I have no problems with reversing the string, but with other three I am facing a problem because it seems that I can`t @Produce an int for some reason. 我没有反转字符串的问题,但是与其他三个字符串我都遇到了问题,因为由于某种原因,我似乎不能@produce一个int。

What type should I use so that I can @Produce an int so I can return it? 我应该使用哪种类型以便可以@Protuce int以便返回它?

Here is my Java code: 这是我的Java代码:

 public int getNumberOfWords(java.lang.String parameter) {

 int words;

        String [] sentence = parameter.split(" ");
        words = sentence.length;

        return words;





 public int getNumberOfSymbols(java.lang.String parameter) {
        //TODO implement this method
        //throw new UnsupportedOperationException("Not implemented yet.");
   return (int) parameter.chars()
            .distinct()
            .count();



 public java.lang.String invertString(java.lang.String text) {
    //TODO implement this method
    //throw new UnsupportedOperationException("Not implemented yet.");
     int i, len = text.length();
StringBuilder dest = new StringBuilder(len);

for (i = (len - 1); i >= 0; i--){
    dest.append(text.charAt(i));
}

return dest.toString();



 public int findSubstr(java.lang.String text, java.lang.String substr) {
      return text.indexOf(substr);

So the first 3 functions are problematic. 因此,前三个功能是有问题的。 I even tried with @Produces application/json type. 我什至尝试了@Produces application / json类型。

@Produces(“ application / json”)这样,您基本上就可以将大多数RESTFull必须映射到客户端对象的方法从方法中返回json,即使它是String或Integer之类的简单对象也是如此。

It's not possible return an int, @Produces defines which MIME type is provided by the method. 返回int是不可能的,@ Produces定义方法提供的MIME类型。 In your case the most suitable should be plain text. 在您的情况下,最合适的应该是纯文本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM