Java后台实现方法
Java后台实现方法
首先后台结构分为四个部分(以表schedule为例)
entity>mapper>service>controller
1. 在entity里面写好实体,新建目录schedule,再建子文件Schedule.java,在里面定义好全部表名的字段
package com.eisp.eoms.entity.schedule;
import java.sql.Timestamp;
//日志信息
public class Schedule {
private Long scheId;
private String schCode;
private String userCode;
private String orgCode;
private String scheduleContent;
private Timestamp startDate;
private Timestamp endDate;
private String comments;
}
2.在mapper里面写好接口
建立schedule目录,再建立ScheduleMapper.java文件
里面写sql语句
/**
* @author Administrator
*
*/
package com.eisp.eoms.mapper.schedule;
import java.util.List;
import com.eisp.eoms.entity.schedule.Schedule;
public interface ScheduleMapper {
List<Schedule>selectByUserCode(String userCode);
List<Schedule>select();
}
//select和selectByUserCode名称不能一样
再建立ScheduleMapper.xml文件,里面写sql语
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.eisp.eoms.mapper.schedule.ScheduleMapper">
<select id="select" resultType="com.eisp.eoms.entity.schedule.Schedule">
select * from EOMS_SCHEDULE
</select>
<select id="selectByUserCode" parameterType="String"
resultType="com.eisp.eoms.entity.schedule.Schedule">
select * from EOMS_SCHEDULE where USERCODE=#{param1}
</select>
</mapper>
//id相应ScheduleMapper.java中的select方法
3.在service层建立schedule目录。再建立ScheduleService.java文件,里面写的语句例如以下
package com.eisp.eoms.service.schedule;
import java.util.List;
import com.eisp.eoms.entity.schedule.Schedule;
public interface ScheduleService {
List<Schedule> selectByUserCode(String userCode);
List<Schedule> select();
}
再建立impl文件,里面建立ScheduleServiceImpl.java文件
package com.eisp.eoms.service.schedule.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.eisp.eoms.entity.schedule.Schedule;
import com.eisp.eoms.mapper.schedule.ScheduleMapper;
import com.eisp.eoms.service.schedule.ScheduleService;
@Service
public class ScheduleServiceImpl implements ScheduleService {
@Autowired
private ScheduleMapper scheduleMapper;
public List<Schedule> selectByUserCode(String userCode) {
return scheduleMapper.selectByUserCode(userCode);
}
public List<Schedule> select() {
return scheduleMapper.select();
}
}
4.在controller新建schedule文件件。里面建业务文件SonntagController.java文件用于接收数据
package com.eisp.eoms.controller.schedule;
import java.util.HashMap;
import java.util.Map;
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.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import com.eisp.eoms.service.schedule.ScheduleService;
@Controller
@RequestMapping("/schedule/sonntag")
public class SonntagController {
@Autowired
private ScheduleService scheduleService;
@RequestMapping("/showIndex")
public ModelAndView scheduleIndex() {
return new ModelAndView("schedule/index");
}
@RequestMapping("/list")
@ResponseBody
public Map<String, Object> listAll() {
Map<String, Object> data = new HashMap<String, Object>();
data.put("list", scheduleService.select());
data.put("AAA", scheduleService.select());
System.out.println(data);
return data;
}
}
总结,经过以上几个环节。后台数据库表的数据可以成功调取出来。当然假设要载入到页面上。还须要js中用ajax传输
Java后台实现方法的更多相关文章
- java后台获取Access_token的工具方法
本方法主要通过java后台控制来获取Access_token,需要你已经知道自己的ID跟密码 因为微信的权限设置大概每天可以获取两千条,每条有效时间为2小时 /** * 输入自己的id跟密码,获取微信 ...
- java后台list集合传值到前台,再取值的几种方法
1.在jsp页面中嵌套 java代码: 首先jsp页面中导入java的工具类 <%@ page language="java" import="java.util. ...
- ajax提交数据到java后台,并且返回json格式数据前台接收处理值
1.前台html页面.有一段代码如下: 账 户: <input type="text" name="userName" id="userN& ...
- java后台对前端输入的特殊字符进行转义
转自:http://www.cnblogs.com/yangzhilong/p/5667165.html java后台对前端输入的特殊字符进行转义 HTML: 常见的帮助类有2个:一个是spring的 ...
- JSF页面中使用js函数回调后台bean方法并获取返回值的方法
由于primefaces在国内使用的并不是太多,因此,国内对jsf做系统.详细的介绍的资料很少,即使有一些资料,也仅仅是对国外资料的简单翻译或者是仅仅讲表面现象(皮毛而已),它们的语句甚至还是错误的, ...
- java后台异步任务执行器TaskManager
java后台异步任务执行器TaskManager 此方式基于MVC方式: 一,使用任务: @Resource private TaskManager taskManager; public strin ...
- fastJson java后台转换json格式数据
什么事JSON? JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式. 易于人阅读和编写.同时也易于机器解析和生成. 它基于JavaScript Progra ...
- encodeURIComponent编码后java后台的解码 (AJAX中文解决方案)
encodeURIComponent编码后java后台的解码 (AJAX中文解决方案) 同学的毕业设计出现JavaScript用encodeURIComponentt编码后无法再后台解码的问题. 原来 ...
- Java后台工程师面试杂记——不跳不涨工资星人跳槽经历
经过接近一个月的时间,完成换工作这件“小事”,前后总计面试了多家公司,最后也没接到几个offer,不过最终总算尘埃落定,就对这个过程进行一个总结吧. 在某互联网公司工作了近一年的时间,但是频繁的业务需 ...
随机推荐
- 【Tesseract】Tesseract API在VS 2013中的配置以及调用
想要在VS中使用Tesseract库,必须使用经过相对应的VS版本编译过的dll以及lib.比如在VS 2013中,就必须使用在VS 2013中编译过的Tesseract库. 这里我给出经过VS 20 ...
- jQuery+ajax实现局部刷新
在项目中,经常会用到ajax,比如实现局部刷新,比如需要前后端交互等,这里呢分享局部刷新的两种方法,主要用的是ajax里面的.load(),其他高级方法的使用以后再做详细笔记. 第一种: 当某几个页面 ...
- 2017年当下最值得你关注的前端开发框架,不知道你就OUT了!
近几年随着 jQuery.Ext 以及 CSS3 的发展,以 Bootstrap 为代表的前端开发框架如雨后春笋般挤入视野,可谓应接不暇. 在这篇分享中,我将总结2017年当下最值得你关注的前端开发框 ...
- 新的开始,hello world!
开始使用博客一年多来,在各位大神的博客上找了很多学习需要的资料,受益匪浅.一直来自己也想过开始写自己的博客,但是一直没有开始.一来是懒,懒的整理,懒的打字排版,二来是那段时间加入实验室,自我感觉一直有 ...
- [转载] Java实现生产者消费者问题
转载自http://www.cnblogs.com/happyPawpaw/archive/2013/01/18/2865957.html 引言 生产者和消费者问题是线程模型中的经典问题:生产者和消费 ...
- 工作中用到的一些shell命令
1.将十进制转换为十六进制 for i in `seq 0 127`; do printf "%02x\n" $i; done
- Python之函数返回多个值
#!/usr/bin/env python26 #-*- coding:utf-8-*- def test(): a = 10 b = 20 return a,b #返回一个元组 atuple= te ...
- js 图片转换为base64 (2)
<input type="file" id="testUpload"> <img src="" id="img& ...
- ASP.NET Core教程【二】从保存数据看特有属性与服务端验证
前文索引: 在layout.cshtml文件中,我们可以看到如下代码: <a asp-page="/Index" class="navbar-brand" ...
- A:分段函数-poj
A:分段函数 总时间限制: 1000ms 内存限制: 65536kB 描述 编写程序,计算下列分段函数y=f(x)的值. y=-x+2.5; 0 <= x < 5 y=2-1.5(x- ...