【232】ssm maven在线拍卖系统源码
开发工具:idea 或eclipse
数据库mysql5.7+
数据库链接工具:navcat,小海豚等
技术:ssm
package school.controller;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import school.domain.Product;
import school.domain.Record;
import school.domain.User;
import school.mapper.*;
import school.service.UserService;
import school.support.BaseController;
import school.support.pojo.CommentPo;
import school.support.pojo.OfferPo;
import school.support.util.ParamUtils;
import tk.mybatis.mapper.entity.Example;
import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;
@Controller
public class IndexController extends BaseController {
@Autowired
private UserService userService;
@Autowired
private UserMapper userMapper;
@Autowired
private ProductMapper productMapper;
@Autowired
private OfferMapper offerMapper;
@Autowired
private CommentMapper commentMapper;
@Autowired
private RecordMapper recordMapper;
@RequestMapping({"/", "index"})
public String index(Model model, @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "") String name) {
session.removeAttribute("errorMsg");
Example example = new Example(Product.class);
Example.Criteria criteria = example.createCriteria();
criteria.andLike("name", "%" + name + "%");
PageHelper.startPage(pageNum, pageSize);
PageInfo<Product> pageInfo = new PageInfo<Product>(productMapper.selectByExample(example), 5);
model.addAttribute(pageInfo);
model.addAttribute("url", request.getRequestURI() + "?" + ParamUtils.params2String(request));
return "index";
}
/**
* 到注册页面
*
* @return
*/
@GetMapping("register")
public String register() {
session.removeAttribute("errorMsg");
return "register";
}
/**
* 注册用户
*
* @return
*/
@PostMapping("register")
public String register(User user, Model model) {
model.addAttribute("errorMsg", session.getAttribute("errorMsg"));
session.removeAttribute("errorMsg");
if (userService.selectByUsername(user.getUsername()) != null) {
model.addAttribute("msg", "用户名已经存在");
return "register";
}
if (userService.selectByEmail(user.getEmail()) != null) {
model.addAttribute("msg", "邮箱已经存在");
return "register";
}
user.setAddtime(new Date());
user.setDeal(0);
user.setIllegal(0);
userMapper.insert(user);
model.addAttribute("errorMsg", "注册成功,验证信息已经发送邮箱,请去邮箱激活!");
return "redirect:index";
}
/**
* 登录页面
*
* @return
*/
@GetMapping("login")
public String login() {
session.removeAttribute("errorMsg");
return "login";
}
/**
* 登录
*
* @return
*/
@PostMapping("login")
public String login(String username, String password, HttpSession session, Model model) {
User user = userService.login(username, password);
if (null == user) {
model.addAttribute("msg", "用户名或密码错误");
return "login";
}
session.setAttribute("sessionUser", user);
return "redirect:index";
}
/**
* 退出系统
*
* @return
*/
@RequestMapping("logout")
public String logout(HttpSession session) {
session.removeAttribute("sessionUser");
return "redirect:login";
}
/**
* 项目详情
*
* @param id
* @return
*/
@RequestMapping("product/{id}")
public String product(@PathVariable Integer id, Model model) {
model.addAttribute("errorMsg", session.getAttribute("errorMsg"));
session.removeAttribute("errorMsg");
Product product = productMapper.selectByPrimaryKey(id);
updateProduct(product);
model.addAttribute(product);
//竞价记录
List<OfferPo> offerList = offerMapper.selectPoByProduct(id);
List<CommentPo> commentList = commentMapper.selectPoByProduct(id);
model.addAttribute("offerList", offerList);
model.addAttribute("commentList", commentList);
if (frontUser() != null) {
//竞价判断
Record record = new Record();
record.setProductid(id);
record.setUserid(frontUser().getId());
record = recordMapper.selectOne(record);
if (null == record) {
request.setAttribute("err", "error");
}
}
return "project";
}
}
package school.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import school.domain.Offer;
import school.domain.Product;
import school.domain.Record;
import school.mapper.OfferMapper;
import school.mapper.ProductMapper;
import school.mapper.RecordMapper;
import school.support.BaseController;
import java.util.Date;
@RequestMapping("offer")
@Controller
public class OfferController extends BaseController {
@Autowired
private OfferMapper offerMapper;
@Autowired
private ProductMapper productMapper;
@Autowired
private RecordMapper recordMapper;
/**
* 竞价
* @return
*/
@RequestMapping("send")
public String send(Integer price ,Integer productid){
session.removeAttribute("errorMsg");
Product product = productMapper.selectByPrimaryKey(productid);
updateProduct(product);
//竞价判断
Record record = new Record();
record.setProductid(productid);
record.setUserid(frontUser().getId());
record = recordMapper.selectOne(record);
if(null == record) {
session.setAttribute("error","error");
return refresh();
}
if(!product.getStatus().equals("拍卖中")){
session.setAttribute("errorMsg","该商品不能拍卖,不在拍卖的时间范围");
return refresh();
}
if(price < product.getCurrent()){
session.setAttribute("errorMsg","您的出价必须高于现在的出价");
return refresh();
}
product.setCount(product.getCount()+1);
product.setCurrent(price);
product.setIllegalprice(price);
product.setIllegaluser(frontUser().getId());
productMapper.updateByPrimaryKey(product);
//添加记录
Offer offer = new Offer();
offer.setAddtime(new Date());
offer.setPrice(price);
offer.setProductid(productid);
offer.setUserid(frontUser().getId());
offerMapper.insertSelective(offer);
session.setAttribute("errorMsg","竞价成功");
return refresh();
}
@RequestMapping("pay/{id}")
public String pay(@PathVariable Integer id){
Record record = new Record();
record.setProductid(id);
record.setUserid(frontUser().getId());
recordMapper.insert(record);
session.setAttribute("errorMsg","支付成功,可以参与竞拍了");
return refresh();
}
}