java web项目的dao,service层
PHPz
PHPz 2017-04-18 10:23:13
0
1
298

又来做伸手党问问题了,感到很羞愧,所以问之前还是先谢谢愿意回答的各位朋友~
有2个问题,也是java web初级问题,但看了不少资料还是有点模糊,毕竟不知道自己理解的对不对。

1是如题所属的dao层和service层设计。
不少问题回答都说dao层只要负责和数据库打交道,简单点甚至可以理解成一个dao对应一个表,然后增删查改,写完SQL隔离开。而对于多张表的复杂操作则通过service调用dao层实现,不要涉及SQL的操作?
但实际写项目时候碰到一个问题:
我在写登录页面和搜索用户的时候,将登陆信息封装成一个简化版user类,但涉及空字符串和null的问题需要做些判断,所以我是不是应该service层做判断然后传参入dao对象然后返回结果这样么?

2是目录,怎么感觉看得不少教程目录都有不同的偏好啊,用maven创建不好么?这是现在的目录,请指教可取么Orz,谢谢!!

PHPz
PHPz

学习是最好的投资!

reply all(1)
Peter_Zhu

When I wrote the login page and searched for users, I encapsulated the login information into a simplified version of the user class, but issues involving empty strings and nulls require some judgment, so should I make a judgment at the service layer and then pass in the parameters? dao object and then return the result like this?

What you do is correct. Business operations are placed in service, and there are just some simple ones in the dao layer CURD操作.

Second point, I think your directory result is very good, there is no problem. Anyway, I am using the directory structure generated by Maven by default.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!