when should I use PathVariable and when should I use RequestParam [closed] - java

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 1 year ago.
Improve this question
I understand the main difference between the two,
#RequestParam is used for query parameters, and can have few more attributes,
while #PathVariable has one attribute and is for a path parameter.
but I couldn't find any info about when there's a preference to use either query param or path param.
I assume that in some cases in which I want a default value or some other attribute that #RequestParam has, It's probably better to use it. but is there any big difference other than that? any time that #PathVariable is preferred?

It depends on your design choices, i.e. whether you want to have information in your path or the query part. Using REST you would normally put resource identifiers into the path and additional parameters into the query, e.g. like this (made up):
/questions/67156664/comments?count=5
This would mean:
comments for question with id 67156664 (path variable)
return up to 5 comments (query param)
Note again, that it often depends on your requirements, i.e. what part of your url you want to put the parameters in.

Related

How to achieve the same result as with filter and findFirst [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 1 year ago.
Improve this question
Is there a more elegant way to achieve by using java 8 or above the eighth version what's below?
List<String> exampleList = List.of("test","test1");
exampleList.stream().filter(s -> s.equals("test")).findFirst();
Thanks in advance
It depends on what exactly you want to do.
If you just want to check if "test" is in one of the elements, you could just use .contains():
List.of("test","test1").contains("test");
If you want to find the first element fitting a condition, you can omit creating the list and directly create a Stream:
Stream.of("test","test1").filter(s->"test".equals(s)).findFirst()
If you want to check if an element fitting the condition exist, you can use anyMatch:
Stream.of("test","test1").anyMatch(s->"test".equals(s))
This is probably the best your going to get.
List<String> exampleList = List.of("test","test1");
exampleList.stream().filter("test"::equals).findFirst();
If its reused you can just make a method out of the 2nd line. Question has also already been answered here

Why the name IntSupplier and not ToIntSupplier? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I'm a little confused with the naming conventions used in default functional interface names available in javax.util.function package:
For instance, primitive specialization of Function have names like:
IntFunction/LongFunction/DoubleFunction in which argument type is of specified type
But primitive specialization of Supplier have names like:
BooleanSupplier/DoubleSupplier/LongSupplier/IntSupplier in which return type is of specified type.
If you compare the name and functionality of other interfaces in java.util.function, shouldn't the names have been like:
ToBooleanSupplier/ToDoubleSupplier/ToLongSupplier/ToIntSupplier?
The word "to" in ToIntFunction, ToDoubleFunction, et al indicates that something is being converted to something else. The function's input parameters are being converted into an int/double/whatever.
The word "supplier" denotes a function that takes no input and returns some value. It supplies values. There's no input, only output.
Adding "to" would be redundant and/or misleading: redundant because the fact that it returns values is already indicated by the word "supplier"; misleading because there's no conversion. The values are generated out of thin air.

How to write LIKE condition for UUID by Querydsl to find values wich match prefix? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I need to write a code by using Querydsl for this https://stackoverflow.com/a/46494463/7750228.
How to do it?
Since this is Postgres, you have to use function cast() to do this, because JPQL validator does not recognize this kind of casting. You have a choice:
Write native query
Use cast(expression as datatype) function instead of casting like this ::datatype.
The result would look like:
SELECT u FROM User u
WHERE cast(id as text) LIKE CONCAT(:prefix,'%')

Java naming convention for identifiers that begin with a number [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I have to deal with a domain object that's real name is 351K-Report. According to the Java naming convention its forbidden to use a number at the beginning of an identifier.
I don't want to fully spell out the number. And, I also think that it's a bad idea to place an underline in front of the number.
But what is the recommended alternative?
UPDATE
There are also other reports, like SpecReport, TopReport, LF10Report and so on. So I'm very doubtful that inverting parts of the noun changes the meaning of the whole project.
Maybe reverse it. For example:
report351K
That would be very bad..
Imagine this:
int 1d = 3;
double d = 1d * 2;
What would be d?
Alternatives:
Since variables that begins with _ usually indicates for class member, I would use report351K.
if you really want to do this then _351KReport but I don't think you should do this. try to make something meaningful of it and at the same time is convineient to Java

Naming convention for JSF pages [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
In Java, there's a naming convention for classes, interfaces, packages, methods, variables and constants. I'm just wondering if there is a naming convention for JSF XHTML pages.
Here are a few variants that came up to my mind:
MyPage.xhtml
myPage.xhtml
my-page.xhtml
mypage.xhtml
There's no need to think of xhtml pages as something different from plain html pages. In the end, if a user has to type it out, then it would help to have a simple page name (just like we would name any html page).
To give you an example, even a company like Apple who are so specific about using the correct case for their products, still maintain a URL such as http://www.apple.com/iphone! (iPhone is written as iphone)
To summarize I would say, don't use capital letters in URL, and try not to use special characters either.
Camel-case starting with a lowercase letter is good, I use hyphens to distinguish modules/ subpages/ subelements.
For example:
productList.xhtml
productEdit.xhtml
productEdit-buttons.xhtml
productReport.xhtml
customerAddress.xhtml
customerAddress-map.xhtml
Not a formal convention, but it works well. Being able to modularize or identify fragments or sub-functions is useful.

Categories