Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class User{
- @Column(unique = true, nullable = false)
- private String username;
- ...
- private String city;
- private String isHosting;
- public boolean isHosting() {
- return hosting;
- }
- public void setHosting(boolean hosting) {
- this.hosting = hosting;
- }
- ...
- }
- public class Search {
- private String city;
- private String sdate;
- private String fdate;
- private String numOfvisitor;
- ...
- }
- @Repository
- public class SearchDao extends GenericDao<User> {
- public User findByUserCity(final String city){
- final Criteria c = createCriteria(User.class).add(Restrictions.eq("city", city));
- return (User) c.uniqueResult();
- }
- @Service
- @Transactional
- public class SearchService extends GenericService<User>{
- @Autowired
- public SearchService(SearchDao dao) {
- super(dao);
- }
- ...
- public User findByUserCity(final String city) {
- return ((SearchSurferDao) this.dao).findByUserCity(city);
- }
- @RequestMapping(value = "/search", method = RequestMethod.GET)
- public ModelAndView search(@ModelAttribute Search search) {
- User user = SearchService.findByUserCity(search.getCity());
- ModelAndView result = new ModelAndView("hello");
- ...
- result.addObject("username", user.getUsername());
- return result;
- }
- Criteria c = createCriteria(User.class).add(Restrictions.eq("city", city));
- return (User) c.uniqueResult();
- public List<User> findByUserCity(final String city) {
- Criteria c = createCriteria(User.class).add(Restrictions.eq("city", city));
- return c.list();
- }
- public List<User> findByUserCity(String city) {
- return session.createQuery("select u from User u where u.city = :city")
- .setString("city", city)
- .list();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement