Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get parameter which is containing dot(.) from rest url in spring

I am creating a web application using Spring REST and hibernate. Here i am fetching record from database using unique username which is coming from url. But the problem is that if i am writing simple string then it is working fine but when in username i am writing dot(.) then no result is coming from database.

For ex.

http://localhost:8080/WhoToSubscribe/subscribe/anshul007

but when i am using this url

http://localhost:8080/WhoToSubscribe/subscribe/nadeem.ahmad095

it is not working because it is containing dot(.)

Here is my controller

@RequestMapping(value = "/{uname}", method = RequestMethod.GET)
public @ResponseBody
List<Profession> getSubscriber(@PathVariable("uname") String uname) {

    List<Profession> pro = null;

    try {
        pro = subscribeService.getProfessionById(uname);


    } catch (Exception e) {
        e.printStackTrace();
    }

    return pro;
}

Here is my DAO class

@SuppressWarnings("unchecked")
public List<Profession> getProfessionById(String uname) throws Exception {
session = sessionFactory.openSession();
  session.beginTransaction();
  String queryString = "from Profession where username = :uname";
  Query query = session.createQuery(queryString);
  query.setString("uname", uname);
  //List<Profession> queryResult = (List<Profession>) query.uniqueResult();
  session.getTransaction().commit();
  return query.list();
}
like image 711
artle Avatar asked Aug 07 '15 11:08

artle


People also ask

How do I know if a URL has a parameter query?

To check if a url has query parameters, call the indexOf() method on the url, passing it a question mark, and check if the result is not equal to -1 , e.g. url. indexOf('? ') !== -1 .

Which parameter appears to the right of the in a URL?

While the query parameters appear on the right side of the '? ' in the URL, path parameters come before the question mark sign. Secondly, the query parameters are used to sort/filter resources. On the other hand, path parameters are used to identify a specific resource or resources.


1 Answers

change your mapping to /somepath/{variable:.+}

or add a slash at the end /somepath/{variable}/

like image 131
Jkike Avatar answered Sep 21 '22 07:09

Jkike