package com.wjh.controller;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.spring work.beans.factory.annotation.Autowired;
import org.spring work.stereotype.Controller;
import org.spring work.ui.Model;
import org.spring work.web.bind.annotation.RequestMapping;
import org.spring work.web.bind.annotation.ResponseBody;
import org.spring work.web.multipart.MultipartFile;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wjh.dao.CommodityMapper;
import com.wjh.dao.UserMapper;
import com.wjh.dao.model.Commodity;
import com.wjh.dao.model.CommodityExample;
import com.wjh.dao.model.CommodityExample.Criteria;
import com.wjh.dao.model.User;
import com.wjh.untl.FileUtils;
@Controller
public class CommodityController {
@Autowired
CommodityMapper comm;
@Autowired
UserMapper us;
@RequestMapping(\"login\")
@ResponseBody
public int login(HttpSession session,User user) {
User usr = us.login(user);
if(usr!=null) {
return 1;
}else {
return 0;
}
}
@RequestMapping(\"/list\")
public String list(CommodityExample example,Model model,Commodity co,Integer current,Integer size) {
if(current == null) {
current = 1;
}
if(size == null) {
size = 4;
}
PageHelper.startPage(current, size);
if(co.getName()!= null) {
Criteria criteria = example.createCriteria();
criteria.andNameLike(\"%\"+co.getName()+\"%\");
}
List<Commodity> list =comm.selectByExample(example);
PageInfo<Commodity> pageInfo = new PageInfo<Commodity>(list);
model.addAttribute(\"current\", current);
model.addAttribute(\"pageInfo\", pageInfo);
model.addAttribute(\"co\", co);
return \"list\";
}
/**
* 单删
* @return
*/
@RequestMapping(\"/del\")
@ResponseBody
public int del(int id) {
int i = comm.deleteByPrimaryKey(id);
return i;
}
/**
* 批删
* @return
*/
@RequestMapping(\"/dels\")
@ResponseBody
public int dels(String id) {
comm.dels(id);
return 1;
}
/**
* 跳转添加页面
* @return
*/
@RequestMapping(\"/toadd\")
public String toadd() {
return \"add\";
}
/**
* 添加
* @param br
* @return
*/
@RequestMapping(\"/add\")
public String add(Commodity co,MultipartFile file,HttpServletRequest request) throws
IllegalStateException, IOException{
String str = FileUtils.upload(file, request);
String logo=\"http://localhost:8888/upload/\"+str;
co.setCreationtime(new Date());
co.setTurnovertime(new Date());
co.setLogo(logo);
comm.insertSelective(co);
return \"redirect:list\";
}
@RequestMapping(\"/toupdate\")
public String toupdate(int id,Model model) {
Commodity co = comm.selectByPrimaryKey(id);
model.addAttribute(\"co\", co);
return \"update\";
}
@RequestMapping(\"/update\")
public String update(Commodity co,MultipartFile file,HttpServletRequest request) throws
IllegalStateException ,IOException
{
String str = FileUtils.upload(file, request);
String logo=\"http://localhost:8888/upload/\"+str;
co.setLogo(logo);
co.setTurnovertime(new Date());
comm.updateByPrimaryKeySelective(co);
return \"redirect:list\";
}
}
继续阅读与本文标签相同的文章
基于压机吨位的数据分析
-
将阿里云产品整合成为高校课程实训的训练营产品的实践(四)
2026-05-18栏目: 教程
-
中间人攻击,HTTPS也可以被碾压
2026-05-18栏目: 教程
-
什么叫做IaC,与DevOps有什么关系?如何实现?
2026-05-18栏目: 教程
-
解读《运维知识体系》,直面自动化运维的“灵魂八问”
2026-05-18栏目: 教程
-
阿里99大促 | 模型识别背后的样本生成
2026-05-18栏目: 教程
