-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
224 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/classes/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
-12 Bytes
(99%)
WebRoot/WEB-INF/classes/ssm/controller/ItemsController1.class
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package ssm.controller; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import javax.servlet.ServletException; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
import org.springframework.web.HttpRequestHandler; | ||
|
||
|
||
import ssm.po.Items; | ||
|
||
public class ItemsController2 implements HttpRequestHandler { | ||
|
||
@Override | ||
public void handleRequest(HttpServletRequest request, HttpServletResponse response) | ||
throws ServletException, IOException { | ||
//实际中是调用service查找数据库,查询商品列表,这里直接使用静态数据来模拟了 | ||
List<Items> itemsList = new ArrayList<Items>(); | ||
//向list中填充静态数据 | ||
Items items_1 = new Items(); | ||
items_1.setName("联想笔记本"); | ||
items_1.setPrice(6000f); | ||
items_1.setDetail("ThinkPad T430 联想笔记本电脑!"); | ||
|
||
Items items_2 = new Items(); | ||
items_2.setName("苹果手机"); | ||
items_2.setPrice(5000f); | ||
items_2.setDetail("iPhone6苹果手机!"); | ||
|
||
itemsList.add(items_1); | ||
itemsList.add(items_2); | ||
|
||
//设置模型数据 | ||
request.setAttribute("itemsList", itemsList); | ||
|
||
//设置转发的视图 | ||
request.getRequestDispatcher("/WEB-INF/jsp/items/itemsList.jsp").forward(request, response); | ||
|
||
//使用此方法可以通过修改response,设置响应的数据格式,比如响应json数据 | ||
/* | ||
response.setCharacterEncoding("utf-8"); | ||
response.setContentType("application/json;charset=utf-8"); | ||
response.getWriter().write("json串");*/ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package ssm.controller; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.servlet.ModelAndView; | ||
|
||
import ssm.po.Items; | ||
|
||
@Controller | ||
public class ItemsController3 { | ||
|
||
// 商品查询列表 | ||
// @RequestMapping实现 对queryItems方法和url进行映射,一个方法对应一个url | ||
// 一般建议将url和方法写成一样 | ||
@RequestMapping("/queryItems") | ||
public ModelAndView queryItems() throws Exception { | ||
|
||
// 实际中是调用service查找数据库,查询商品列表,这里直接使用静态数据来模拟了 | ||
List<Items> itemsList = new ArrayList<Items>(); | ||
// 向list中填充静态数据 | ||
Items items_1 = new Items(); | ||
items_1.setName("联想笔记本"); | ||
items_1.setPrice(6000f); | ||
items_1.setDetail("ThinkPad T430 联想笔记本电脑!"); | ||
|
||
Items items_2 = new Items(); | ||
items_2.setName("苹果手机"); | ||
items_2.setPrice(5000f); | ||
items_2.setDetail("iPhone6苹果手机!"); | ||
|
||
itemsList.add(items_1); | ||
itemsList.add(items_2); | ||
|
||
// 返回ModelAndView | ||
ModelAndView modelAndView = new ModelAndView(); | ||
|
||
// 相当于request的setAttribute,在jsp页面中通过itemsList取数据 | ||
modelAndView.addObject("itemsList", itemsList); | ||
|
||
// 指定视图 | ||
modelAndView.setViewName("/WEB-INF/jsp/items/itemsList.jsp"); | ||
|
||
return modelAndView; | ||
} | ||
|
||
@RequestMapping("/queryItems2") | ||
public ModelAndView queryItems2() throws Exception { | ||
|
||
// 实际中是调用service查找数据库,查询商品列表,这里直接使用静态数据来模拟了 | ||
List<Items> itemsList = new ArrayList<Items>(); | ||
// 向list中填充静态数据 | ||
Items items_1 = new Items(); | ||
items_1.setName("联想笔记本2"); | ||
items_1.setPrice(6000f); | ||
items_1.setDetail("ThinkPad T430 联想笔记本电脑!"); | ||
|
||
Items items_2 = new Items(); | ||
items_2.setName("苹果手机2"); | ||
items_2.setPrice(5000f); | ||
items_2.setDetail("iPhone6苹果手机!"); | ||
|
||
itemsList.add(items_1); | ||
itemsList.add(items_2); | ||
|
||
// 返回ModelAndView | ||
ModelAndView modelAndView = new ModelAndView(); | ||
|
||
// 相当于request的setAttribute,在jsp页面中通过itemsList取数据 | ||
modelAndView.addObject("itemsList", itemsList); | ||
|
||
// 指定视图 | ||
modelAndView.setViewName("/WEB-INF/jsp/items/itemsList.jsp"); | ||
|
||
return modelAndView; | ||
} | ||
} |