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

网站建设入门 下载wordpress+贴吧主题

网站建设入门 下载,wordpress+贴吧主题,东营市住宅与房地产信息网,品牌推广论文概念 当我们使用传统的jdbc进行数据库与程序的连接时#xff0c;每一个操作都需要写一条sql语句#xff0c;并且没法调试和修改 jdbc连接数据库流程#xff1a; 创建数据库连接池DataSource获取数据库连接Connection执行带占位符的sql语句通过Connection创建操作对象Stat…概念 当我们使用传统的jdbc进行数据库与程序的连接时每一个操作都需要写一条sql语句并且没法调试和修改 jdbc连接数据库流程 创建数据库连接池DataSource获取数据库连接Connection执行带占位符的sql语句通过Connection创建操作对象Statement指定替换占位符的字段类型值使用Statement执行sql语句返回结果或更新的数量处理返回的结果释放资源 而MyBatis则是一个持久层框架可以使用xml或者注解来方便的进行数据库的操作 创建MyBatis项目 创建spring项目时勾选上面五个依赖 如果使用的是oracle数据库那么将MySQL Driver替换成Oracle Driver 在配置文件中配置数据库的连接信息 spring.datasource.urljdbc:mysql://127.0.0.1:3306/database?characterEncodingutf-8 spring.datasource.usernameroot spring.datasource.password密码 spring.datasource.driver-class-namecom.mysql.cj.jdbc.DriverMyBatise是一个ORM框架会将查询到的数据与java中的类进行互相转化 配置MyBatis中的XML路径 MyBatis中使用XML来保存数据库的sql语句因此在配置文件中还要加上下面这条语句 mybatis.mapper-locationsclasspath:包名/*Mapper.xml例如 mybatis.mapper-locationsclasspath:mybatis/*Mapper.xml业务代码 创建用户信息类 package com.example.demo.entity; import lombok.Data; import java.time.LocalDateTime;Data public class UserInfo {private int id;private String username;private String password;private String photo;private LocalDateTime createTime;private LocalDateTime updateTime;private int state; }创建Mapper接口 package com.example.demo.mapper;import org.apache.ibatis.annotations.Mapper; import com.example.demo.entity.UserInfo; import org.apache.ibatis.annotations.Param;Mapper public interface UserMapper {UserInfo getUserById(Param(user_id) Integer id); }添加UserMapper.xml ?xml version1.0 encodingUTF-8? !DOCTYPE mapper PUBLIC -//mybatis.org//DTD Mapper 3.0//EN http://mybati s.org/dtd/mybatis-3-mapper.dtd mapper namespacecom.example.demo.mapper.UserMapperselect idgetUserById resultTypecom.example.demo.entity.UserInfoselect * from userinfo where id${user_id}/select /mapper创建UserService 使用属性注入获取UserMapper对象调用其getUserById方法 package com.example.demo.service;import com.example.demo.entity.UserInfo; import com.example.demo.mapper.UserMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service;Service public class UserService {Autowiredprivate UserMapper userMapper;public UserInfo getUserById(Integer id){return userMapper.getUserById(id);} } 创建UserController 使用属性注入获取到UserService对象然后调用其getUserById方法 package com.example.demo.controller; import com.example.demo.entity.UserInfo; import com.example.demo.service.UserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController;RestController RequestMapping(/user) public class UserController {Autowiredpublic UserService userService;RequestMapping(/get-user-by-id)public UserInfo getUserById(Integer id){if(id null){return null;}return userService.getUserById(id);} } 最终就可以在浏览器中获取到数据库中的数据了
http://www.w-s-a.com/news/363276/

相关文章:

  • 做暧暧小视频有声音的网站太原网页搜索排名提升
  • 公众号链接的手机网站怎么做动易2006学校网站
  • 网站网上推广网站推他网站
  • 如何进行网站建设分析济宁做企业网站
  • 长沙网站seo技巧wordpress插件头像
  • appserv做网站教程微信信息流广告案例
  • 前端网站开发兼职长春火车站地下停车场收费标准
  • 苏州推广网站建设概况大连公交app
  • 移动互联网站开发与维护招聘网站建设计入什么费用
  • 郑州营销型网站建设erp系统有什么用
  • 公司网站开发费怎么入账投放广告网站
  • 企业网站开发文献综述加盟网网站建设策划书
  • 最便宜的网站空间网站建设和app开发
  • 承装承修承试材料在哪个网站做如何用虚拟主机建设网站
  • 如何建一个外贸网站网页设计零基础学习课程
  • 营销型外贸网站广州昆明建设网站制作
  • 网页制作网站素材项目建设全过程管理
  • 正能量网站下载柬埔寨网赌网站开发
  • 如何免费建设公司网站广州传业建设有限公司网站
  • 织梦做的网站快照被攻击张家口网站建设公司
  • 平顶山公司网站建设南昌网站seo多少钱
  • 网站开发要先买服务器吗建设婚恋网站用什么搭建
  • 我想自己在网站上发文章 怎样做wordpress站点安装
  • 北京模板网站开发全包昆明网站开发正规培训
  • 西咸新区建设环保网站谷歌风格wordpress
  • 嘉兴港区建设局网站2018年网站开发
  • 网站里图片做超链接专业开发网站报价单
  • server2003网站建设做销售记住这十句口诀
  • microsoft免费网站网站后台登陆路径
  • 贵州住房和城乡建设局网站做网站排名费用多少钱