dongou4052 2015-04-14 05:30
浏览 203

我的SQL代码在MVC中应该放在哪里

I'm just starting to learn the MVC design pattern, and I was wondering where should my SQL code go.

For example, lets say I have a register form structure that looks like this

type Form struct {
 Username string
 Password string
}

I assume that the form structure is part of the model, so I have some function that goes with the form that after a user submits the form, the data gets put into the database, so my function would look something like this

func (f *Form) registerUser() {
   // SQL code goes here
}

Is this the best way of doing it? I have been searching around for open source Golang web apps that utilizes the MVC pattern, but I have not be able to find one which I completely understand.

  • 写回答

2条回答 默认 最新

  • douyu3145 2015-04-14 05:43
    关注

    In model-view-controller pattern...

    Model is for entities all your classes represent real world objects.

    View is the forms and all the graphic things user can see and interact with.

    Controller is for controller classes, is all the logic of the program, for the sql code as you said you can implement a dao pattern and have all the sql code in the controller package and the database class in the entities package(i leave it in the Controller class).

    评论

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题