java实现后台功能程序_Java后台实现⽅法Java后台实现⽅法
⾸先后台结构分为四个部分(以表schedule为例)
entity>mapper>service>controller
1. 在entity⾥⾯写好实体,新建⽂件夹schedule,再建⼦⽂件Schedule.java,在⾥⾯定义好所有表名的字段
package s.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 s.mapper.schedule;
import java.util.List;
import s.entity.schedule.Schedule;
public interface ScheduleMapper {
ListselectByUserCode(String userCode);
Listselect();
}
//select和selectByUserCode名称不能⼀样
再建⽴l⽂件,⾥⾯写sql语
select * from EOMS_SCHEDULE
resultType="s.entity.schedule.Schedule">
select * from EOMS_SCHEDULE where USERCODE=#{param1}
//id对应ScheduleMapper.java中的select⽅法
3.在service层建⽴schedule⽂件夹,再建⽴ScheduleService.java⽂件,⾥⾯写的语句如下package s.service.schedule;
import java.util.List;
import s.entity.schedule.Schedule;
public interface ScheduleService {
List selectByUserCode(String userCode);
List select();
}
再建⽴impl⽂件,⾥⾯建⽴ScheduleServiceImpl.java⽂件
package s.service.schedule.impl;
import java.util.List;
java调用js的ajax
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import s.entity.schedule.Schedule;
import s.mapper.schedule.ScheduleMapper;
import s.service.schedule.ScheduleService;
@Service
public class ScheduleServiceImpl implements ScheduleService {
@Autowired
private ScheduleMapper scheduleMapper;
public List selectByUserCode(String userCode) {
return scheduleMapper.selectByUserCode(userCode);
}
public List select() {
return scheduleMapper.select();
}
}
4.在controller新建schedule⽂件件,⾥⾯建业务⽂件SonntagController.java⽂件⽤于接收数据package s.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 s.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 listAll() {
Map data = new HashMap();
data.put("list", scheduleService.select());
data.put("AAA", scheduleService.select());
System.out.println(data);
return data;
}
}
总结,经过以上⼏个环节,后台数据库表的数据能够成功调取出来,当然如果要加载到页⾯上,还需要js中⽤ajax传输

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。