基于 Java+SpringMVC+MySql+Layui+H5 实现企业门户网站
作者:andy_zf
- 2022 年 3 月 04 日
本文字数:2960 字
阅读完需:约 10 分钟

用户类型:普通用户/管理员
设计模式架构:B/S 架构、MVC
数据库:MySQL5.7 版本。
运行服务器:tomcat7.0 及以上。
是否基于 Maven 环境:是
是否采用框架:是
是否有后台管理:有
数据库表数量:10 张左右
是否有代码注释:部分
备注:数据库源码齐全,功能正常,保证运行
Q:1378107235,手机/vx:13472732255
主要功能
管理员:管理员登录, 新闻管理,文章和分类管理,文章列表管理,友情链接管理, 项目分类方案管理, 产品管理,留言管理,banner 图片管理,联系我们,关于我们,网站管理员管理,等功能。
开发工具
开发工具:idea
开发语言:java、jdk1.8、mysql5、
硬件环境:Mac 操作系统、Google 浏览器等。
主要技术:HTML、CSS、JavaScript、jsp、mysql、Spring、SpringMVC 等
视频演示
代码
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;
@Controllerpublic 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); }}
复制代码
划线
评论
复制
发布于: 刚刚阅读数: 7
版权声明: 本文为 InfoQ 作者【andy_zf】的原创文章。
原文链接:【http://xie.infoq.cn/article/91a31c6637880bd1d33c20038】。文章转载请联系作者。
andy_zf
关注
还未添加个人签名 2022.02.28 加入
10年+互联网、物联网,7年互联网医疗经验,主持研发和运营项目有涉及物联网,互联网医疗健康,工业互联网,大数据健康诊断分析。











评论