团队第一阶段冲刺四总结
作者:互联网
今天冲刺任务就是servlet和service的编写
Service
package com.supercook.service;
import com.supercook.bean.Food;
import com.supercook.bean.Food2;
import com.supercook.bean.Windows;
import java.util.List;
public interface FoodService {
public List<Food>
queryRice(String foodname);
public List<Food> queryXiaochi(String
foodname);
public List<Food> queryNoodle(String
foodname);
public List<Food> queryPastry(String
foodname);
public List<Food> querySimplesnack(String
foodname);
public List<Food> queryDrink(String foodname);
public List<Food> querySoup(String
foodname);
public List<Food> queryKind(String kind);
public List<Food> queryDish(String
foodname);
public List<Food2> queryFood(String
foodname);
public int dianzan(String name);
public int dianzan1(String name);
public Windows querySrc(String name);
}
package com.supercook.service;
public interface UserService {
public int zhuce(String username,String password,String number,String email,String sex,String age,String weight);
public int login(String name,String paw);
}
package com.supercook.service;
import com.supercook.bean.Food;
import com.supercook.bean.Food2;
import com.supercook.bean.Windows;
import com.supercook.dao.FoodDao;
import com.supercook.dao.FoodDaoImpl;
import java.util.List;
public class FoodServiceimpl implements FoodService{
private FoodDao foodDao = new FoodDaoImpl();
@Override
public List<Food2> queryFood(String foodname) {
return foodDao.search(foodname);
}
@Override
public List<Food> queryRice(String foodname) {
return foodDao.queryrice(foodname);
}
@Override
public List<Food> queryXiaochi(String foodname) {
return foodDao.queryxiaochi(foodname);
}
@Override
public List<Food> queryNoodle(String foodname) {
return foodDao.querynoodle(foodname);
}
@Override
public List<Food> queryPastry(String foodname) {
return foodDao.querypastry(foodname);
}
@Override
public List<Food> querySimplesnack(String foodname) {
return foodDao.querysimplesnack(foodname);
}
@Override
public List<Food> queryDrink(String foodname) {
return foodDao.querydrink(foodname);
}
@Override
public List<Food> querySoup(String foodname) {
return foodDao.querysoup(foodname);
}
@Override
public List<Food> queryKind(String kind) {
return foodDao.querykind(kind);
}
@Override
public List<Food> queryDish(String foodname) {
return foodDao.querydish(foodname);
}
@Override
public int dianzan(String name) {
return foodDao.dianzan(name);
}
@Override
public int dianzan1(String name) {
return foodDao.dianzan1(name);
}
@Override
public Windows querySrc(String name) {
return foodDao.querysrc(name);
}
}
package com.supercook.service;
import com.supercook.dao.UserDao;
import com.supercook.dao.UserDaoImpl;
public class UserServiceImpl implements UserService{
private UserDao userDao = new UserDaoImpl();
@Override
public int zhuce(String username, String password, String number, String email, String sex, String age, String weight) {
return userDao.adduser(username,password,number,email,sex,age,weight);
}
@Override
public int login(String name, String paw) {
int login = userDao.login(name, paw);
return login;
}
}
servlet
package com.supercook.servlet;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.IOException;
import java.lang.reflect.Method;
public abstract class BaseServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("UTF-8");
resp.setContentType("text/html; charset=UTF-8");
String action = req.getParameter("action");
try {
// 获取action业务鉴别字符串,获取相应的业务 方法反射对象
Method method = this.getClass().getDeclaredMethod(action, HttpServletRequest.class, HttpServletResponse.class);
// System.out.println(method);
// 调用目标业务 方法
method.invoke(this, req, resp);
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");
String action = request.getParameter("action");
try {
// 获取action业务鉴别字符串,获取相应的业务 方法反射对象
Method method = this.getClass().getDeclaredMethod(action, HttpServletRequest.class, HttpServletResponse.class);
// System.out.println(method);
// 调用目标业务 方法
method.invoke(this, request, response);
} catch (Exception e) {
e.printStackTrace();
}
}
}
package com.supercook.servlet;
import com.supercook.bean.Food;
import com.supercook.bean.Windows;
import com.supercook.service.FoodService;
import com.supercook.service.FoodServiceimpl;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class Servletquery extends BaseServlet {
private FoodService foodService = new FoodServiceimpl();
protected void listxiaochi(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
List<Food> foodList = foodService.queryKind("小吃");
System.out.println(foodList);
ArrayList<Windows>srcList = new ArrayList<>();
for(int i = 0;i < foodList.size();i++){
Food food = foodList.get(i);
Windows windows = foodService.querySrc(food.getPosition());
srcList.add(windows);
}
request.setAttribute("srcList",srcList);
request.setAttribute("foodlist1",foodList);
request.getRequestDispatcher("/xiaochi.jsp").forward(request,response);
}
protected void listrice(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
List<Food> foodList = foodService.queryKind("米饭");
System.out.println(foodList);
ArrayList<Windows>srcList = new ArrayList<>();
for(int i = 0;i < foodList.size();i++){
Food food = foodList.get(i);
Windows windows = foodService.querySrc(food.getPosition());
srcList.add(windows);
}
request.setAttribute("srcList",srcList);
request.setAttribute("foodlist1",foodList);
request.getRequestDispatcher("/rice.jsp").forward(request,response);
}
protected void listpastry(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
List<Food> foodList = foodService.queryKind("面点");
System.out.println(foodList);
ArrayList<Windows>srcList = new ArrayList<>();
for(int i = 0;i < foodList.size();i++){
Food food = foodList.get(i);
Windows windows = foodService.querySrc(food.getPosition());
srcList.add(windows);
}
request.setAttribute("srcList",srcList);
request.setAttribute("foodlist1",foodList);
request.getRequestDispatcher("/pastry.jsp").forward(request,response);
}
protected void listnoodle(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
List<Food> foodList = foodService.queryKind("面食");
System.out.println(foodList);
ArrayList<Windows>srcList = new ArrayList<>();
for(int i = 0;i < foodList.size();i++){
Food food = foodList.get(i);
Windows windows = foodService.querySrc(food.getPosition());
srcList.add(windows);
}
request.setAttribute("srcList",srcList);
request.setAttribute("foodlist1",foodList);
request.getRequestDispatcher("/noodle.jsp").forward(request,response);
}
protected void listdish(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
List<Food> foodList = foodService.queryKind("面食配菜");
System.out.println(foodList);
ArrayList<Windows>srcList = new ArrayList<>();
for(int i = 0;i < foodList.size();i++){
Food food = foodList.get(i);
Windows windows = foodService.querySrc(food.getPosition());
srcList.add(windows);
}
request.setAttribute("srcList",srcList);
request.setAttribute("foodlist1",foodList);
request.getRequestDispatcher("/dish.jsp").forward(request,response);
}
protected void listsimple(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
List<Food> foodList = foodService.queryKind("中式简餐");
System.out.println(foodList);
ArrayList<Windows>srcList = new ArrayList<>();
for(int i = 0;i < foodList.size();i++){
Food food = foodList.get(i);
Windows windows = foodService.querySrc(food.getPosition());
srcList.add(windows);
}
request.setAttribute("srcList",srcList);
request.setAttribute("foodlist1",foodList);
request.getRequestDispatcher("/simplesnack.jsp").forward(request,response);
}
protected void listdrink(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
List<Food> foodList = foodService.queryKind("饮品");
System.out.println(foodList);
ArrayList<Windows>srcList = new ArrayList<>();
for(int i = 0;i < foodList.size();i++){
Food food = foodList.get(i);
Windows windows = foodService.querySrc(food.getPosition());
srcList.add(windows);
}
request.setAttribute("srcList",srcList);
request.setAttribute("foodlist1",foodList);
request.getRequestDispatcher("/drink.jsp").forward(request,response);
}
protected void listsoup(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
List<Food> foodList = foodService.queryKind("汤");
System.out.println(foodList);
ArrayList<Windows>srcList = new ArrayList<>();
for(int i = 0;i < foodList.size();i++){
Food food = foodList.get(i);
Windows windows = foodService.querySrc(food.getPosition());
srcList.add(windows);
}
request.setAttribute("srcList",srcList);
request.setAttribute("foodlist1",foodList);
request.getRequestDispatcher("/soup.jsp").forward(request,response);
}
}
标签:String,List,request,冲刺,foodname,团队,foodList,public,第一阶段 来源: https://www.cnblogs.com/20203923rensaihang/p/16373367.html