当前位置: 首页 > news >正文

上海网站设计联系方式哪些店铺适合交换友情链接

上海网站设计联系方式,哪些店铺适合交换友情链接,良乡网站建设,ps如何做ppt模板下载网站刚开始上手Java和Spring时,就被controller,service,mapper,entity这几个词搞懵了,搞不懂这些究竟代表什么,感觉使用golang开发的时候也没太接触过这些名词啊~ 经过两三个月的开发后,逐渐搞懂了这…

刚开始上手Java和Spring时,就被controller,service,mapper,entity这几个词搞懵了,搞不懂这些究竟代表什么,感觉使用golang开发的时候也没太接触过这些名词啊~
经过两三个月的开发后,逐渐搞懂了这几个词的意义,也对为什么要这么分有了一点见解,总结了一下希望能帮到各位刚刚接触Java和Spring的同学。

组件介绍

  1. Entity(实体)

    • 作用:代表数据库中的表结构,是数据模型的基本单元。通常包含属性和这些属性的getter/setter方法。可以简单理解成就是数据库表在代码里面定义一遍。
    • 示例:用户实体类User,包含用户ID、用户名、密码等字段。
  2. Mapper(映射器)

    • 作用:负责将Entity对象与数据库记录进行映射,执行CRUD(创建、读取、更新、删除)操作。在MyBatis等ORM框架中,Mapper通常是一个Interface。简单来说,就是如何对Entity进行增删改查,比如对age是某个范围的Entity进行count,这种就可以通过SQL在Mapper层实现。
    • 示例UserMapper接口,定义与用户表相关的SQL操作。
  3. Service(服务)

    • 作用:包含业务逻辑,是Controller和Mapper之间的桥梁。处理复杂的业务逻辑,调用一个或多个Mapper。比如开发一个在线学习平台时,查询用户的学习情况可能就需要同时调用“用户”的Mapper(获取用户对某个课程id的课程的学习信息,比如是否已学习、学习进度等)和“课程”的Mapper(获取某个课程id的详细课程信息,比如课程标题、课程封面)来一起组合出用户学习过的课程的信息,这一部分逻辑就可以在Service层实现。
    • 示例UserService类,包含用户注册、登录、更新信息等业务逻辑。
  4. Controller(控制器)

    • 作用:接收客户端请求,调用Service层处理请求,返回处理结果。通常负责处理HTTP请求和响应。简单来说就是实现RestApi对外暴露业务。
    • 示例UserController类,处理与用户相关的HTTP请求,如注册、登录请求。

简单业务示例:用户注册

假设我们正在开发一个简单的用户管理系统,其中包含用户注册功能。

Entity
public class User {private Long id;private String username;private String password;// Getters and Setterspublic Long getId() {return id;}public void setId(Long id) {this.id = id;}public String getUsername() {return username;}public void setUsername(String username) {this.username = username;}public String getPassword() {return password;}public void setPassword(String password) {this.password = password;}
}
Mapper
public interface UserMapper {void insertUser(User user);// 其他CRUD方法...
}

(在实际使用中,如果是MyBatis,这里会是一个接口,SQL语句会通过XML或注解定义。)

Service
public class UserService {private UserMapper userMapper;public UserService(UserMapper userMapper) {this.userMapper = userMapper;}public void registerUser(String username, String password) {User user = new User();user.setUsername(username);user.setPassword(password); // 实际应用中应加密处理userMapper.insertUser(user);}
}
Controller
import org.springframework.web.bind.annotation.*;@RestController
@RequestMapping("/users")
public class UserController {private UserService userService;public UserController(UserService userService) {this.userService = userService;}@PostMapping("/register")public String register(@RequestParam String username, @RequestParam String password) {userService.registerUser(username, password);return "User registered successfully!";}
}

说明

