栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Vue+SpringBoot+跨域实现对数据库的增删改查

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Vue+SpringBoot+跨域实现对数据库的增删改查

搭建项目 pom.xml依赖


        
            org.springframework.boot
            spring-boot-starter-web
        

        
            org.springframework.boot
            spring-boot-starter-test
            test
        

        
            org.springframework.boot
            spring-boot-starter-web
        

        
        
            org.mybatis.spring.boot
            mybatis-spring-boot-starter
            2.1.3
        

        
        
            com.github.pagehelper
            pagehelper
            5.1.2
        

        
        
            mysql
            mysql-connector-java
        

        
        
            com.alibaba
            druid
            1.1.22
        
        
            com.alibaba
            fastjson
            1.2.47
        

        
            org.springframework.boot
            spring-boot-devtools
            runtime
            true
        

        
        
            org.springframework.boot
            spring-boot-starter-thymeleaf
        

        
            net.sourceforge.nekohtml
            nekohtml
            1.9.22
        

        
        
            org.projectlombok
            lombok
        

    
application.yml
#修改端口号
server:
  port: 8080


  servlet:
    encoding:
      charset: UTF-8
      force: true
      enabled: true
  tomcat:
    uri-encoding: UTF-8     # tomcat的URI编码


#数据库
spring:
  datasource:
    type: com.alibaba.druid.pool.DruidDataSource
    username: root
    password: 123456
    url: jdbc:mysql://localhost:3306/user?useUnicode=true&characterEncoding=utf-8
    driver-class-name: com.mysql.cj.jdbc.Driver

#配置静态资源
  web:
   resources:
    static-locations: classpath:/static/,classpath:/templates/


mybatis:
  #别名
  type-aliases-package: com.yzx.boot.entity

  #xml配置
  mapper-locations: classpath:mybatis
    private  Integer id;
    
    private  String name;
    
    private  Integer age;
    
    private  Double salary;

}
mapper层:
package com.yzx.boot.mapper;


import com.yzx.boot.entity.Emp;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

@Mapper
public interface EmpMapper {
//    List login(Emp emp);

    List find(Emp   emp);
    int  del(Integer  id);
    Emp findByID(Integer  id);
    int upd(Emp emp);
    int add(Emp emp);
}
service层:
package com.yzx.boot.service.user;

import com.yzx.boot.entity.Emp;
import com.yzx.boot.entity.Userinfo;

import java.util.List;


public interface EmpService {

  //  Emp login(Emp emp);

    List find(Emp   emp);
    int  del(Integer  id);
    Emp findByID(Integer  id);
    int upd(Emp emp);
    int add(Emp emp);
}

serviceimpl:
package com.yzx.boot.service.user;


import com.yzx.boot.entity.Emp;
import com.yzx.boot.mapper.EmpMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


@Service
public class EmpServiceimpl implements EmpService {
    @Resource
    private EmpMapper empmapper;
//    @Override
//    public Emp login(Emp emp) {
//        List list = empmapper.login(emp);
//        if (list != null && list.size() > 0) {
//            return list.get(0);
//        }
//        return null;
//    }



    @Override
    public List find(Emp emp) {

        return empmapper.find(emp);
    }

    @Override
    public int del(Integer id) {
        return empmapper.del(id);
    }

    @Override
    public Emp findByID(Integer id) {
        return empmapper.findByID(id);
    }

    @Override
    public int upd(Emp emp) {
        return empmapper.upd(emp);
    }

    @Override
    public int add(Emp emp) {
        System.out.println(emp);
        return empmapper.add(emp);

    }
}

前台代码:html



	
		
		
		
		
		
		
	
	
		
			{{msg}}
			  
			
编号 姓名 年龄 工资 操作
{{it.id}} {{it.name}} {{it.age}} {{it.salary}}

姓名:
年龄:
工资:

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/704177.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号