SpringMVC框架搭建idea2021.3.2操作数据库的示例详解

idea激活码激活永久教程:

https://www.jb51.net/article/195962.htm

https://www.jb51.net/article/200652.htm

https://www.jb51.net/article/201899.htm

1.目录

SpringMVC框架搭建idea2021.3.2操作数据库的示例详解_第1张图片

2.PersonController

package com.sk.controller;
import com.sk.entity.Person;
import com.sk.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
 * @Author 松柯
 * @Date 2022/3/31 17:36
 * @Version 1.0
 */
@Controller
@RequestMapping("/com/sk/Person")
public class PersonController {
    @Autowired
   private PersonService personService;
    @RequestMapping("/getPersonById")
    @ResponseBody
    public Object getPersonById(Integer id){
        return personService.getById(id);
    }
    @RequestMapping("/savePerson")
    @ResponseBody
    public Boolean savePerson(Person person){
        return personService.save(person);
    }
    @RequestMapping("/getPersonList")
    @ResponseBody
    public Object getPersonList(){
        return personService.list();
    }
}

3.PersonMapper

package com.sk.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sk.entity.Person;
/**
 * @Author 松柯
 * @Date 2022/3/31 17:36
 * @Version 1.0
 */
public interface PersonMapper extends BaseMapper {
}

4.Person

package com.sk.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
/**
 * @Author 松柯
 * @Date 2022/3/31 17:30
 * @Version 1.0
 */
@Data
public class Person {
    /**
     * personID
     */
    @TableId(type = IdType.ASSIGN_ID)
    private String personId;
     * 人名
    private String personName;
     * 年龄
    private Integer personAge;
}

5.PersonServiceImpl

package com.sk.service.Impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sk.dao.PersonMapper;
import com.sk.entity.Person;
import com.sk.service.PersonService;
import org.springframework.stereotype.Service;
/**
 * @Author 松柯
 * @Date 2022/3/31 17:35
 * @Version 1.0
 */
@Service
public class PersonServiceImpl extends ServiceImpl implements PersonService {
}

6.PersonService

package com.sk.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.sk.entity.Person;
import org.apache.ibatis.annotations.Mapper;
/**
 * @Author 松柯
 * @Date 2022/3/31 17:35
 * @Version 1.0
 */
public interface PersonService extends IService {
}

7.jdbc.properties

jdbc.driver=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/test?serverTimezone=GMT%2B8
jdbc.username=root
jdbc.password=123456

8.springmvc-servlet.xml




    
    
    
    
    
    
        
        
    
    
    
        
    
    
        
        
        
        
    
    
    
    
    
    
    

    
        
        
    

9.sql

-------------person----------------
CREATE TABLE `test` (
  `person_id` int NOT NULL AUTO_INCREMENT COMMENT '主键id',
  `person_name` varchar(255) NULL COMMENT '人名',
  `person_age` int NULL COMMENT '年龄',
  PRIMARY KEY (`person_id`)
);
-------------------------------------

10.pom



    4.0.0
    org.example
    spring-mvc
    1.0-SNAPSHOT
    
        11
        11
    
    
        
        
            org.springframework
            spring-core
            5.3.16
        
            spring-web
            spring-webmvc
            5.3.17
            spring-aop
        
        
            org.webjars.bower
            jquery
            3.6.0
        
            org.projectlombok
            lombok
            1.18.20
        
            com.baomidou
            mybatis-plus
            3.3.1
        
        
            mysql
            mysql-connector-java
            8.0.28
        
            com.alibaba
            druid
            1.1.9
        
            com.microsoft.sqlserver
            mssql-jdbc
            8.4.1.jre8
        
            spring-context
        
            spring-expression
        
            spring-tx
            4.3.22.RELEASE
            com.fasterxml.jackson.core
            jackson-annotations
            2.9.3
        
            jackson-core
        
            jackson-databind
            spring-jdbc
    

到此这篇关于SpringMVC框架搭建(idea2021.3.2)- 操作数据库的文章就介绍到这了,更多相关SpringMVC搭建idea2021.3.2内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

你可能感兴趣的:(SpringMVC框架搭建idea2021.3.2操作数据库的示例详解)