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

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

@ -6,7 +6,10 @@ import com.example.demo.searchService.service.ProductSearchService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
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 javax.servlet.ServletException;
@ -19,7 +22,9 @@ import java.util.List;
@Controller
public class SearchServiceController extends HttpServlet {
@Autowired
private ProductSearchService productSearchService;
@RequestMapping("/search")
public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
@ -45,7 +50,13 @@ public class SearchServiceController extends HttpServlet {
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;
public interface ProductSearchService {
//按关键字查询
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.searchService.service.ProductSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
@Service
public class ProductSearchServiceImpl implements ProductSearchService {
@Autowired
productMapper productMapper;
@Autowired
usageDateMapper usageDateMapper;
Product product;
@Override
public List<Product> findByNameLike(String productName){
@ -32,6 +34,7 @@ public class ProductSearchServiceImpl implements ProductSearchService {
@Override
public List<Product> findByCount(){
Product product = new Product();
List<Product> productList = new ArrayList<Product>();
List<Integer> listusage = usageDateMapper.selectByCount();
int[] arr = listusage.stream().mapToInt(Integer::valueOf).toArray();

Loading…
Cancel
Save