package com.fz.controller;
import com.fz.entity.BaoMing;
import com.fz.entity.News;
import com.fz.entity.YYBaoMing;
import com.fz.mapper.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Controller
public class IndexController {
@Autowired
private YYBaoMingMapper ym;
@Autowired
private BaoMingMapper bm;
@Autowired
private LunboMapper lm;
@Autowired
private ZYMapper zm;
@Autowired
private BannerMapper bannerMapper;
@Autowired
private WebconfMapper wm;
@Autowired
private NewsMapper nm;
@Autowired
private JYXQMapper jm;
@RequestMapping("/index")
public ModelAndView index() {
//前台显示预约报名
ModelAndView mv = new ModelAndView("index");
int num=ym.queryCount();
List<YYBaoMing> yyBaoMings;
if (num<8) {
yyBaoMings = ym.queryAll();
}else {
yyBaoMings=ym.queryLimit();
}
for (YYBaoMing y : yyBaoMings) {
String name = y.getName();
String phone = y.getPhone();
String newname=null;
char[] r = name.toCharArray();
char[] m = phone.toCharArray();
if (r.length == 2) {
newname = name.replaceFirst(name.substring(1), "*");
}
if (r.length > 2) {
newname = name.replaceFirst(name.substring(1, r.length - 1), "*");
}
for (int i = 0; i < m.length; i++) {
if (i > 2 && i < 7) {
m[i] = '*';
}
}
String mobile = String.valueOf(m);
y.setName(newname);
y.setPhone(mobile);
}
mv.addObject("yy",yyBaoMings);
//显示前台报名信息
int n = bm.queryCount();
List<BaoMing> baoMings;
if (n<8){
baoMings = bm.queryAll();
}else {
baoMings = bm.queryLimit();
}
mv.addObject("bm",baoMings);
//前台轮播查询
mv.addObject("zxdt",lm.queryByfenlei("最新动态"));
mv.addObject("xyhj",lm.queryByfenlei("校园环境"));
mv.addObject("xyhd",lm.queryByfenlei("校园活动"));
mv.addObject("jymx",lm.queryByfenlei("就业明星"));
mv.addObject("zy",zm.queryLimit());
mv.addObject("zyminid",zm.queryMinId());
// Banner图
mv.addObject("banner",bannerMapper.queryAll());
// 网站信息配置
mv.addObject("webconf",wm.selectByPrimaryKey(1));
//新闻显示
mv.addObject("hynews",nm.selHyNews());
mv.addObject("xxnews",nm.selXxNews());
return mv;
}
//新闻资讯
@RequestMapping("/news")
public ModelAndView a1(@RequestParam(defaultValue = "1", required = false, value = "p") int p){
ModelAndView mv=new ModelAndView("/news");
//显示前台报名信息
int n = bm.queryCount();
List<BaoMing> baoMings;
if (n<8){
baoMings = bm.queryAll();
}else {
baoMings = bm.queryLimit();
}
//前台显示预约报名信息
int num=ym.queryCount();
List<YYBaoMing> yyBaoMings;
if (num<8) {
yyBaoMings = ym.queryAll();
}else {
yyBaoMings=ym.queryLimit();
}
for (YYBaoMing y : yyBaoMings) {
String name = y.getName();
String phone = y.getPhone();
String newname=null;
char[] r = name.toCharArray();
char[] m = phone.toCharArray();
if (r.length == 2) {
newname = name.replaceFirst(name.substring(1), "*");
}
if (r.length > 2) {
newname = name.replaceFirst(name.substring(1, r.length - 1), "*");
}
for (int i = 0; i < m.length; i++) {
if (i > 2 && i < 7) {
m[i] = '*';
}
}
String mobile = String.valueOf(m);
y.setName(newname);
y.setPhone(mobile);
}
//校园动态分页
int pagesize = 10;
int currpage = 1;
currpage = p;
//查询多少条记录
int recordcount =nm.queryXxCount();
//一共多少页
int pagecount = recordcount % pagesize == 0 ? recordcount / pagesize : recordcount / pagesize + 1;
if (currpage < 0) currpage = 1;
if (currpage > pagecount) currpage = pagecount;
int nn = currpage * pagesize - pagesize;
List<News> ys = nm.queryXxPage(nn,pagesize);
mv.addObject("xxnews", ys);
//显示分页
StringBuffer s = new StringBuffer();
int ss = 1;
int ee = 7;
if (currpage >= 4) {
ss = currpage - 3;
ee = currpage + 3;
}
s.append("<nav aria-label=\"...\"><ul class=\"pagination\">");
s.append(String.format("<li class=\"disabled\"><a href=\"?p=%d\" aria-label=\"Previous\"><span aria-hidden=\"true\">首页</span></a></li>", 1));
if (currpage == 1) {
s.append("<li class=\"disabled\"><a href=\"\" aria-label=\"Previous\">«上一页</a></li>");
} else {
s.append(String.format("<li class=\"disabled\"><a href=\"?p=%d\" aria-label=\"Previous\"><span aria-hidden=\"true\">«上一页</span></a></li>", currpage - 1));
}
for (int i = ss; i <= ee; i++) {
if (i > pagecount) {
break;
}
if (i == currpage) {
s.append(String.format("<li class=\"active\"><a href=\"?p=%d\">%d<span class=\"sr-only\">(current)</span></a></li>", i, i));
} else {
s.append(String.format("<li><a href=\"?p=%d\">%d</a></li>", i, i));
}
}
if (currpage == pagecount) {
s.append("<li class=\"disabled\"><a href=\"\" aria-label=\"Previous\">»下一页</a></li>");
} else {
s.append(String.format("<li class=\"disabled\"><a href=\"?p=%d\" aria-label=\"Previous\"><span aria-hidden=\"true\">»下一页</span></a></li>", currpage + 1));
}
s.append(String.format("<li class=\"disabled\"><a href=\"?p=%d\" aria-label=\"Previous\"><span aria-hidden=\"true\">尾页</span></a></li>", pagecount));
s.append(" </ul></nav>");
mv.addObject("fenye", s);
//行业新闻分页
int recordcount1 =nm.queryHyCount();
//一共多少页
int pagecount1 = recordcount1 % pagesize == 0 ? recordcount1 / pagesize : recordcount1 / pagesize + 1;
if (currpage < 0) currpage = 1;
if (currpage > pagecount1) currpage = pagecount1;
int nnn = currpage * pagesize - pagesize;
List<News> yss = nm.queryXxPage(nnn,pagesize);
mv.addObject("hynews", yss);
//显示分页
StringBuffer s1 = new StringBuffer();
if (currpage >= 4) {
ss = currpage - 3;
ee = currpage + 3;
}
s1.append("<nav aria-label=\"...\"><ul class=\"pagination\">");
s1.append(String.format("<li class=\"disabled\"><a href=\"?p=%d\" aria-label=\"Previous\"><span aria-hidden=\"true\">首页</span></a></li>", 1));
if (currpage == 1) {
s1.append("<li class=\"disabled\"><a href=\"\" aria-label=\"Previo
评论2
最新资源