1、对每一个表都应该建一个model(javabean,映射数据库实体),当有关联表时需创建关连model类的对象。model类只能比表的数量多不能少;
2、前台传入数据时,可直接传入model类对象,只需传入数据名称和model名称一样即可。
前台:
$.ajax({
url:url,
dataType:'json',
data:{"name":name},
Type:'post',
success : function (data){}
})
后台:
public class Information{
private name;
}
当两者的名字相同时,可直接取值,在Controller层中:
@RequestMapping("url")
public class getInformation(Information information){
}
此时information对象中自动的传入name属性值。
3、创建的model类在对表进行增删改查时必须使用(不然没用)。禁止直接将前台数据不经过Service、dao层以及不被model修饰直接与数据库进行关联。如
<insert id='' paramerType="model">
insert into table values()
</insert>
传入的参数应该使用model类对象。对前台传过来的数据,需要使用set方法注入数据到model类对象后使用(如2中可以不使用set注入)。
@Controller
public class getInformation(HttpServletRequest request){
Information information = new Information;
information.setName(request.getParameter("name"))
}
在dao中以
.select(Statement,information)类似的方式传入数据库
4、增删改查时,xml中的标签名(如)不影响对数据库的操作,最好写成对应操作的名字。
路过留名iung,才刚写博客,求人气。。。