app开发者平台在数字化时代的重要性与发展趋势解析
558
2022-10-14
SpringMVC框架搭建idea2021.3.2操作数据库的示例详解
目录idea激活码激活永久教程:1.目录2.PersonController3.PersonMapper4.Person5.PersonServiceImpl6.PersonService7.jdbc.properties8.springmvc-servlet.xml9.sql10.pom
idea激活码激活永久教程:
https://jb51-/article/195962.htm
https://jb51-/article/200652.htm
https://jb51-/article/201899.htm
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
}
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.properczxvxkDeties
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
xmlns:xsi="http://w3.org/2001/XMLSchema-instance" xmlns:mvc="http://springframework.org/schema/mvc" xmlns:context="http://springframework.org/schema/context" xsi:schemaLocation="http://springframework.org/schema/beans http://springframework.org/schema/beans/spring-beans.xsd http://springframework.org/schema/mvc https://springframework.org/schema/mvc/spring-mvc.xsd http://springframework.org/schema/context https://springframework.org/schema/context/spring-context.xsd">
xmlns:xsi="http://w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://springframework.org/schema/mvc"
xmlns:context="http://springframework.org/schema/context"
xsi:schemaLocation="http://springframework.org/schema/beans
http://springframework.org/schema/beans/spring-beans.xsd
http://springframework.org/schema/mvc
https://springframework.org/schema/mvc/spring-mvc.xsd
http://springframework.org/schema/context
https://springframework.org/schema/context/spring-context.xsd">
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
xmlns:xsi="http://w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> czxvxkDe
xmlns:xsi="http://w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
czxvxkDe
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~