基于Java+SpringMVC+MySql+Layui+H5实现企业门户网站

183 阅读2分钟
  • 用户类型:普通用户/管理员
  • 设计模式架构:B/S 架构、MVC
  • 数据库:MySQL5.7/8.0 版本。
  • 运行服务器:tomcat7.0及以上。
  • 是否基于 Maven 环境:是
  • 是否采用框架:是
  • 数据库表数量:10张左右
  • 是否有代码注释:部分
  • 备注:数据库源码齐全,功能正常,保证运行 Q:1378107235,手机/vx:13472732255

主要功能 管理员:管理员登录, 新闻管理,文章和分类管理,文章列表管理,友情链接管理, 项目分类方案管理, 产品管理,留言管理,banner图片管理,联系我们,关于我们,网站管理员管理,等功能。

开发工具 开发工具:idea 开发语言:java、jdk1.8、mysql5、 硬件环境:Mac操作系统、Google浏览器等。 主要技术:HTML、CSS、JavaScript、H5、jsp、mysql、Spring、SpringMVC等

源码获取

截屏2022-02-28 15.13.46.png

截屏2022-03-02 17.49.03.png

部分代码截图

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
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.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.util.Iterator;
import java.util.List;

@Controller
public class AboutusController {
    @Autowired
    AboutusService aboutusService;
    @RequestMapping(value = "/listallabout",method = RequestMethod.POST)
    @ResponseBody
    public void listallabout(HttpServletResponse response){

        List<Aboutus> listall = null;
        listall = aboutusService.findall();

        response.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset = UTF-8");

        JsonArray array = new JsonArray();
        JsonObject objson = new JsonObject();


        if (null !=listall && listall.size()>0){

            Iterator<Aboutus> it = listall.iterator();

            Aboutus aboutus = new Aboutus();
            int n = 0;
            while (it.hasNext()){
                aboutus = (Aboutus) it.next();
                JsonObject ob = new JsonObject();
                ob.addProperty("id",aboutus.getId());
                ob.addProperty("aboutname",aboutus.getAboutname());
                ob.addProperty("aboutcontent",aboutus.getAboutcontent());
                ob.addProperty("aboutimgpath",aboutus.getAboutimgpath());
                ob.addProperty("des",aboutus.getDescription());
                array.add(ob);
                n++;
            }
            objson.addProperty("code", "0");
            objson.addProperty("count", listall.size());
            objson.add("data", array);

            listall.clear();
            PrintWriterJson.writegJsonArray(objson, response);

        }else {
            objson.addProperty("code", "0");
            objson.addProperty("count", "0");
            objson.add("data", array);

            PrintWriterJson.writegJsonArray(objson, response);
        }

    }

    @RequestMapping(value = "/aboutsaveflus",method = RequestMethod.POST)
    @ResponseBody
    public void saveflush(HttpServletResponse response,
                          @RequestParam("id") Integer id,
                          @RequestParam("aboutname") String aboutname,
                          ) throws JsonProcessingException {
        result result = new result();
        ObjectMapper objectMapper = new ObjectMapper();

        Aboutus aboutus = new Aboutus();
        aboutus.setId(id);
        aboutus.setAboutname(aboutname);
        aboutus.setAboutcontent(aboutcontent);
        aboutus.setAboutimgpath(aboutimgpath);
        aboutus.setDescription(des);

        response.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset = UTF-8");
        aboutusService.update(aboutus);
        result.setMsg("更新成功");
        result.setCode("0");

        String json = objectMapper.writeValueAsString(result);
        PrintWriterJson.writeStringjson(json, response);

    }

    @RequestMapping(value = "/saveabout",method = RequestMethod.POST)
    @ResponseBody
    public void save(HttpServletResponse response,
                     @RequestParam("aboutname") String aboutname,                     @RequestParam("des") String des) throws JsonProcessingException {
        result result = new result();
        ObjectMapper objectMapper = new ObjectMapper();
        String reslut1 = aboutusService.findyname(aboutname);

        response.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset = UTF-8");

        if (reslut1.equals("yes")){
            result.setMsg("名称已经存在");
            result.setCode("1");
        }else {
            Aboutus aboutus = new Aboutus();
            aboutus.setAboutname(aboutname);
            aboutus.setAboutcontent(aboutcontent);
            aboutus.setAboutimgpath(aboutimgpath);
            aboutus.setDescription(des);
            aboutusService.save(aboutus);

            result.setMsg("成功");
            result.setCode("0");
        }

        String json = objectMapper.writeValueAsString(result);
        PrintWriterJson.writeStringjson(json, response);

    }

    @RequestMapping(value = "/delabout",method = RequestMethod.POST)
    @ResponseBody
    public void del(HttpServletResponse response,
                    @RequestParam("id") Integer id) throws JsonProcessingException {
        result result = new result();
        ObjectMapper objectMapper = new ObjectMapper();
        response.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset = UTF-8");
        aboutusService.del(id);
        result.setMsg("删除成功");
        result.setCode("0");
        String json = objectMapper.writeValueAsString(result);
        PrintWriterJson.writeStringjson(json, response);
    }
}