一.pojo
1.基本实体类
Items(商品信息)
Orderdetail(订单详情)
Orders(订单)
User(用户)
2.自定义扩展类(用以Mapper中映射及参数绑定)
OrdersCustom extends Orders(在订单信息基础上增加所需)
UserCustom extends User(在用户信息基础上增加所需)
public class ItemsQueryVo{
//商品信息
private Items items;
//扩展pojo
private ItemsCustom itemsCustom;
//批量商品信息
private List<ItemsCustom> itemsList;
//用户信息
//private UserCustom userCustom;
}
public class QueryVo{
private Map<String,Object> iteminfo=new HashMap<String,Object>();
private User user;
private UserCustom userCustom;
private List<Integer> ids;
}
二.Dao
public interface UserDao {
//根据id查询用户信息
public User findUserById(int id) throws Exception;
//根据用户名列查询用户列表
public List<User> findUserByName(String name) throws Exception;
//添加用户信息
public void insertUser(User user) throws Exception;
//删除用户信息
public void deleteUser(int id) throws Exception;
}
三.Service
根据id查询商品信息
public ItemsCustom findItemsById(Integer id) throws Exception;
商品修改
public void updateItems(Integer id,ItemsCustom itemsCustom)throws Exception;
四.Controller
1.返回ModelAndView
@requestMapping(value="/editItems",method=RequestMethod.POST)
public ModelAndView editItems()throws Exception{
ItemsCustom itemsCustom=itemsService.findItemsById(1)
model.addAttribute("itemsCustom",itemsCustom)
}
2.返回string@requestMapping(value="/editItems",method=RequestMethod.POST)
public String editItems(Model model)throws Exception{
ItemsCustom itemsCustom=itemsService.findItemsById(1);
model.addAttribute("itemsCustom",itemsCustom)
返回视图
return "items/editItems";
重定向
return "redirect:queryItems.action";
转发
return "forward:queryItems.action";
}
返回void
public void editItems(HttpServletRequest request,HttpServletResponse response)throws Exception{
ItemsCustom itemsCustom=itemsService.findItemsById(1);
返回视图
return "items/editItems";
重定向
return "redirect:queryItems.action";
转发
return "forward:queryItems.action";
}
1、使用request转向页面,如下:
request.getRequestDispatcher("页面路径").forward(request, response);
2、也可以通过response页面重定向:
response.sendRedirect("url")
3、也可以通过response指定响应结果,例如响应json数据如下:
response.setCharacterEncoding("utf-8");
response.setContentType("application/json;charset=utf-8");
response.getWriter().write("json串");
@RequestMapping("/itemsView/{id}")
public @responseBody ItemsCustom itemsView(@PathVariable("id") Integer id)throws Exception{
ItemsCustom itemsCustom=itemsService.findItemsById(id);
return itemsCustom;
}
本文详细介绍了Java商城系统的开发流程,包括实体类设计如商品、订单等,DAO层的增删查改操作,Service层的商品信息查询与更新,以及Controller层的请求处理方式。文章还探讨了不同的响应类型,如ModelAndView、String和void,并提供了页面转向和重定向的具体实现。
1768

被折叠的 条评论
为什么被折叠?



