spring(Spring框架全面详解)

懵懂先生 网文资讯spring(Spring框架全面详解)已关闭评论118阅读模式

文章源自略懂百科-http://wswcn.cn/24621.html

步骤文章源自略懂百科-http://wswcn.cn/24621.html

1.创建Springboot:文章源自略懂百科-http://wswcn.cn/24621.html

如果想学习Java工程化、高性能及分布式、深入浅出。微服务、Spring,MyBatis,Netty源码分析的朋友可以加我的Java高级交流:787707172,群里有阿里大牛直播讲解技术,以及Java大型互联网技术的视频免费分享给大家。文章源自略懂百科-http://wswcn.cn/24621.html

2.创建项目文件结构文章源自略懂百科-http://wswcn.cn/24621.html

3.POM依赖文章源自略懂百科-http://wswcn.cn/24621.html

如果使用阿里云的连接池不选择JDBC,小编用的阿里云这里不选择文章源自略懂百科-http://wswcn.cn/24621.html

点击Finish;文章源自略懂百科-http://wswcn.cn/24621.html

注:可能Maven中无Jar包需要从仓库下载,需要耐心等待(可以去听首歌)文章源自略懂百科-http://wswcn.cn/24621.html

4.项目结构文章源自略懂百科-http://wswcn.cn/24621.html

5.POM文章源自略懂百科-http://wswcn.cn/24621.html

4.0.0文章源自略懂百科-http://wswcn.cn/24621.html

org.springframework.boot
spring-boot-starter-parent
2.1.1.RELEASE文章源自略懂百科-http://wswcn.cn/24621.html

com.spring
boot
0.0.1-SNAPSHOT
boot
Demo project for Spring Boot文章源自略懂百科-http://wswcn.cn/24621.html

1.8文章源自略懂百科-http://wswcn.cn/24621.html

org.springframework.boot
spring-boot-devtools
true文章源自略懂百科-http://wswcn.cn/24621.html

com.alibaba
druid-spring-boot-starter
1.1.10文章源自略懂百科-http://wswcn.cn/24621.html

org.springframework.boot
spring-boot-starter-thymeleaf文章源自略懂百科-http://wswcn.cn/24621.html

org.springframework.boot
spring-boot-starter-web文章源自略懂百科-http://wswcn.cn/24621.html

org.mybatis.spring.boot
mybatis-spring-boot-starter
1.3.2文章源自略懂百科-http://wswcn.cn/24621.html

mysql
mysql-connector-java
runtime文章源自略懂百科-http://wswcn.cn/24621.html

org.springframework.boot
spring-boot-starter-test
test文章源自略懂百科-http://wswcn.cn/24621.html

org.springframework.boot
spring-boot-maven-plugin文章源自略懂百科-http://wswcn.cn/24621.html

注:IDEA失效解决方法文章源自略懂百科-http://wswcn.cn/24621.html

6.小编使用的application.properties文件,项目启动识别两种格式的文件properties和yml文件:文章源自略懂百科-http://wswcn.cn/24621.html

缓存设置为false, 修改之后马上生效
spring.thymeleaf.cache=false
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html文章源自略懂百科-http://wswcn.cn/24621.html

server.port=8080
server.tomcat.uriEncoding=utf-8文章源自略懂百科-http://wswcn.cn/24621.html

spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.url=jdbc:mysql://localhost:3306/web?useUnicode=true&serverTimezone=GMT%2B8&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.druid.driverClassName=com.mysql.cj.jdbc.Driver
初始化连接
spring.datasource.initialSize=20
最大空闲数
spring.datasource.maxActive=50
最小空闲数
spring.datasource.minIdle=10
获取连接等待时间
spring.datasource.druid.max-wait=60000
最小等待时间
spring.datasource.minEvictableIdleTimeMillis=3600000
7.其他文件生成
User.java
package com.spring.boot.bean;文章源自略懂百科-http://wswcn.cn/24621.html

public class User {文章源自略懂百科-http://wswcn.cn/24621.html

public Integer uid;
public String uname;
public String upassword;文章源自略懂百科-http://wswcn.cn/24621.html

public Integer getUid() {
return uid;
}文章源自略懂百科-http://wswcn.cn/24621.html

public void setUid(Integer uid) {
this.uid = uid;
}文章源自略懂百科-http://wswcn.cn/24621.html

public String getUanme() {
return uname;
}文章源自略懂百科-http://wswcn.cn/24621.html

public void setUanme(String uanme) {
this.uname = uanme;
}文章源自略懂百科-http://wswcn.cn/24621.html

public String getUpassword() {
return upassword;
}文章源自略懂百科-http://wswcn.cn/24621.html

public void setUpassword(String upassword) {
this.upassword = upassword;
}文章源自略懂百科-http://wswcn.cn/24621.html

@Override
public String toString() {
return "User{" +
"uid=" + uid +
", uname=" + uname + +
", upassword=" + upassword + +
};
}
}文章源自略懂百科-http://wswcn.cn/24621.html

UserDao.java文章源自略懂百科-http://wswcn.cn/24621.html

注解的形式,小编感觉比XML好用文章源自略懂百科-http://wswcn.cn/24621.html

package com.spring.boot.dao;文章源自略懂百科-http://wswcn.cn/24621.html

import com.spring.boot.bean.User;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;文章源自略懂百科-http://wswcn.cn/24621.html

import java.util.List;文章源自略懂百科-http://wswcn.cn/24621.html

