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

做汽车团购网站有哪些阜宁企业做网站多少钱

做汽车团购网站有哪些,阜宁企业做网站多少钱,邯郸网络企业版,属于什么的网页制作工具文章目录一、创建SpringBoot项目二、添加Mybatis相关依赖三、数据源配置四、创建事务的模型实体类五、创建和数据库交互联系的映射关系类六、创建业务接口和实现类七、创建控制器类八、请求验证一、创建SpringBoot项目 如何创建详见#xff1a;IDEA 创建 SpringBoot 项目 二、… 文章目录一、创建SpringBoot项目二、添加Mybatis相关依赖三、数据源配置四、创建事务的模型实体类五、创建和数据库交互联系的映射关系类六、创建业务接口和实现类七、创建控制器类八、请求验证一、创建SpringBoot项目 如何创建详见IDEA 创建 SpringBoot 项目 二、添加Mybatis相关依赖 以前开发Web项目我们都知道要想把数据添加到数据库不仅必须要数据库的驱动程序还要有各种各样的配置文件像java Bean配置数据源配置对象和数据库字段的映射配置等等。使用SpringBoot开发我们只需要加入依赖文件就可以了SpringBoot已经都帮我配置好了。配置如下图所示 dependencygroupIdmysql/groupIdartifactIdmysql-connector-java/artifactIdscoperuntime/scope /dependencydependencygroupIdorg.mybatis.spring.boot/groupIdartifactIdmybatis-spring-boot-starter/artifactIdversion2.2.1/version /dependency三、数据源配置 在application.properties中配置数据库连接的相关信息 spring.datasource.driver-class-namecom.mysql.jdbc.Driver spring.datasource.urljdbc:mysql://127.0.0.1:18103/db_test?characterEncodingGBK spring.datasource.usernameroot spring.datasource.passwordroot四、创建事务的模型实体类 编程是利用面向对象的思想把自然界中的事物抽象成模型利用模型来解决实际中的问题。如下图 package com.springboottest.bean;public class StudentBean {private int id;private String name;public StudentBean() {}public int getId() {return id;}public void setId(int id) {this.id id;}public String getName() {return name;}public void setName(String name) {this.name name;} }注这里的字段名称与数据库表字段名称一致。 五、创建和数据库交互联系的映射关系类 这个类主要是和数据进行交互联系的需要配置好实体类和数据库字段的映射关系。由于SpringBoot已经做了大量的工作我们只需要做好相关注解就可以使用了。如下图所示 package com.springboottest.sql.mapper; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Select;Mapper public interface StudentMapper {Select(select * from tb_student where name#{name})StudentBean getStudentInfoByName(String name); }Mapper 表明该类是一个Mapper接口使用Select、Insert等注解我们可以直接在类中书写sql语句来实现我们的目的。 六、创建业务接口和实现类 我们在接口类里定义要实现的业务功能接口在它的实现类里实现接口。接口类如下图 package com.springboottest.sql.service;import com.springboottest.bean.StudentBean;public interface StudentService {StudentBean getStudentInfoByName(String name); }实现类如下图 package com.springboottest.sql.service;import com.springboottest.bean.StudentBean; import com.springboottest.sql.mapper.StudentMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional;Service public class StudentServiceImpl implements StudentService{Autowiredprivate StudentMapper studentMapper;OverrideTransactionalpublic StudentBean getStudentInfoByName(String name) {return studentMapper.getStudentInfoByName(name);} }Service注解表明它是一个服务类Bean可以被SpringBoot识别使用相当于以前在xml里配置的bean。 七、创建控制器类 Web项目的请求经过映射找到控制器类里对应的方法然后再实现完业务返回响应信息。如下图 package com.springboottest.controller;import com.springboottest.bean.StudentBean; import com.springboottest.sql.MySQLProcessor; import com.springboottest.sql.service.StudentService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController;RestController RequestMapping(/mysql) public class SqlController {Autowiredprivate StudentService studentService;RequestMapping(value /student)public String studentSelect(RequestParam String name){StudentBean bean studentService.getStudentInfoByName(name);if(bean ! null){return Name bean.getName();} else {return null;}} }八、请求验证 请求地址http://localhost:8991/mysql/student?nametom
http://www.pierceye.com/news/612140/

相关文章:

  • 潍坊网站建设多少钱做网站seo优化
  • 南昌网站建设方案外包怎么自己做网站凑钱
  • 贵州企业展示型网站建设网站建设需要摊销吗
  • 网站建设视频教程广州哪里有正规的技能培训
  • 网站后台iis配置小程序模板消息推送规则
  • 桥梁建设工程网站残疾人网站服务平台
  • 网站开发语言包括哪些潍坊公司注册
  • 平顶山网站制作哪家公司好阿里巴巴网站建设改图片
  • 网站设计培训学校有哪些wordpress主题什么值得买
  • 如皋建设工程局网站静态网站做淘宝客
  • 温州网站建设案例做网站卖衣服物流包年多少钱
  • 响应 网站建设招聘室内设计
  • 网站建设宣传册内容南京个人网站建设
  • 毕业设计可以做哪些网站遵义原创网站
  • 国外服装设计网站app网站建设需要什么
  • 网站建设a云世家宋南南网站建设合集
  • 可以网上做单的网站创建全国文明城市的宗旨是什么
  • 北京诚信建设网站成都蓉城最新消息
  • 上市公司网站建设分析评价网页制作的视频教程
  • 网站营运费网站关键字优化工具
  • 上海企业网站建站中山一站式营销推广平台
  • 想做网站策划怎么做苏州seo关键词排名
  • 中小型企业电子商务网站建设seo优化推广公司
  • 网站开发类型什么意思网页制作与设计千年之恋代码
  • 怎么做公司的网站免费网站建设专业的公司
  • 适合这手机浏览器主页的网站wordpress本地上传服务器
  • 济南百度网站开发寮步镇做网站
  • 营销类型的公司网站专注高密做网站哪家好
  • 公司网站建设找谁做网络渠道
  • 网站建设公司 校园网站html5商城网站