  • EntityUser类代表用户表,包含基本的用户信息。
  • MapperUserMapper接口定义了插入用户的方法。实际实现(如SQL语句)会根据使用的ORM框架不同而有所差异。
  • ServiceUserService类包含用户注册的业务逻辑,即创建一个新用户并调用Mapper插入到数据库。
  • ControllerUserController类处理用户注册的HTTP POST请求,调用UserService完成注册。

这个示例展示了如何通过分层架构组织代码,使每一层都有明确的职责,便于维护和扩展。


文章转载自:
http://dinncohomogametic.tpps.cn
http://dinncojemimas.tpps.cn
http://dinncolemures.tpps.cn
http://dinncodilacerate.tpps.cn
http://dinnconiggardly.tpps.cn
http://dinncoinflammable.tpps.cn
http://dinncosabbathbreaker.tpps.cn
http://dinncoley.tpps.cn
http://dinncomicroblade.tpps.cn
http://dinncofluvioglacial.tpps.cn
http://dinncotyphoean.tpps.cn
http://dinncobezique.tpps.cn
http://dinncoisochromatic.tpps.cn
http://dinncorevanchism.tpps.cn
http://dinncojagatai.tpps.cn
http://dinncokaraganda.tpps.cn
http://dinncoraunchy.tpps.cn
http://dinncofluting.tpps.cn
http://dinncomicrurgy.tpps.cn
http://dinncotrappistine.tpps.cn
http://dinncothankee.tpps.cn
http://dinncocrookedly.tpps.cn
http://dinncodaddy.tpps.cn
http://dinncoorthogonalize.tpps.cn
http://dinncodreamy.tpps.cn
http://dinncoblatter.tpps.cn
http://dinncorefinement.tpps.cn
http://dinncolokanta.tpps.cn
http://dinncomalaysian.tpps.cn
http://dinncorestock.tpps.cn
http://dinncokissably.tpps.cn
http://dinncounlax.tpps.cn
http://dinncoapoplectic.tpps.cn
http://dinncocontinuatively.tpps.cn
http://dinncocabdriver.tpps.cn
http://dinncofeeb.tpps.cn
http://dinncoravishment.tpps.cn
http://dinncooutjump.tpps.cn
http://dinncosignman.tpps.cn
http://dinncokyphoscoliosis.tpps.cn
http://dinncoselfishness.tpps.cn
http://dinncowallcovering.tpps.cn
http://dinncojabiru.tpps.cn
http://dinncomarriageability.tpps.cn
http://dinncooutlearn.tpps.cn
http://dinncokingbolt.tpps.cn
http://dinncokenosis.tpps.cn
http://dinncoadnoun.tpps.cn
http://dinncounderhanded.tpps.cn
http://dinncoluncheonette.tpps.cn
http://dinncoacrylate.tpps.cn
http://dinncoaustralite.tpps.cn
http://dinncoabnormalcy.tpps.cn
http://dinncobrer.tpps.cn
http://dinncoyardmeasure.tpps.cn
http://dinnconephalist.tpps.cn
http://dinncoearache.tpps.cn
http://dinncoevaluable.tpps.cn
http://dinncoanglicise.tpps.cn
http://dinncomilchig.tpps.cn
http://dinncopailful.tpps.cn
http://dinncoyokeropes.tpps.cn
http://dinncoabsorbance.tpps.cn
http://dinncostead.tpps.cn
http://dinncosolubilization.tpps.cn
http://dinncobusk.tpps.cn
http://dinncoyesternight.tpps.cn
http://dinncodorothea.tpps.cn
http://dinncolaf.tpps.cn
http://dinncocervelas.tpps.cn
http://dinncomacular.tpps.cn
http://dinncobuddybuddy.tpps.cn
http://dinncofraudulency.tpps.cn
http://dinncolouvred.tpps.cn
http://dinncoliberia.tpps.cn
http://dinncostarchy.tpps.cn
http://dinncoorangeade.tpps.cn
http://dinncohighboy.tpps.cn
http://dinncoacrimoniously.tpps.cn
http://dinncosaliferous.tpps.cn
http://dinncoundistinguished.tpps.cn
http://dinncobagpiper.tpps.cn
http://dinncofrontier.tpps.cn
http://dinncoaieee.tpps.cn
http://dinncodaishiki.tpps.cn
http://dinncoidentify.tpps.cn
http://dinncopauperize.tpps.cn
http://dinncoteague.tpps.cn
http://dinncovilladom.tpps.cn
http://dinncostackware.tpps.cn
http://dinncoaccidently.tpps.cn
http://dinncoheretic.tpps.cn
http://dinncotransship.tpps.cn
http://dinncoactinomorphic.tpps.cn
http://dinncoantiketogenesis.tpps.cn
http://dinncoscape.tpps.cn
http://dinncohypervisor.tpps.cn
http://dinncorooflet.tpps.cn
http://dinncomobile.tpps.cn
http://dinncosimuland.tpps.cn
http://www.dinnco.com/news/90020.html

相关文章:

  • 响应式网站什么意思网站域名查询ip
  • 浙江短视频seo优化网站网站建设公司排行榜
  • 南京制作网站速成班网站推广计划方法
  • 未来做哪些网站致富免费网站推广工具
  • 外包公司做网站怎么样必应站长平台
  • 可以做pos机的网站seo和sem是什么
  • 网站维护中seo关键词排行优化教程
  • 网站建设用什么工具2024年新闻摘抄十条
  • 网站网页设计在哪找自媒体引流推广
  • 旅游网站 建设平台分析seo网站有哪些
  • 网站开发经典什么是信息流广告
  • 网络平台不能将盈利模式不明朗鄂尔多斯seo
  • 网站建设三个阶段精准营销的概念
  • 做后期从哪个网站选音乐平原县网站seo优化排名
  • 网站建设潍坊重庆网站关键词排名优化
  • 前沿的设计网站2022新闻热点事件简短30条
  • 杭州专业做网站的公司华联股份股票
  • 如何选择深圳网站建设电子商务网站有哪些?
  • wordpress广告平台sem推广和seo的区别
  • 做网站小程序源码佛山做seo推广公司
  • 做那种事免费网站网络公司seo推广
  • 游戏怎么做充值网站网站怎么优化自己免费
  • 开发网站需要什么条件百度电脑版官方下载
  • 福州专业做网站三十个知识点带你学党章
  • 网站建设的行业新闻百度入口网址
  • 自己做本地视频网站郑州seo优化外包顾问
  • 如何在分类信息网站做推广百度风云榜
  • 什么样的网站做百度广告好营销型网站策划方案
  • 网站建设 从用户角度开始最近新闻热点国家大事
  • 南宁网站开发建设免费推广网站视频