最后
面试题文档来啦,内容很多,485页!
由于笔记的内容太多,没办法全部展示出来,下面只截取部分内容展示。
1111道Java工程师必问面试题
MyBatis 27题 + ZooKeeper 25题 + Dubbo 30题:
Elasticsearch 24 题 +Memcached + Redis 40题:
Spring 26 题+ 微服务 27题+ Linux 45题:
Java面试题合集:
<c:forEach items=“${itemList }” var=“item”>
${item.name } ${item.price } ${item.detail } 修改</c:forEach>
3、修改ItemController.java当中的queryItem方法的参数
@RequestMapping(“queryItem”)//绑定请求地址
public String queryItem(QueryVo vo,Integer[] ids, Model model){
if(vo.getItem() != null){
System.out.println(vo.getItem().toString());
}
//模拟搜索商品
List itemList = itemService.getItemList();
model.addAttribute(“itemList”, itemList);
return “itemList”;
}
4、运行并测试
http://localhost:8080/itemList.action
选择1和3提交
点击查询后台显示内容
5、修改QueryVo类,添加数组列表
package com.itzheng.springmvc.pojo;
/**
-
包装的pojo传递
-
@author Steven
*/
public class QueryVo {
private Item item;
private Integer[] ids;
public Integer[] getIds() {
return ids;
}
public void setIds(Integer[] ids) {
this.ids = ids;
}
public Item getItem() {
return item;
}
public void setItem(Item item) {
this.item = item;
}
}
6、运行并测试项目
在QueryVo当中的
http://localhost:8080/itemList.action
选择1和3提交
点击查询后台显示内容
两种QueryVo当中的Integer[] ids和方法参数Integer[] ids当中的内容都有值,无论是类当中变量和方法的参数只要和参数的名称所对应上,就可以绑定数据
1、List参数绑定
(1)修改itemList.jsp
<%@ page language=“java” contentType=“text/html; charset=UTF-8”
pageEncoding=“UTF-8”%>
<%@ taglib uri=“http://java.sun.com/jsp/jstl/core” prefix=“c” %>
<%@ taglib uri=“http://java.sun.com/jsp/jstl/fmt” prefix=“fmt”%>
查询条件:
商品列表:
<c:forEach items=“${itemList }” var=“item” varStatus=“status” >
<%–
${item.name } ${item.price } ${item.detail } 修改–%>
修改</c:forEach>
(2)修改QueryVo类
package com.itzheng.springmvc.pojo;
import java.util.List;
/**
-
包装的pojo传递
-
@author Steven
*/
public class QueryVo {
private Item item;
private Integer[] ids;
private List items;
public List getItems() {
return items;
}
public void setItems(List items) {
this.items = items;
}
public Integer[] getIds() {
return ids;
}
public void setIds(Integer[] ids) {
this.ids = ids;
}
public Item getItem() {
return item;
}
public void setItem(Item item) {
this.item = item;
}
}
(3)访问页面http://localhost:8080/queryItem.action
(4)测试项目
a、修改ItemController.java
@RequestMapping(“queryItem”)//绑定请求地址
public String queryItem(QueryVo vo,Integer[] ids, Model model){
if(vo.getItem() != null){
System.out.println(vo.getItem().toString());
}
if(ids != null && ids.length > 0) {
for (Integer id : ids) {
System.out.println(id);
}
}
if(vo.getItem() != null && vo.getItems().size() > 0) {
for (Item item : vo.getItems()) {
System.out.println(item);
}
}
//模拟搜索商品
List itemList = itemService.getItemList();
model.addAttribute(“itemList”, itemList);
return “itemList”;
}
b、访问页面测试并提交参数
访问页面http://localhost:8080/queryItem.action
修改内容并提交表单
页面报错
修改jsp页面内容
重新提交页面
1、配置多个请求地址
(1)修改ItemController当中的itemList方法
@RequestMapping(value = {“itemList”,“itemList2”})
public ModelAndView itemList() {
ModelAndView mav = new ModelAndView();
List itemList = itemService.getItemList();
mav.addObject(“itemList”, itemList);
// mav.setViewName(“/WEB-INF/jsp/itemList.jsp”);
mav.setViewName(“itemList”);
return mav;
}
(2)运行并测试
http://localhost:8080/itemList.action
使用绑定的第二个访问http://localhost:8080/itemList2.action
2、@RequestMapping加在类的上面:分目录管理
@Controller
@RequestMapping(“item”)
public class ItemController {
@Autowired
private ItemService itemService;
@RequestMapping(value = {“itemList”,“itemList2”})
public ModelAndView itemList() {
ModelAndView mav = new ModelAndView();
List itemList = itemService.getItemList();
mav.addObject(“itemList”, itemList);
// mav.setViewName(“/WEB-INF/jsp/itemList.jsp”);
mav.setViewName(“itemList”);
return mav;
}
运行并访问项目
新的访问地址:http://localhost:8080/item/itemList.action
演示完注释一下
3、设置固定的提交请求方式
(1)设置为只接收post请求
修改ItemController.java当中的updateItem方法
@RequestMapping(value=“updateItem”,method = RequestMethod.POST)
public String updateItem(Item item,Model model){
itemService.updateItem(item);
model.addAttribute(“item”, item);
model.addAttribute(“msg”, “修改商品信息成功”);
return “itemEdit”;
}
(2)设置为接收post和get请求
修改ItemController.java当中的updateItem方法
/**
-
修改商品
-
演示pojo参数绑定
-
@param item
-
@return
*/
@RequestMapping(value=“updateItem”,method = {RequestMethod.POST,RequestMethod.GET})
public String updateItem(Item item,Model model){
itemService.updateItem(item);
model.addAttribute(“item”, item);
model.addAttribute(“msg”, “修改商品信息成功”);
return “itemEdit”;
}
(3)在Tomcat的server.xml文件当中配置get请求的编码格式
1、返回void
(1)创建新页面
<%@ page language=“java” contentType=“text/html; charset=UTF-8” pageEncoding=“UTF-8”%>
${ msg }
(2)在ItemController当中创建queryVoid方法
a、request响应用户请求
@RequestMapping(“queryVoid”)
public void queryVoid(HttpServletRequest request,HttpServletResponse response) throws Exception {
request.setAttribute(“msg”, “这个是request响应的消息”);
request.getRequestDispatcher(“/WEB-INF/jsp/msg.jsp”).forward(request, response);
}
运行并测试
http://localhost:8080/queryVoid.action
b、response响应用户请求
@RequestMapping(“queryVoid”)
public void queryVoid(HttpServletRequest request,HttpServletResponse response) throws Exception {
//request响应用户请求
/*
-
request.setAttribute(“msg”, “这个是request响应的消息”);
-
request.getRequestDispatcher(“/WEB-INF/jsp/msg.jsp”).forward(request,
-
response);
*/
//response的响应用户请求
response.sendRedirect(“/itemList.action”);
}
运行并测试http://localhost:8080/itemList.action
c、response打印消息
@RequestMapping(“queryVoid”)
public void queryVoid(HttpServletRequest request,HttpServletResponse response) throws Exception {
//request响应用户请求
/*
-
request.setAttribute(“msg”, “这个是request响应的消息”);
-
request.getRequestDispatcher(“/WEB-INF/jsp/msg.jsp”).forward(request,response);
*/
//response的响应用户请求
//response.sendRedirect(“/itemList.action”);
PrintWriter printwriter = response.getWriter();
printwriter.println(“response”);
}
http://localhost:8080/queryVoid.action
2、返回String
(一)SpringMVC请求转发
(1)修改ItemController类当中updateItem方法:
总结
谈到面试,其实说白了就是刷题刷题刷题,天天作死的刷。。。。。
为了准备这个“金三银四”的春招,狂刷一个月的题,狂补超多的漏洞知识,像这次美团面试问的算法、数据库、Redis、设计模式等这些题目都是我刷到过的
并且我也将自己刷的题全部整理成了PDF或者Word文档(含详细答案解析)
66个Java面试知识点
架构专题(MySQL,Java,Redis,线程,并发,设计模式,Nginx,Linux,框架,微服务等)+大厂面试题详解(百度,阿里,腾讯,华为,迅雷,网易,中兴,北京中软等)
算法刷题(PDF)
F,t_70)
2、返回String
(一)SpringMVC请求转发
(1)修改ItemController类当中updateItem方法:
总结
谈到面试,其实说白了就是刷题刷题刷题,天天作死的刷。。。。。
为了准备这个“金三银四”的春招,狂刷一个月的题,狂补超多的漏洞知识,像这次美团面试问的算法、数据库、Redis、设计模式等这些题目都是我刷到过的
并且我也将自己刷的题全部整理成了PDF或者Word文档(含详细答案解析)
[外链图片转存中…(img-PvTVm0xT-1715470262317)]
66个Java面试知识点
架构专题(MySQL,Java,Redis,线程,并发,设计模式,Nginx,Linux,框架,微服务等)+大厂面试题详解(百度,阿里,腾讯,华为,迅雷,网易,中兴,北京中软等)
[外链图片转存中…(img-Ol9EjPuQ-1715470262317)]
算法刷题(PDF)
[外链图片转存中…(img-RASBB89T-1715470262317)]