Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. public class User{
  2.  
  3.  
  4. @Column(unique = true, nullable = false)
  5. private String username;
  6. ...
  7. private String city;
  8. private String isHosting;
  9.  
  10. public boolean isHosting() {
  11. return hosting;
  12. }
  13.  
  14.  
  15. public void setHosting(boolean hosting) {
  16. this.hosting = hosting;
  17. }
  18.  
  19. ...
  20. }
  21.  
  22. public class Search {
  23.  
  24. private String city;
  25. private String sdate;
  26. private String fdate;
  27. private String numOfvisitor;
  28.  
  29. ...
  30.  
  31. }
  32.  
  33. @Repository
  34. public class SearchDao extends GenericDao<User> {
  35.  
  36. public User findByUserCity(final String city){
  37.  
  38. final Criteria c = createCriteria(User.class).add(Restrictions.eq("city", city));
  39.  
  40. return (User) c.uniqueResult();
  41. }
  42.  
  43. @Service
  44. @Transactional
  45. public class SearchService extends GenericService<User>{
  46.  
  47. @Autowired
  48. public SearchService(SearchDao dao) {
  49. super(dao);
  50.  
  51. }
  52.  
  53. ...
  54.  
  55. public User findByUserCity(final String city) {
  56. return ((SearchSurferDao) this.dao).findByUserCity(city);
  57. }
  58.  
  59. @RequestMapping(value = "/search", method = RequestMethod.GET)
  60. public ModelAndView search(@ModelAttribute Search search) {
  61.  
  62.  
  63. User user = SearchService.findByUserCity(search.getCity());
  64.  
  65. ModelAndView result = new ModelAndView("hello");
  66.  
  67. ...
  68.  
  69. result.addObject("username", user.getUsername());
  70. return result;
  71. }
  72.  
  73. Criteria c = createCriteria(User.class).add(Restrictions.eq("city", city));
  74. return (User) c.uniqueResult();
  75.  
  76. public List<User> findByUserCity(final String city) {
  77. Criteria c = createCriteria(User.class).add(Restrictions.eq("city", city));
  78. return c.list();
  79. }
  80.  
  81. public List<User> findByUserCity(String city) {
  82. return session.createQuery("select u from User u where u.city = :city")
  83. .setString("city", city)
  84. .list();
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement