Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!

must Janik

Ranch Hand
+ Follow
since Jul 04, 2018
Cows and Likes
Cows
Total received
1
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
36
Given in last 30 days
1
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by must Janik

Thanks a lot @Stephan! I think I know already everything that I wanted to know.
1 week ago
Hi, I’m going to start writing my application for athletes based on Spring 2.5.6 and Java 6 (as I’ve read that Java 7 is less compatibile with this Spring version). I’ve couple of questions as I’m not familiar with such an old versions. (I need to write it for my Engineer’s Thesis – comparing app written in old version of Spring and in newest version of Sping Boot)  

1. I know already I need web.xml, but do I need servlets  to handle http requests or there is some other common way to do it? I won’t have any front sides (like jsp files) – just backend.
I mean, I want to build the most common app based on Spring 2.5 and java 6 and to do it I need these two things to do any request, right?

2. What about declaring beans in these versions. Do I need to do it in xml like <bean>….</bean> or I can annotate class with for example @Component (as @Service propably does not exist in this version). Which way should I go? I would like the differences to be most visible - beetwen spring boot and old spring, so declaring beans in xml would be fine (as in SpringBoot I have annotation like @Service, @Repository etc) -  but it’s hard to explain in my Engineer's Thesis why I’ve chosen for example declaring beans in xml when I could do it easily with annotations.

Do you have any simple crud examples of projects written in these versions?
1 week ago

Himai Minh wrote:Hi, Must,
I think you may need a CustomAdvertisementRepository interface and its implementation:






Your service or controller can do this:

In your pom, put java persistence dependency



yee, I have made with the same solution earlier. Thanks anyway, will be for next people!
2 months ago
That's why I wanted to use Example, but nevermind will check criteria out.
3 months ago

Dave Tolls wrote:Define a method for your repository which takes all the searchable parameters.
You'll then need to add an implementation, inside which use a CriteriaBuilder, adding criteria for each parameter that is supplied.

Something along those lines.

https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.custom-implementations
https://www.baeldung.com/spring-data-jpa-query (section 9.2)



Ye, I've heared about that but I thought that it's much longer solution than that I had. I cannot use Example right here?
3 months ago

Himai Minh wrote:If you only want to search by city, then create another method called findByCity.
If you have a very complicated query you can create something like this:



Folk, you dont understand me. These parameters are OPTIONAL. What if city will be null and I want to search only by category, what if category will be null and I want to search only by city, what if I want to search by both arguemnts. What if I will have 3,4,5 arguments to pass whcih some fo them can be null as I do not pass any value?

That's why I want to use dynamic query to query by only these values which are not nul... Do you understnad?
3 months ago

Himai Minh wrote:Try this :

I  think you don't need to build a query  since Spring Data JPA will build a query for you.



Is it good? I mean it will search only by city if I pass city? What if I will have like 10 arguments to pass (10 filters) I will have really huge name method. I'm thinking about this.
3 months ago

Himai Minh wrote:Hi, Must,
In your getSpecificShortAdvertisements() , the city is not a request parameter.  So, even if you input city=LALA, it still returns you everything.
In your Advertisement builder, the city is null and it may return you everything?



Hi Himai, thanks for the answer, but to be honest I do not understand.

To be clear, if I send the city "LALA" I want to get all advertisements with that city which I passed via controller to the service. If I pass city and category so for example: the city is LALA and category is HOUSEWORK I want to get all advertisements that contain category AND city not this or this. If nothing is passed so city and category is null it should return everything.

That's what I want to achieve. I searched via google and have found that this may be the best option for me. If you knwo some other options to create dynamic query you can tell.

3 months ago
I have a method controller which gonna return all advertisements that are being filtered by passed paremetrs.



So for example it can be: http://localhost:8080/search/advertisements?city=WARSZAWA&category=ANIMALSCARE

but it can be also http://localhost:8080/search/advertisements?category=ANIMALSCARE If I do not send any parameters it shoudl return all advertisements.

It would be so hard to write query for every single parameter, so I've used Example, but do not know why it returns empty list all the time despite having data in DB.

It's being added for every run of application (initial data)



So as you can see if I send 'WARSZAWA' as an city it should return this advertisement, but it returns nothing.

Service method:



Repo



SQL generated for this:

If I made



then it returns everything despite sending http://localhost:8080/search/advertisements?city=LALA which should not match anything

3 months ago
I have got two methods that redirect to the same .html file. First method is method responsible for saving, the second method is for updating. It has got the same view so I just wanted to move user to the same view. I have <h1>..</h1> in .html I would like to have title "New Mapping" for adding new mapping and "Update mapping" when we want to update mapping. These are methods that do all the stuff (redirecting to the .html file)



save.html file



I have added to model heading variable with according value, but unfortunately I have only ${heading} displayed.
Do you know how to fix it or how to make it on anothre way?
I do not want to use JS here
6 months ago
Even this small improvement (2 lines into 1) is much better. Thanks.
11 months ago
Without fetching letters in advance.



Is it better than previous? Can I improve this somehow?
11 months ago
I see that using streams is bad idea here. So with no talking about streams, is there any way to improve it and make it efficient?
11 months ago
Hi guys. Given sentence for example: ala ma kota, kot koduje w Javie kota I should to every letter occurring in the sentence I should map every string that this letter contains. So the output should be:


I have written algorithm for it, but I think that there is a better way do to this using streams (or somehow else).
Code;


And these two methods which are placed in other class:



Thanks a lot.
11 months ago
Bump. Really looking forward to see what I did wrong. Thanks.
11 months ago