小组成员分工
zhanghanmu:主要完成源码编写
zhaoxue :主要完成软件的环境配置,可以运行helloworld等,认真听课
wangchenyue:主要完成软件的环境配置,可以运行helloworld等,认真听课
fengqilu:主要完成软件的环境配置,可以运行helloworld等,认真听课
zhaozhehan: 主要完成软件的环境配置,可以运行helloworld等,认真听课
jinjiajun:主要完成软件的环境配置,可以运行helloworld等,认真听课
项目介绍
请在此处描述项目的主要功能、核代码、代码截图、运行效果截图在这里插入代码片
在这里插入代码片`
1.首先配置好java环境
2.安装好IDEA
3.创建helloworld包
4.安装maven,并解决maven导包问题
5.安装完成MySQL
等一些环境的配置。
package com.cn.panda.config;
public class Constants {
public static String ok = "ok";
public static String ERROR = "ERROR";
}
package com.cn.panda.controller;
import com.cn.panda.entity.Attraction;
import com.cn.panda.entity.Order;
import com.cn.panda.entity.User;
import com.cn.panda.service.AttractionService;
import com.cn.panda.service.CollectService;
import com.cn.panda.service.OrderService;
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.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Type;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
@Controller
@RequestMapping("/attraction")
public class AttractionController {
@Autowired
private AttractionService attractionService;
@Autowired
private CollectService collectService;
@Autowired
private OrderService orderService;
@RequestMapping("/list")
public String getAttractions(HttpServletRequest request, @RequestParam(required = true, name = "page", defaultValue = "1") Integer page) {
PageHelper.startPage(page, 8);
List<Attraction> attractions = attractionService.getAttractions();
PageInfo<Attraction> pageInfo = new PageInfo<>(attractions, 5);
request.setAttribute("pageInfo", pageInfo);
System.out.println("当前页:" + pageInfo.getPageNum());
System.out.println("总页码:" + pageInfo.getPages());
System.out.println("总条数:" + pageInfo.getPageSize());
System.out.println("每页显示的条数:" + pageInfo.getPageSize());
List<Attraction> list = pageInfo.getList();
for (int i = 0; i < list.size(); i++) {
Attraction attraction = list.get(i);
System.out.println(attraction);
}
return "front/attraction";
@RequestMapping("/{id}")
public String getAttractionById(@PathVariable(name = "id") int id, HttpServletRequest request){
Attraction attraction = attractionsService.getAttractionById(id);
request.setAttribute("attraction", attraction);
User user = (User) request.getSession().getAttribute("user");
if (user != null) {
int userID = user.getId();
boolean isCollect = collectService.isCollect(userID, Type.attraction, id);
request.setAttribute("isCollect", isCollect);
Order order = orderService.getOrderByTypeAndIDs(UserId, Type.attraction, id);
if (order != null) {
String pattern = "yyyy-MM-dd";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
Date createTimeDate = order.getOrderTime();
String createTimeString = simpleDateFormat(createTimeDate);
Date todayTimeDate = new Date();
String todayTimeString = simpleDateFormat.format(todayTimeDate);
if (createTimeString.equals(todayTimeString)) {
request.setAttribute("isOrder", true);
} else {
request.setAttribute("isOrder", false);
}
} else {
request.setAttribute("idOrder", false);
}
} else {
request.setAttribute("isOrder", false);
}
return "front/attraction_datail";
}
}
}
package com.cn.panda.controller;
import com.cn.panda.entity.Collect;
import com.cn.panda.service.CollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpSession;
@Controller
@RequestMapping("/collect")
public class CollectController {
@Autowired
private CollectService collectService;
@PostMapping("/on")
public String on(Collect collect, @RequestParam(name="from",required = true)String from, HttpSession session){
boolean on = collectService.saveCollect(collect);
if (on){
session.setAttribute("message","收藏成功");
}else {
session.setAttribute("message","收藏失败");
}
return "redirect:" + from;
}
@PostMapping("off")
public String off(Collect collect, @RequestParam(name="from",required = true)String from, HttpSession session){
boolean off = collectService.saveCollect(collect);
if (off){