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,不过最终总算尘埃落定,就对这个过程进行一个总结吧. 在某互联网公司工作了近一年的时间,但是频繁的业务需 ...
随机推荐
- struts2运行过程(图解)
.................................................................................................... ...
- 《Python数据分析常用手册》一、NumPy和Pandas篇
一.常用链接: 1.Python官网:https://www.python.org/ 2.各种库的whl离线安装包:http://www.lfd.uci.edu/~gohlke/pythonlibs/ ...
- .net中LAMBDA表达式常用写法
这里主要是将数据库中的常用操作用LAMBDA表达式重新表示了下,用法不多,但相对较常用,等有时间了还会扩展,并将查询语句及LINQ到时也一并重新整理下: 1.select语句:books.Select ...
- Python——网络爬虫
此篇文章继续跟着小甲鱼的视频来初学网络爬虫,除了小甲鱼的网站上可下载视频,发现b站上也有全套的视频哦,会比下载来的更方便些. 网络爬虫,又称为网页蜘蛛(WebSpider),非常形象的一个名字.如果你 ...
- 从MVC到Ajax再到前后端分离的思考
前言 一位小妹去面试前端,前端leader问了"什么是ajax?",答:"接收后台的数据,然后然后自己填充和渲染样式":一位小哥去面试后台,技术经理问了&quo ...
- vuejs(2.0)基础笔记
基本结构 <div id="app"> {{ message }} </div> var app = new Vue({ el: '#wrap', data ...
- Error when sending message to topic test with key: null, value: 2 bytes with error: (org.apache.kafka.clients.producer.internals.ErrorLoggingCallback)
windows下使用kafka遇到这个问题: Error when sending message to topic test with key: null, value: 2 bytes with ...
- ptrdiff_t 和 size_t
size_t和ptrdiff_t常常用来指示数组长度. size_t常用于表示数组的大小,可以一般的将他看为 typedef unsigned int size_t,实质是一个无符号整形.包含在头文件 ...
- 查找算法(Java实现)
1.二分查找算法 package other; public class BinarySearch { /* * 循环实现二分查找算法arr 已排好序的数组x 需要查找的数-1 无法查到数据 */ p ...
- SEO是件贼有意思的事情 golang入坑系列
这两天迷上了SEO.真心看不起百度的竞价排名,但作为一个商业网站,赚钱是一件无可厚非的事情.只做活雷锋,没有大金主是做不长的.做完功课后,发现百度和google的SEO策略又不相同,几乎是无法通用.百 ...