基于javaweb+mysql的ssm+maven问卷调查系统(java+ssm+layui+jsp+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SSM+Maven问卷调查系统(java+ssm+layui+jsp+mysql)
项目介绍
这是一个基于SpringMVC+Spring+MyBatis的SSM问卷调查系统。 管理端权限 管理员信息CURD 制作调查问卷 发布调查问卷 统计调查结果 统计报表展示 用户端权限 填写问卷
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。 2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA; 3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可 4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS; 5.是否Maven项目: 是;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目 6.数据库:MySql 5.7等版本均可;
技术栈
- 后端:Spring Springmvc Mybatis 2. 前端:JSP+css+javascript+jQuery+layui
使用说明
- 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2.使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven; 若为maven项目,导入成功后请执行maven clean;maven install命令,配置tomcat, 3. 将项目中db.properties配置文件中的数据库配置改为自己的配置,然后运行; 4.运行项目,在浏览器中输入http://localhost:8080/survey 管理员用户名密码:admin/123456
@Controller
public class DynamicController {
@Autowired
private SurveyService surveyService;
@Autowired
private QuestionService questionService;
@GetMapping("/dy/{uuid}")
public String preview(@PathVariable("uuid") String uuid, ModelMap modelMap){
Survey param = new Survey();
param.setState(Survey.state_exec);
List<Survey> list = surveyService.queryAll(param);
Survey entity = null;
for (Survey survey : list) {
if(survey.getUrl() !=null && survey.getUrl().contains(uuid)){
entity = survey;
}
}
if(entity == null){
modelMap.addAttribute("msg","你要访问的问卷已过期或不存在");
return "error";
}else{
Question question = new Question();
question.setSurveyId(entity.getId());
//查询一个问卷中的所有问题及选项
List<Question> questions = questionService.query(question);
//将问题设置为survey的属性
entity.setQuestions(questions);
modelMap.addAttribute("survey",entity);
return "survey/exec";
}
public String object2String(Object object){
if(object !=null){
return object+"";
}else{
return null;
}
}
public Integer object2Integer(Object object){
if(object !=null){
return Integer.parseInt(object+"");
}else{
return null;
}
}
}
@Controller
@RequestMapping("/question")
public class QuestionController {
@Autowired
private QuestionService questionService;
@PostMapping("/create")
@ResponseBody
public Map<String,Object> create(@RequestBody Question question){
int result = questionService.create(question);
if(result<=0){
//失败的情况下
return MapControl.getInstance().error().getMap();
@Controller
@RequestMapping("/survey")
public class SurveyController {
@Autowired
private SurveyService surveyService;
@Autowired
private QuestionService questionService;
@GetMapping("/create")
public String v_create(){
return "survey/add";
}
@PostMapping("/create")
@ResponseBody
public Map<String,Object> create(@RequestBody Survey survey, HttpServletRequest request){
Admin currAdmin = SessionUtils.getAdmin(request);
survey.setCreator(currAdmin.getId());
survey.setState(Survey.state_create);
survey.setAnon(survey.getAnon()!=null?0:1);
int result = surveyService.create(survey);
if(result<=0){
//失败的情况下
return MapControl.getInstance().error().getMap();
}
return MapControl.getInstance().success().getMap();
}
@PostMapping("/delete")
@ResponseBody
public Map<String,Object> delete(String ids){
int result = surveyService.deleteBatch(ids);
if(result<=0){
//失败的情况下
return MapControl.getInstance().error().getMap();
}
return MapControl.getInstance().success().getMap();
@Controller
public class DynamicController {
@Autowired
private SurveyService surveyService;
@Autowired
private QuestionService questionService;
@GetMapping("/dy/{uuid}")
public String preview(@PathVariable("uuid") String uuid, ModelMap modelMap){
Survey param = new Survey();
param.setState(Survey.state_exec);
List<Survey> list = surveyService.queryAll(param);
Survey entity = null;
for (Survey survey : list) {
if(survey.getUrl() !=null && survey.getUrl().contains(uuid)){
entity = survey;
}
}
if(entity == null){
modelMap.addAttribute("msg","你要访问的问卷已过期或不存在");
return "error";
}else{
Question question = new Question();
question.setSurveyId(entity.getId());
//查询一个问卷中的所有问题及选项
List<Question> questions = questionService.query(question);
//将问题设置为survey的属性
entity.setQuestions(questions);
modelMap.addAttribute("survey",entity);
return "survey/exec";
}
modelMap.addAttribute("msg","你要访问的问卷已过期或不存在");
return "error";
}else{
Question question = new Question();
question.setSurveyId(entity.getId());
//查询一个问卷中的所有问题及选项
List<Question> questions = questionService.query(question);
//将问题设置为survey的属性
entity.setQuestions(questions);
modelMap.addAttribute("survey",entity);
return "survey/exec";
}
}
@GetMapping("/dy/success")
public String success(){
return "survey/success";
}
}
@Controller
public class IndexController {
@Value("classpath:init.json")
int result = surveyService.deleteBatch(ids);
if(result<=0){
//失败的情况下
return MapControl.getInstance().error().getMap();
}
return MapControl.getInstance().success().getMap();
}
@PostMapping("/update")
@ResponseBody
public Map<String, Object> update(@RequestBody Survey survey){
survey.setAnon(survey.getAnon()!=null?0:1);
int result = surveyService.update(survey);
if(result<=0){
//失败的情况下
return MapControl.getInstance().error().getMap();
}
return MapControl.getInstance().success().getMap();
}
@GetMapping("/list")
public String list(){
return "survey/list";
}
@PostMapping("/query")
@ResponseBody
public Map<String,Object> query(@RequestBody Survey survey, ModelMap modelMap){
List<Survey> list = surveyService.query(survey);
//创建者信息写入survey对象
for (Survey entity : list) {
entity.setAdmin(SystemInit.adminMap.get(entity.getCreator()));
}
Integer count = surveyService.count(survey);
return MapControl.getInstance().page(list,count).getMap();
}
@GetMapping("/detail")
public String detail(Integer id,ModelMap modelMap){
Survey survey = surveyService.detail(id);
modelMap.addAttribute("survey",survey);
return "survey/update";
try {
multipartFile.transferTo(new File(path, saveName));
Survey survey = new Survey();
survey.setId(id);
survey.setBgimg(saveName);
surveyService.update(survey);
} catch (IOException e) {
e.printStackTrace();
}
return "redirect:preview/"+id;
}
@PostMapping("/publish")
@ResponseBody
public Map<String,Object> publish(Integer id,HttpServletRequest request){
Survey param = surveyService.detail(id);
if(!Survey.state_exec.equals(param.getState())){
return MapControl.getInstance().error("操作失败,当前问卷未在执行中!").getMap();
}
String uuid = "/dy/"+UUID.randomUUID().toString();
Survey survey = new Survey();
survey.setId(id);
//http://localhost:8080/survey/ieieas-asdf-asdf-3-asd-f-asdf
String url = "http://"+request.getServerName()+ ":" + request.getServerPort() + request.getContextPath()+uuid;
survey.setUrl(url);
surveyService.update(survey);
return MapControl.getInstance().success().getMap();
}
@PostMapping("/submit")
@ResponseBody
public Map<String,Object> submit(@RequestBody List<Map<String,Object>> list){
List<AnswerOpt> optList = new ArrayList();
List<AnswerTxt> txtList = new ArrayList();
String uuid = UUID.randomUUID().toString();
for (Map<String, Object> stringObjectMap : list) {
if(object2String(stringObjectMap.get("type")).equals("1") || object2String(stringObjectMap.get("type")).equals("2")){
List<Object> opts = (List<Object>) stringObjectMap.get("opts");
for (Object opt : opts) {
return "info";
}
@GetMapping("/menu")
@ResponseBody
public void menu(HttpServletResponse response) {
try {
File file = resource.getFile();
FileReader fileReader = new FileReader(file);
BufferedReader bufferedReader = new BufferedReader(fileReader);
String str;
StringBuffer sb = new StringBuffer();
while ((str = bufferedReader.readLine()) !=null){
sb.append(str);
}
bufferedReader.close();
fileReader.close();
response.setContentType("application/json;charset=utf-8");
response.getWriter().print(sb.toString());
} catch (IOException e) {
e.printStackTrace();
}
}
}
public class SessionInterceptor implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
Admin admin = SessionUtils.getAdmin(request);
@Controller
@RequestMapping("/survey")
public class SurveyController {
@Autowired
private SurveyService surveyService;
@Autowired
private QuestionService questionService;
@GetMapping("/create")
public String v_create(){
return "survey/add";
}
@PostMapping("/create")
@ResponseBody
public Map<String,Object> create(@RequestBody Survey survey, HttpServletRequest request){
Admin currAdmin = SessionUtils.getAdmin(request);
survey.setCreator(currAdmin.getId());
survey.setState(Survey.state_create);
survey.setAnon(survey.getAnon()!=null?0:1);
int result = surveyService.create(survey);
if(result<=0){
//失败的情况下
return MapControl.getInstance().error().getMap();
}
public class AdminController {
@Autowired
private AdminService adminService;
@GetMapping("/create")
public String v_create(){
return "admin/add";
}
@PostMapping("/create")
@ResponseBody
public Map<String,Object> create(@RequestBody Admin admin){
admin.setPassword(MD5Utils.getMD5(admin.getPassword()));
int result = adminService.create(admin);
if(result<=0){
//失败的情况下
return MapControl.getInstance().error().getMap();
}
return MapControl.getInstance().success().getMap();
}
@PostMapping("/delete")
@ResponseBody
public Map<String,Object> delete(String ids){
int result = adminService.deleteBatch(ids);
if(result<=0){
//失败的情况下
return MapControl.getInstance().error().getMap();
}
return MapControl.getInstance().success().getMap();
}
@PostMapping("/update")
@ResponseBody
public Map<String, Object> update(@RequestBody Admin admin){
int result = adminService.update(admin);
if(result<=0){
//失败的情况下
return MapControl.getInstance().error().getMap();
}
return MapControl.getInstance().success().getMap();
@Controller
public class LoginController {
@Autowired
private AdminService adminService;
@GetMapping("/login")
public String v_login(){
return "login";
}
@PostMapping("/login")
@ResponseBody
public Map<String, Object> login(@RequestBody Map<String,Object> map, HttpServletRequest request){
String account = map.get("account")+"";
String password = map.get("password")+"";
if(Strings.isNullOrEmpty(account) || Strings.isNullOrEmpty(password)){
return MapControl.getInstance().error("用户名或密码不能为空").getMap();
}
Admin admin = adminService.login(account, MD5Utils.getMD5(password));
if(admin != null){
SessionUtils.setAdmin(request,admin);
return MapControl.getInstance().success().getMap();
}else{
return MapControl.getInstance().error("用户名或密码错误").getMap();
}
}
@GetMapping("/pwd")
public String pwd(){
return "pwd";
}
@PostMapping("/pwd")
@ResponseBody
public Map<String,Object> pwd(Integer id,String type,String sourcePwd,String newPwd){
Admin user = adminService.detail(id);
if(user.getPassword().equals(MD5Utils.getMD5(sourcePwd))){
Admin entity = new Admin();
entity.setId(id);
entity.setPassword(MD5Utils.getMD5(newPwd));
int update = adminService.update(entity);
if(update>0){
return MapControl.getInstance().success().getMap();
}else{
return MapControl.getInstance().error().getMap();
@Controller
public class LoginController {
@Autowired
private AdminService adminService;
@GetMapping("/login")
public String v_login(){
return "login";
}
@PostMapping("/login")
@ResponseBody
public Map<String, Object> login(@RequestBody Map<String,Object> map, HttpServletRequest request){
String account = map.get("account")+"";
String password = map.get("password")+"";
if(Strings.isNullOrEmpty(account) || Strings.isNullOrEmpty(password)){
return MapControl.getInstance().error("用户名或密码不能为空").getMap();
}
Admin admin = adminService.login(account, MD5Utils.getMD5(password));
if(admin != null){
SessionUtils.setAdmin(request,admin);
return MapControl.getInstance().success().getMap();
}else{
return MapControl.getInstance().error("用户名或密码错误").getMap();
}
}
@GetMapping("/pwd")
public String pwd(){
return "pwd";
}
@PostMapping("/pwd")
@ResponseBody
public Map<String,Object> pwd(Integer id,String type,String sourcePwd,String newPwd){
@PostMapping("/query")
@ResponseBody
public Map<String,Object> query(@RequestBody Admin admin, ModelMap modelMap){
System.out.println(admin.getPage());
System.out.println(admin.getLimit());
System.out.println(admin.getAccount());
List<Admin> list = adminService.query(admin);
Integer count = adminService.count(admin);
return MapControl.getInstance().page(list,count).getMap();
}
@GetMapping("/detail")
public String detail(Integer id,ModelMap modelMap){
Admin admin = adminService.detail(id);
modelMap.addAttribute("admin",admin);
return "admin/update";
}
}
@ResponseBody
public Map<String,Object> create(@RequestBody Admin admin){
admin.setPassword(MD5Utils.getMD5(admin.getPassword()));
int result = adminService.create(admin);
if(result<=0){
//失败的情况下
return MapControl.getInstance().error().getMap();
}
return MapControl.getInstance().success().getMap();
}
@PostMapping("/delete")
@ResponseBody
public Map<String,Object> delete(String ids){
int result = adminService.deleteBatch(ids);
if(result<=0){
//失败的情况下
return MapControl.getInstance().error().getMap();
}
return MapControl.getInstance().success().getMap();
}
@PostMapping("/update")
@ResponseBody
public Map<String, Object> update(@RequestBody Admin admin){
int result = adminService.update(admin);
if(result<=0){
//失败的情况下
return MapControl.getInstance().error().getMap();
}
return MapControl.getInstance().success().getMap();
}
@GetMapping("/list")
public String list(){
return "admin/list";
}
@PostMapping("/query")
@ResponseBody
public Map<String,Object> query(@RequestBody Admin admin, ModelMap modelMap){
System.out.println(admin.getPage());
System.out.println(admin.getLimit());
multipartFile.transferTo(new File(path, saveName));
Survey survey = new Survey();
survey.setId(id);
survey.setBgimg(saveName);
surveyService.update(survey);
} catch (IOException e) {
e.printStackTrace();
}
return "redirect:preview/"+id;
}
@PostMapping("/publish")
@ResponseBody
public Map<String,Object> publish(Integer id,HttpServletRequest request){
Survey param = surveyService.detail(id);
if(!Survey.state_exec.equals(param.getState())){
return MapControl.getInstance().error("操作失败,当前问卷未在执行中!").getMap();
}
String uuid = "/dy/"+UUID.randomUUID().toString();
Survey survey = new Survey();
survey.setId(id);
//http://localhost:8080/survey/ieieas-asdf-asdf-3-asd-f-asdf
String url = "http://"+request.getServerName()+ ":" + request.getServerPort() + request.getContextPath()+uuid;
survey.setUrl(url);
surveyService.update(survey);
return MapControl.getInstance().success().getMap();
}
@PostMapping("/submit")
@ResponseBody
public Map<String,Object> submit(@RequestBody List<Map<String,Object>> list){
List<AnswerOpt> optList = new ArrayList();
List<AnswerTxt> txtList = new ArrayList();
String uuid = UUID.randomUUID().toString();
for (Map<String, Object> stringObjectMap : list) {
if(object2String(stringObjectMap.get("type")).equals("1") || object2String(stringObjectMap.get("type")).equals("2")){
List<Object> opts = (List<Object>) stringObjectMap.get("opts");
for (Object opt : opts) {
AnswerOpt answerOpt = new AnswerOpt();
answerOpt.setQuestionId(object2Integer(stringObjectMap.get("questionId")));
answerOpt.setSurveyId(object2Integer(stringObjectMap.get("surveyId")));
answerOpt.setType(object2String(stringObjectMap.get("type")));
answerOpt.setOptId(object2Integer(opt));
answerOpt.setCreateTime(new Date());
answerOpt.setVoter(uuid);
optList.add(answerOpt);
@Controller
@RequestMapping("/survey")
public class SurveyController {
@Autowired
private SurveyService surveyService;
@Autowired
private QuestionService questionService;
@GetMapping("/create")
public String v_create(){
return "survey/add";
}
@PostMapping("/create")
@ResponseBody
public Map<String,Object> create(@RequestBody Survey survey, HttpServletRequest request){
Admin currAdmin = SessionUtils.getAdmin(request);
survey.setCreator(currAdmin.getId());
survey.setState(Survey.state_create);
survey.setAnon(survey.getAnon()!=null?0:1);
int result = surveyService.create(survey);
if(result<=0){
//失败的情况下
return MapControl.getInstance().error().getMap();
}
return MapControl.getInstance().success().getMap();
}
@PostMapping("/delete")
@ResponseBody
public Map<String,Object> delete(String ids){
int result = surveyService.deleteBatch(ids);
if(result<=0){
//失败的情况下
return MapControl.getInstance().error().getMap();
}
return MapControl.getInstance().success().getMap();
}
@PostMapping("/update")
@ResponseBody
public Map<String, Object> update(@RequestBody Survey survey){
return MapControl.getInstance().error().getMap();
}
return MapControl.getInstance().success().add("id",result).getMap();
}
@PostMapping("/delete")
@ResponseBody
public Map<String,Object> delete(String ids){
int result = questionService.deleteBatch(ids);
if(result<=0){
//失败的情况下
return MapControl.getInstance().error().getMap();
}
return MapControl.getInstance().success().getMap();
}
@PostMapping("/update")
@ResponseBody
public Map<String, Object> update(@RequestBody Question question){
int result = questionService.update(question);
if(result<=0){
//失败的情况下
return MapControl.getInstance().error().getMap();
}
return MapControl.getInstance().success().getMap();
}
@GetMapping("/list")
public String list(){
return "question/list";
}
@PostMapping("/query")
@ResponseBody
public Map<String,Object> query(@RequestBody Question question, ModelMap modelMap){
List<Question> list = questionService.query(question);
Integer count = questionService.count(question);
return MapControl.getInstance().page(list,count).getMap();
}
@GetMapping("/detail")
public String detail(Integer id,ModelMap modelMap){
Question question = questionService.detail(id);
modelMap.addAttribute("question",question);
return "question/update";
}
@GetMapping("/question")
public String question(Integer id,ModelMap modelMap){
Question question = questionService.detail(id);
modelMap.addAttribute("question",question);
return "question/question";
}
}
}
surveyService.submit(optList,txtList);
return MapControl.getInstance().success().getMap();
}
@GetMapping("/query_detail/{id}")
public String query_detail(@PathVariable("id") Integer id,ModelMap modelMap){
Survey survey = surveyService.detail(id);
Question question = new Question();
question.setSurveyId(survey.getId());
//查询一个问卷中的所有问题及选项
List<Question> questions = questionService.query(question);
//将问题设置为survey的属性
survey.setQuestions(questions);
//总投票人数
AnswerOpt answerOpt = new AnswerOpt();
answerOpt.setSurveyId(id);
List<AnswerOpt> answerOpts = surveyService.queryAnswerOpt(answerOpt);
Set<String> set = new HashSet<String>();
for (AnswerOpt opt : answerOpts) {
set.add(opt.getVoter());
}
for (Question question1 : questions) {
for (QuestionOpt questionOpt : question1.getOptions()) {
int num = 0;
for (AnswerOpt opt : answerOpts) {
if(questionOpt.getId().equals(opt.getOptId())){
num++;
}
}
questionOpt.setNum(num);
}
}
modelMap.addAttribute("survey",survey);
modelMap.addAttribute("total",set.size());
return "survey/query_detail";
}
public String object2String(Object object){