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传输

最新文章

  1. Http、Https请求工具类
  2. iOS-网络基础
  3. jquery placeholder
  4. C#函数式编程之可选值
  5. 自己签发免费ssl证书
  6. DIOCP之获取在线用户列表
  7. Struts2 面试题分析
  8. 【BZOJ 1036】【ZJOI 2008】树的统计 树链剖分模板题
  9. Java获取泛型的Class对象
  10. Android写入文件操作权限
  11. iOS开发——发短信,邮件
  12. verilog学习笔记(0)
  13. [问题]Android listView item edittext 不能调用软键盘输入法
  14. 修改Linux用户配置之后先验证再退出
  15. Python 传递任意数量的实参
  16. HDU2844买表——多重背包初探
  17. Find minimum continuous subsequence tags
  18. cuda使用
  19. “私人助手”Beta版使用说明
  20. x01.polls: 学习 django

热门文章

  1. 【IDEA】向IntelliJ IDEA创建的项目导入Jar包的两种方式
  2. 图文详解linux/windows mysql忘记root密码解决方案
  3. 浅谈字体小图标font awesome,iconfont,svg各自优缺点
  4. List实现
  5. 发现大量的TIME_WAIT解决办法 -- 修改内核参数
  6. BootStrap的入门和响应式的使用
  7. IMDB TOP 250爬虫
  8. csv格式订单下载,完成后伴随邮件通知下载
  9. gulp 小坑一个
  10. RAC环境下误操作将数据文件添加到本地存储