Entity
一般先写操作数据库数据的entity实体文件 private的各个参数必须与数据库里的各个字段名称与类型一致,不能有缺漏  varchar和text都存成string,如果有日期可以存成date格式
package cn.zxwl.entity;
public class hqreaction {
private int id;
private String Define_ID;
private String Unsingle_ID;
private String Single_ID;
private String EC_Number;
private String Recommended_Name;
private String Reactant_ID;
private String Product_ID;
private String Reactant;
private String Product;
private String Reaction_ID_SABIO_RK;
private String Reaction_ID_KEGG;
private String Reaction_ID_BRENDA;
private String Reaction_ID_MetaCyc;
}
把数据库字段存入定义好的本地变量需要加上getter,setter方法以操作数据库 空白处右击generate  getter and setter 
shift选择所有变量添加getset方法
在DAO文件里定义数据库接口方法
DAO里可以定义操作所有数据库的方法 
DAO接口的实现–xml文件
xml建立各个dao方法实际操作数据库的sql语句,之后此数据库方法返回数据库各个字段一个字典集合  实际上是可以在
service层
服务层调用dao方法操作数据库,比如刚刚使用了like的sql语句,所以调用方法时传入的参数里需要给搜索的关键字加上%%进行模糊查询,此时重新封装以供controller调用的方法里也可以对从数据库得到的数据进行进一步的处理 
controller
提供URL访问接口,把获取到的数据变成字符串输出,嵌套多个service方法等
@ResponseBody
@RequestMapping(value = "hqReaction.do", method = RequestMethod.GET, produces = "text/html; charset=UTF-8")
public String getCompound(String needinfo){
JSONObject object = new JSONObject();
List<hqreaction> list = new ArrayList<hqreaction>();
object.put("admin",hqService.getreaction(needinfo));
return object.toJSONString();
}
|