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

廉价网站建设php 同学录在线网站开发

廉价网站建设,php 同学录在线网站开发,中介网站建设,宁波网页设计在宁勤区概述 使用springboot 集成 mybatys后,通过http请求接口,使得通过http请求可以直接直接操作数据库; 完成后端功能框架;前端是准备上小程序,调用https的请求接口用。简单实现后端框架; 详细 springboot 集…

概述

使用springboot 集成 mybatys后,通过http请求接口,使得通过http请求可以直接直接操作数据库; 完成后端功能框架;前端是准备上小程序,调用https的请求接口用。简单实现后端框架;

详细

springboot 集成 mybatys项目demo

通过idea实现springboot集成mybatys;通过http请求操作mysql数据库

先将science.zip导入idea;

image.png

在mysql中运行test.sql;创建测试用数据库;数据库test用户名密码root/root

image.png

项目中只实现了一个对象User;通过controller接受http请求实现对user的操作;

实现过程:

编辑application.properties

spring.datasource.url = jdbc:mysql://127.0.0.1:3306/test
spring.datasource.username = root
spring.datasource.password = root
spring.datasource.driverClassName = com.mysql.cj.jdbc.Driver
实现springboot启动类
package com.liji.science;import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;@SpringBootApplication
public class ScienceApplication {public static void main(String[] args) {SpringApplication.run(ScienceApplication.class, args);}}

实现controller

package com.liji.science.controller;import com.liji.science.bean.User;
import com.liji.science.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;import java.util.List;@RestController
public class UserController {@Autowiredprivate UserService userService;@RequestMapping("/listUser")public  List<User> listUser(Model model) {List<User> users = userService.findAll();model.addAttribute("users", users);return users;}/*@RequestMapping("/toAdd")public String toAdd() {return "/addUser";}@RequestMapping("/add")public String addUser(User user) {userService.addUser(user);return "redirect:/listUser";}@RequestMapping("/toUpdate")public String toUpdate(Model model, int id) {User user = userService.findById(id);model.addAttribute("user", user);return "/updateUser";}@RequestMapping("/update")public String updateUser(User user) {userService.updateUser(user);return "redirect:/listUser";}@RequestMapping("/delete")public String deleteUser(int id) {userService.deleteUser(id);return "redirect:/listUser";}*/}

service实现

package com.liji.science.mapper;import com.liji.science.bean.User;
import org.apache.ibatis.annotations.*;import java.util.List;@Mapper
public interface UserMapper {/*** 全部用户查询* @return*/@Select("SELECT ID,NAME,PASSWORD,AGE FROM USER")List<User> findAll();/*** 新增用户*/@Insert("INSERT INTO USER(NAME,PASSWORD,AGE)VALUES(#{name}, #{password}, #{age})")void addUser(User user);/*** 修改用户*/@Update("UPDATE USER SET NAME=#{name}, PASSWORD=#{password}, AGE=#{age} WHERE ID=#{id}")void updateUser(User user);/*** 删除用户*/@Delete("DELETE FROM USER WHERE ID=#{id}")void deleteUser(int id);@Select("SELECT ID,NAME,PASSWORD,AGE FROM USER WHERE ID=#{id}")User findById(@Param("id")int id);
}
创建实体类
package com.liji.science.bean;public class User {private int id;private String name;private String password;private int age;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;}public String getPassword() {return password;}public void setPassword(String password) {this.password = password;}public int getAge() {return age;}public void setAge(int age) {this.age = age;}
}

idea启动成功;

idea启动成功;

image.png

范文用户列表

image.png

http://www.15wanjia.com/news/173777.html

相关文章:

  • 门户网站建设工作制度建立情况小游戏 打开
  • wap网站如何制作做网站商城项目的流程
  • 沛县网站易语言可以做网站后端
  • 一家装修的网站怎么做什么软件是做网站模板的
  • 做网站心得体会为自家企业做网站
  • 天津有哪些好的做网站公司房产类网站开发
  • 邢台做网站优化wordpress html5 主题
  • 网站制作哪家做的好项目计划书文件
  • 深圳哪里有做网站的怎么在自己的网站上做链接
  • 对网站建设的讲话核桃编程怎么报名网课
  • 批量上传产品WordPress汕头seo公司咨询23火星
  • 天津专业制作网站theme wordpress
  • 自己怎样做网站2003 建设网站
  • 深圳一元网站建设公司四川省建设厅证件查询
  • 博客网站是自己做的吗平谷青岛网站建设
  • 做照片书的模板下载网站小程序服务器多少钱
  • 网站文章模块dw做的网站怎么被别人打开
  • 网址导航网站建站网站开发硬件要求
  • 彩票资料网站怎么做暖色调 网站
  • 网站落地页怎么做的wordpress主题在哪
  • 个人备案网站经营怎么建立一个公司的网站吗
  • 搭建一个自己的网站滨湖网站制作
  • 做服装到哪个网站拿货品质好网站需要什么服务器
  • 网站建设的工具是福建住房和建设网站
  • 电子商务网站硬件建设的核心做网站会员功能
  • 网站后台多附件上传软件开发的过程
  • 新品发布会英语青岛网络优化公司
  • 网站建设的公司有哪些网站推广优化服务
  • 无锡网站制作楚天软件天河建设网站方案
  • w网站建设网站开发进度确认单