修改完成登录注册跳转到首页并展示产品

master
jyx 7 years ago
parent 18ae4c8304
commit fc768aa566

@ -4,6 +4,7 @@ import com.example.demo.bean.User;
import com.example.demo.loginService.API.impl.UserServiceImpl; import com.example.demo.loginService.API.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import javax.servlet.ServletException; import javax.servlet.ServletException;
@ -21,7 +22,7 @@ public class UserController extends HttpServlet {
@Autowired @Autowired
private UserServiceImpl userServiceImpl; private UserServiceImpl userServiceImpl;
@PostMapping("/login") @GetMapping("/login")
public String handle(HttpServletRequest request, HttpServletResponse response)throws IOException, ServletException { public String handle(HttpServletRequest request, HttpServletResponse response)throws IOException, ServletException {
String userName = request.getParameter("userName"); String userName = request.getParameter("userName");
String userPwd = request.getParameter("userPwd"); String userPwd = request.getParameter("userPwd");
@ -30,8 +31,8 @@ public class UserController extends HttpServlet {
if(user.getUserPwd().equals(userPwd)){ if(user.getUserPwd().equals(userPwd)){
HttpSession session=request.getSession(); HttpSession session=request.getSession();
session.setAttribute("user",user); session.setAttribute("user",user);
return "redirect:index.html"; //request.getRequestDispatcher("index.html").forward(request,response);
//request.getRequestDispatcher("/").forward(request,response); return "index";
} }
else{ else{
return "/userPwdError"; return "/userPwdError";

@ -6,7 +6,10 @@ import com.example.demo.searchService.service.ProductSearchService;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.ServletException; import javax.servlet.ServletException;
@ -19,7 +22,9 @@ import java.util.List;
@Controller @Controller
public class SearchServiceController extends HttpServlet { public class SearchServiceController extends HttpServlet {
@Autowired
private ProductSearchService productSearchService; private ProductSearchService productSearchService;
@RequestMapping("/search") @RequestMapping("/search")
public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException { public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8"); response.setContentType("text/html;charset=utf-8");
@ -45,7 +50,13 @@ public class SearchServiceController extends HttpServlet {
response.getWriter().print(json); response.getWriter().print(json);
} }
public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException{
doPost(request,response); @PostMapping("/showIndex")
public void showPro(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException{
List<Product> products = productSearchService.findByCount();
String json = JSONObject.toJSONString(products);
System.out.println(json);
response.setCharacterEncoding("utf-8");
response.getWriter().print(json);
} }
} }

@ -4,6 +4,7 @@ import com.example.demo.bean.Product;
import java.util.List; import java.util.List;
public interface ProductSearchService { public interface ProductSearchService {
//按关键字查询 //按关键字查询
List<Product> findByNameLike(String productName); List<Product> findByNameLike(String productName);

@ -5,15 +5,17 @@ import com.example.demo.Dao.usageDateMapper;
import com.example.demo.bean.Product; import com.example.demo.bean.Product;
import com.example.demo.searchService.service.ProductSearchService; import com.example.demo.searchService.service.ProductSearchService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@Service
public class ProductSearchServiceImpl implements ProductSearchService { public class ProductSearchServiceImpl implements ProductSearchService {
@Autowired @Autowired
productMapper productMapper; productMapper productMapper;
@Autowired
usageDateMapper usageDateMapper; usageDateMapper usageDateMapper;
Product product;
@Override @Override
public List<Product> findByNameLike(String productName){ public List<Product> findByNameLike(String productName){
@ -32,6 +34,7 @@ public class ProductSearchServiceImpl implements ProductSearchService {
@Override @Override
public List<Product> findByCount(){ public List<Product> findByCount(){
Product product = new Product();
List<Product> productList = new ArrayList<Product>(); List<Product> productList = new ArrayList<Product>();
List<Integer> listusage = usageDateMapper.selectByCount(); List<Integer> listusage = usageDateMapper.selectByCount();
int[] arr = listusage.stream().mapToInt(Integer::valueOf).toArray(); int[] arr = listusage.stream().mapToInt(Integer::valueOf).toArray();

Loading…
Cancel
Save