Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.danchu.momuck.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.danchu.momuck.service.SearchService;
import com.danchu.momuck.view.ResultView;
import com.danchu.momuck.vo.Food;

@Controller
public class SearchController {

private static final Logger LOG = LoggerFactory.getLogger(SearchController.class);

@Autowired
private SearchService searchService;

@ResponseBody
@RequestMapping(value = "/search", method = RequestMethod.GET, produces = "application/json; charset=UTF-8")
public ResultView search(@RequestParam String keyword, @RequestParam int page, @RequestParam(defaultValue = "0") int sort) {
LOG.info(keyword);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

인덴트가 이상한것 같슴니다

LOG.info(String.valueOf(page));
LOG.info(String.valueOf(sort));
List<Food> result = searchService.search(keyword, page, sort);


return new ResultView("200", "success", result);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ public interface FoodDao {
public Food insertFood(Food food);
public List<Food> selectFoodList(int page);
public List<Food> selectFoodListByCategory(String category, int page);
public List<Food> selectFoodListByKeyword(String keyword, int page, int sort);
public int deleteFood(String name, int restaurantSeq);
}
17 changes: 17 additions & 0 deletions momuck-web/src/main/java/com/danchu/momuck/mapper/FoodMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
import java.util.HashMap;
import java.util.List;

import org.apache.ibatis.logging.log4j.Log4jImpl;
import org.mybatis.spring.SqlSessionTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Repository;

import com.danchu.momuck.dao.FoodDao;
import com.danchu.momuck.vo.Food;
import com.mysql.jdbc.log.Log;


/**
Expand All @@ -24,6 +28,7 @@ public class FoodMapper implements FoodDao {
private SqlSessionTemplate sqlSessionTemplate;

private static final String NAMESPACE = "Food";
private static final Logger LOG = LoggerFactory.getLogger(AccountMapper.class);

public Food insertFood(Food food) {
HashMap<String, Object> map = new HashMap<String, Object>();
Expand Down Expand Up @@ -58,4 +63,16 @@ public int deleteFood(String name, int restaurantSeq) {
sqlSessionTemplate.delete(NAMESPACE + ".deleteFood", map);
return 0;
}

public List<Food> selectFoodListByKeyword(String keyword, int page, int sort) {
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("offset", 0 + 10 * (page - 1));
map.put("keyword", keyword);
map.put("sort", sort);

LOG.info(keyword);
LOG.info(String.valueOf(page));
LOG.info(String.valueOf(sort));
return sqlSessionTemplate.selectList(NAMESPACE + ".selectFoodListByKeyword", map);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.danchu.momuck.service;

import java.util.List;

import com.danchu.momuck.vo.Food;

public interface SearchService {

List<Food> search(String keyword, int page, int sort);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.danchu.momuck.service;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.danchu.momuck.dao.FoodDao;
import com.danchu.momuck.vo.Food;

@Service
public class SearchServiceImpl implements SearchService {

private static final Logger LOG = LoggerFactory.getLogger(SearchServiceImpl.class);

@Autowired
private FoodDao foodDao;

public List<Food> search(String keyword, int page, int sort) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기도 인덴트 수정 부탁드림니다

return foodDao.selectFoodListByKeyword(keyword, page, sort);
}

}
16 changes: 16 additions & 0 deletions momuck-web/src/main/resources/mapper/food/Food_SQL.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,20 @@
DELETE FROM food
WHERE name = #{name} and restaurant_seq = #{restaurantSeq}
</delete>

<select id="selectFoodListByKeyword" resultMap="Food">
SELECT *
FROM food f, restaurant r
WHERE f.restaurant_seq = r.seq AND
(f.category LIKE CONCAT('%',#{keyword},'%') OR
f.name LIKE CONCAT('%',#{keyword},'%') OR
r.name LIKE CONCAT('%',#{keyword},'%'))
<if test="sort == 0">
ORDER BY f.avg_score desc
</if>
<if test="sort == 1">
ORDER BY f.price asc
</if>
LIMIT #{offset}, 10
</select>
</mapper>