欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

spring?boot寫java?web和接口

 更新時間:2022年01月26日 10:32:27   作者:捕風(fēng)捉影  
這篇文章主要介紹了spring?boot寫java?web和接口,Spring?Boot是由Pivotal團隊提供的全新框架,其設(shè)計目的是用來簡化新Spring應(yīng)用的初始搭建以及開發(fā)過程,該框架使用了特定的方式來進行配置,從而使開發(fā)人員不再需要定義樣板化的配置,下面詳細內(nèi)容需要的小伙伴可以參考一下

流程:

Springboot開發(fā)過程

還有一個是mybatis的依賴

測試接口

@RestController

public class Hello {
? ? @RequestMapping("/hello")
? ? public String hello(){
? ? ? ? return "helloworld";
? ? }

}

***.yml文件配置

spring:
? ? ? datasource:
? ? ? ? ? ? driver-class-name: com.mysql.cj.jdbc.Driver
? ? ? ? ? ? url: jdbc:mysql://localhost:3306/student?useUnicode=true&useSSL=false&characterEncoding=utf8&serverTimezone=Asia/Shanghai
? ? ? ? ? ? username: root
? ? ? ? ? ? password: 123456
mybatis:
? ? ? mapper-locations: classpath:mapper/*.xml

數(shù)據(jù)庫字段:

pojo

@Data
public class User {
? ? private ?int id ;
? ? private String name;
? ? private int age;
? ? private String email;
? ? *****

剩下的就是getset方法自行完成

mapper

@Mapper
public interface UserMapper {
? ? List<User> findAll();
}

如果是springboot,在啟動類中使用@MapperScan(“mapper接口所在包全名”)即可,不用一個一個的在Mapper接口中加@Mapper注解。@Mapper注解是識別他為mybatis的mapper接口,會自動的把 加@Mapper 注解的接口生成動態(tài)代理類。
springboot認(rèn)識你的mapper層,也可以在啟動類上面加MapperScan(“mapper層所在包的全名”)

mapper.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.liuyang.mapper.UserMapper">
? ? <select id="findAll" resultType="com.liuyang.entity.User">
? ? ? ? SELECT * FROM user
? ? </select>
</mapper>

controller

@RestController
public class UserController {

? ? @Autowired
? ? //把userService實例化
? ? private UserService userService;
? ? @RequestMapping("/user")
? ? public List<User> getUser(){

? ? ? ? return userService.findAll();

? ? }

}

注意一定要把userService 注入到容器中

數(shù)據(jù)成功拿到

相關(guān)文章

最新評論