当前位置: 首页 > 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.zqtcl.cn/news/692680/

相关文章:

  • 电子商务网站建设与管理第四章答案seo入门培训学校
  • 温州最便宜网站建设有哪些网站可以做推广
  • 郑州网站建设制作公司wordpress播放m3u8
  • wordpress企业站手机客户端wordpress获取主页路径
  • 免费开通的网站外国网站在中国做推广
  • 揭阳公司做网站泰国网站域名
  • 上海网站制作方法北京网站制作设计推广公司
  • 衡水哪有建网站的吗个人简历word模板
  • 网站建设前期开发企业网站开发丨薇
  • 流程图 网站做网站后台数据库建设
  • 免费做英语卷子的网站wordpress去谷歌插件
  • 做网站费用网站极简设计
  • 兰州市建设工程安全质量监督站网站优化公司治理
  • 高质量的合肥网站建设天津百度网站快速优化
  • 千元低价网站建设wordpress修改文章时间
  • 做网站需要几个程序wordpress淘客api
  • 建筑公司网站源码本地建站教程
  • 甘肃省建设厅官方网站信息网腾讯企点qq
  • 搜狗收录网站建个网络平台多少钱
  • 电子商务网站开发目的和意义郑州网站优化的微博_腾讯微博
  • asp.net网站建设项目实战 董义革wordpress伪静态规则访问失败
  • 网站添加锚点网站备案名称更换
  • 手机商城网站如何企业网站建设及运营现状分析
  • 网站建设注意的问题网站模板 知乎
  • 自主设计和创建网站网站建设价格便宜
  • 高手做网站财经资讯网站该怎么做推广
  • 加强农业网站建设青岛全网营销推广
  • 做淘客网站怎么样济南软件公司排名
  • 企业网站优化兴田德润怎么样网站建设建设公司资质要求
  • 如何把网站做跳转浏览器链接地址wordpress 离线更新