public interface UserDao {文章源自略懂百科-http://wswcn.cn/24621.html

@Select("select * from user")
public List AllUser();文章源自略懂百科-http://wswcn.cn/24621.html

@Update(" ")
public int Update(User user);文章源自略懂百科-http://wswcn.cn/24621.html

}
UserService.java
package com.spring.boot.service;文章源自略懂百科-http://wswcn.cn/24621.html

import com.spring.boot.bean.User;文章源自略懂百科-http://wswcn.cn/24621.html

import java.util.List;文章源自略懂百科-http://wswcn.cn/24621.html

public interface UserService {文章源自略懂百科-http://wswcn.cn/24621.html

public List AllUser();文章源自略懂百科-http://wswcn.cn/24621.html

public int Update(User user);文章源自略懂百科-http://wswcn.cn/24621.html

}文章源自略懂百科-http://wswcn.cn/24621.html

如果想学习Java工程化、高性能及分布式、深入浅出。微服务、Spring,MyBatis,Netty源码分析的朋友可以加我的Java高级交流:787707172,群里有阿里大牛直播讲解技术,以及Java大型互联网技术的视频免费分享给大家。文章源自略懂百科-http://wswcn.cn/24621.html

UserImpl.java文章源自略懂百科-http://wswcn.cn/24621.html

主要是注解问题Service可以命名,主要还是看自己的日常使用文章源自略懂百科-http://wswcn.cn/24621.html

package com.spring.boot.service.impl;文章源自略懂百科-http://wswcn.cn/24621.html

import com.spring.boot.bean.User;
import com.spring.boot.dao.UserDao;
import com.spring.boot.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;文章源自略懂百科-http://wswcn.cn/24621.html

import java.util.List;文章源自略懂百科-http://wswcn.cn/24621.html

@Service
public class UserImpl implements UserService {文章源自略懂百科-http://wswcn.cn/24621.html

@Autowired
private UserDao userDao;文章源自略懂百科-http://wswcn.cn/24621.html

@Override
public List AllUser() {文章源自略懂百科-http://wswcn.cn/24621.html

return userDao.AllUser();
}文章源自略懂百科-http://wswcn.cn/24621.html

@Override
public int Update(User user) {
return userDao.Update(user);
}
}文章源自略懂百科-http://wswcn.cn/24621.html

注:userDao报红解决方法文章源自略懂百科-http://wswcn.cn/24621.html

UserController.java
package com.spring.boot.controller;文章源自略懂百科-http://wswcn.cn/24621.html

import com.spring.boot.bean.User;
import com.spring.boot.service.impl.UserImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;文章源自略懂百科-http://wswcn.cn/24621.html

@Controller
public class UserController {文章源自略懂百科-http://wswcn.cn/24621.html

@Autowired
private UserImpl userimpl;文章源自略懂百科-http://wswcn.cn/24621.html

@RequestMapping("/index")
public String index(Model model, User user){
model.addAttribute("user",userimpl.AllUser());
user.uid = 2;
user.uname = "nan";
user.upassword = "lou";
userimpl.Update(user);
System.out.println("******************"+userimpl.AllUser());
System.out.println("******************"+userimpl.Update(user));
return "index";
}文章源自略懂百科-http://wswcn.cn/24621.html

}
index.html文章源自略懂百科-http://wswcn.cn/24621.html

Title文章源自略懂百科-http://wswcn.cn/24621.html

Spring boot+Thymeleaf!文章源自略懂百科-http://wswcn.cn/24621.html

8.界面显示文章源自略懂百科-http://wswcn.cn/24621.html

欢迎工作一到八年的Java工程师朋友们加入Java高级交流:787707172文章源自略懂百科-http://wswcn.cn/24621.html

本群提供免费的学习指导 架构资料 以及免费的解答文章源自略懂百科-http://wswcn.cn/24621.html

不懂得问题都可以在本群提出来 之后还会有直播平台和讲师直接交流噢文章源自略懂百科-http://wswcn.cn/24621.html

文章源自略懂百科-http://wswcn.cn/24621.html

懵懂先生
  • 本文由 发表于 2022年8月5日 11:14:53
  • 转载请注明:http://wswcn.cn/24621.html
网文资讯

从写作开始的成语全集(从写作开始的四个字是什么)

文:崔馨雨 原创不易 抄袭必究 自媒体时代,各个app,无门槛入住。很多人,写写文字、拍拍视频,就能获得睡后收入,躺赢人生。 你蠢蠢欲动吗?心动不如行动! 自媒体人生存的第一要素:必须具有写的能力。 ...
网文资讯

云手机(阿里云手机正式公测)

2021年12月1日,阿里弹性云手机正式公测,移动应用新载体,赋予手机全新的接入方式。 云手机市场从2015-2020年持续增长,结合未来移动行业的技术发展趋势如5G、边缘计算等,云手机扮演的角色会更...
网文资讯

皮卡丘简笔画(可爱的皮卡丘简笔画教程)

重播播放00:00/00:00正在直播00:00进入全屏点击按住可拖动视频第86期原创教程:皮卡丘简笔画 ▼ hi~大家好,你们要的皮卡丘简笔画来了~皮卡丘是小朋友们最喜欢的卡通形象之一,它简单漂亮又...
网文资讯

尺码对照表(衣服尺码对照表)

很多人不喜欢网购的原因之一,就是不能够现场试穿来确定尺码是否合适。其实在我国,不论女装男装童装或者内衣,各种服饰都有行业通用的标准尺码对照表。了解清楚这些尺码型号对应的尺寸,那样网购再也不怕买到不合适...