Spring框架详解 - 03

前言

Spring boot + Mybatis + Thymeleaf + Druid +mySql

开发环境(小编使用的版本)

JDK版本 :1.8及以上 (JDK1.8);
开发工具 :Intellij IDEA (IDEA2018.2);
服务器 :Tomcat(务必比JDK版本高,小编不在解释(Jar包不用配置、War需要配置)) (Tomcat9) ;
JRE包 :Maven仓库 (Maven3.6);
数据库 :MySql(MySql5.5) ;
正题

Spring boot :2.1.1RELEASE ;

Thymeleaf

Mybatis

阿里云的连接池 : Druid ;

步骤

1.创建Springboot:

2.创建项目文件结构

3.POM依赖

如果使用阿里云的连接池不选择JDBC,小编用的阿里云这里不选择

点击Finish;
注:可能Maven中无Jar包需要从仓库下载,需要耐心等待(可以去听首歌)

4.项目结构

5.POM

<?xml version="1.0" encoding="UTF-8"?>


4.0.0

org.springframework.boot
spring-boot-starter-parent
2.1.1.RELEASE


com.spring
boot
0.0.1-SNAPSHOT
boot
Demo project for Spring Boot

<properties>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <!-- Springboot 热部署 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
    </dependency>
    <!-- 阿里的Druid连接池 -->
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>druid-spring-boot-starter</artifactId>
        <version>1.1.10</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.mybatis.spring.boot</groupId>
        <artifactId>mybatis-spring-boot-starter</artifactId>
        <version>1.3.2</version>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>
注:IDEA失效解决方法

6.小编使用的application.properties文件,项目启动识别两种格式的文件properties和yml文件:

#缓存设置为false, 修改之后马上生效
spring.thymeleaf.cache=false
spring.thymeleaf.encoding=UTF-8
#spring.thymeleaf.prefix=classpath:/templates/
#spring.thymeleaf.suffix=.html

server.port=8080
server.tomcat.uriEncoding=utf-8

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;

public class User {

public Integer uid;
public String uname;
public String upassword;

public Integer getUid() {
    return uid;
}

public void setUid(Integer uid) {
    this.uid = uid;
}

public String getUanme() {
    return uname;
}

public void setUanme(String uanme) {
    this.uname = uanme;
}

public String getUpassword() {
    return upassword;
}

public void setUpassword(String upassword) {
    this.upassword = upassword;
}

@Override
public String toString() {
    return "User{" +
            "uid=" + uid +
            ", uname='" + uname + '\'' +
            ", upassword='" + upassword + '\'' +
            '}';
}

}
UserDao.java

注解的形式,小编感觉比XML好用

package com.spring.boot.dao;

import com.spring.boot.bean.User;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface UserDao {

@Select("select * from user")
public List<User> AllUser();

@Update("<script> " + "update user" +
        "<set>"+  "<if test='uname!=null'>uname=#{uname},</if>"+
        "<if test='upassword!=null'>upassword=#{upassword},</if>"+
        "</set>"+ "where uid=#{uid}"+
        " </script> ")
public int Update(User user);

}
UserService.java

package com.spring.boot.service;

import com.spring.boot.bean.User;

import java.util.List;

public interface UserService {

public List<User> AllUser();

public int Update(User user);

}

UserImpl.java
主要是注解问题Service可以命名,主要还是看自己的日常使用

package com.spring.boot.service.impl;

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;

import java.util.List;

@Service
public class UserImpl implements UserService {

@Autowired
private UserDao userDao;

@Override
public List<User> AllUser() {

    return userDao.AllUser();
}

@Override
public int Update(User user) {
    return userDao.Update(user);
}

}
注:userDao报红解决方法

UserController.java

package com.spring.boot.controller;

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;

@Controller
public class UserController {

@Autowired
private UserImpl userimpl;

@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";
}

}
index.html

Title Spring boot+Thymeleaf!
8.界面显示

注:后续功能再写!
小编这是Java web项目,@Controller注解是界面、@RestController是写接口
哪里又不对的给提醒


作者:沐荔
来源:CSDN
QQ群:810853011

作者:沐荔
来源:CSDN
原文:https://blog.csdn.net/qq_41920732/article/details/85936063
版权声明:本文为博主原创文章,转载请附上博文链接!前言

Spring boot + Mybatis + Thymeleaf + Druid +mySql

开发环境(小编使用的版本)

JDK版本 :1.8及以上 (JDK1.8);
开发工具 :Intellij IDEA (IDEA2018.2);
服务器 :Tomcat(务必比JDK版本高,小编不在解释(Jar包不用配置、War需要配置)) (Tomcat9) ;
JRE包 :Maven仓库 (Maven3.6);
数据库 :MySql(MySql5.5) ;
正题

Spring boot :2.1.1RELEASE ;

Thymeleaf

Mybatis

阿里云的连接池 : Druid ;

步骤

1.创建Springboot:

2.创建项目文件结构

3.POM依赖

如果使用阿里云的连接池不选择JDBC,小编用的阿里云这里不选择

点击Finish;
注:可能Maven中无Jar包需要从仓库下载,需要耐心等待(可以去听首歌)

4.项目结构

5.POM

<?xml version="1.0" encoding="UTF-8"?>


4.0.0

org.springframework.boot
spring-boot-starter-parent
2.1.1.RELEASE


com.spring
boot
0.0.1-SNAPSHOT
boot
Demo project for Spring Boot

<properties>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <!-- Springboot 热部署 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
    </dependency>
    <!-- 阿里的Druid连接池 -->
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>druid-spring-boot-starter</artifactId>
        <version>1.1.10</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.mybatis.spring.boot</groupId>
        <artifactId>mybatis-spring-boot-starter</artifactId>
        <version>1.3.2</version>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>
注:IDEA失效解决方法

6.小编使用的application.properties文件,项目启动识别两种格式的文件properties和yml文件:

#缓存设置为false, 修改之后马上生效
spring.thymeleaf.cache=false
spring.thymeleaf.encoding=UTF-8
#spring.thymeleaf.prefix=classpath:/templates/
#spring.thymeleaf.suffix=.html

server.port=8080
server.tomcat.uriEncoding=utf-8

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;

public class User {

public Integer uid;
public String uname;
public String upassword;

public Integer getUid() {
    return uid;
}

public void setUid(Integer uid) {
    this.uid = uid;
}

public String getUanme() {
    return uname;
}

public void setUanme(String uanme) {
    this.uname = uanme;
}

public String getUpassword() {
    return upassword;
}

public void setUpassword(String upassword) {
    this.upassword = upassword;
}

@Override
public String toString() {
    return "User{" +
            "uid=" + uid +
            ", uname='" + uname + '\'' +
            ", upassword='" + upassword + '\'' +
            '}';
}

}
UserDao.java

注解的形式,小编感觉比XML好用

package com.spring.boot.dao;

import com.spring.boot.bean.User;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface UserDao {

@Select("select * from user")
public List<User> AllUser();

@Update("<script> " + "update user" +
        "<set>"+  "<if test='uname!=null'>uname=#{uname},</if>"+
        "<if test='upassword!=null'>upassword=#{upassword},</if>"+
        "</set>"+ "where uid=#{uid}"+
        " </script> ")
public int Update(User user);

}
UserService.java

package com.spring.boot.service;

import com.spring.boot.bean.User;

import java.util.List;

public interface UserService {

public List<User> AllUser();

public int Update(User user);

}

UserImpl.java
主要是注解问题Service可以命名,主要还是看自己的日常使用

package com.spring.boot.service.impl;

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;

import java.util.List;

@Service
public class UserImpl implements UserService {

@Autowired
private UserDao userDao;

@Override
public List<User> AllUser() {

    return userDao.AllUser();
}

@Override
public int Update(User user) {
    return userDao.Update(user);
}

}
注:userDao报红解决方法

UserController.java

package com.spring.boot.controller;

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;

@Controller
public class UserController {

@Autowired
private UserImpl userimpl;

@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";
}

}
index.html

Title Spring boot+Thymeleaf!
8.界面显示

注:后续功能再写!
小编这是Java web项目,@Controller注解是界面、@RestController是写接口
哪里又不对的给提醒


作者:沐荔
来源:CSDN
QQ群:810853011

作者:沐荔
来源:CSDN
原文:https://blog.csdn.net/qq_41920732/article/details/85936063
版权声明:本文为博主原创文章,转载请附上博文链接!前言

Spring boot + Mybatis + Thymeleaf + Druid +mySql

开发环境(小编使用的版本)

JDK版本 :1.8及以上 (JDK1.8);
开发工具 :Intellij IDEA (IDEA2018.2);
服务器 :Tomcat(务必比JDK版本高,小编不在解释(Jar包不用配置、War需要配置)) (Tomcat9) ;
JRE包 :Maven仓库 (Maven3.6);
数据库 :MySql(MySql5.5) ;
正题

Spring boot :2.1.1RELEASE ;

Thymeleaf

Mybatis

阿里云的连接池 : Druid ;

步骤

1.创建Springboot:

2.创建项目文件结构

3.POM依赖

如果使用阿里云的连接池不选择JDBC,小编用的阿里云这里不选择

点击Finish;
注:可能Maven中无Jar包需要从仓库下载,需要耐心等待(可以去听首歌)

4.项目结构

5.POM

<?xml version="1.0" encoding="UTF-8"?>


4.0.0

org.springframework.boot
spring-boot-starter-parent
2.1.1.RELEASE


com.spring
boot
0.0.1-SNAPSHOT
boot
Demo project for Spring Boot

<properties>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <!-- Springboot 热部署 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
    </dependency>
    <!-- 阿里的Druid连接池 -->
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>druid-spring-boot-starter</artifactId>
        <version>1.1.10</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.mybatis.spring.boot</groupId>
        <artifactId>mybatis-spring-boot-starter</artifactId>
        <version>1.3.2</version>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>
注:IDEA失效解决方法

6.小编使用的application.properties文件,项目启动识别两种格式的文件properties和yml文件:

#缓存设置为false, 修改之后马上生效
spring.thymeleaf.cache=false
spring.thymeleaf.encoding=UTF-8
#spring.thymeleaf.prefix=classpath:/templates/
#spring.thymeleaf.suffix=.html

server.port=8080
server.tomcat.uriEncoding=utf-8

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;

public class User {

public Integer uid;
public String uname;
public String upassword;

public Integer getUid() {
    return uid;
}

public void setUid(Integer uid) {
    this.uid = uid;
}

public String getUanme() {
    return uname;
}

public void setUanme(String uanme) {
    this.uname = uanme;
}

public String getUpassword() {
    return upassword;
}

public void setUpassword(String upassword) {
    this.upassword = upassword;
}

@Override
public String toString() {
    return "User{" +
            "uid=" + uid +
            ", uname='" + uname + '\'' +
            ", upassword='" + upassword + '\'' +
            '}';
}

}
UserDao.java

注解的形式,小编感觉比XML好用

package com.spring.boot.dao;

import com.spring.boot.bean.User;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface UserDao {

@Select("select * from user")
public List<User> AllUser();

@Update("<script> " + "update user" +
        "<set>"+  "<if test='uname!=null'>uname=#{uname},</if>"+
        "<if test='upassword!=null'>upassword=#{upassword},</if>"+
        "</set>"+ "where uid=#{uid}"+
        " </script> ")
public int Update(User user);

}
UserService.java

package com.spring.boot.service;

import com.spring.boot.bean.User;

import java.util.List;

public interface UserService {

public List<User> AllUser();

public int Update(User user);

}

UserImpl.java
主要是注解问题Service可以命名,主要还是看自己的日常使用

package com.spring.boot.service.impl;

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;

import java.util.List;

@Service
public class UserImpl implements UserService {

@Autowired
private UserDao userDao;

@Override
public List<User> AllUser() {

    return userDao.AllUser();
}

@Override
public int Update(User user) {
    return userDao.Update(user);
}

}
注:userDao报红解决方法

UserController.java

package com.spring.boot.controller;

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;

@Controller
public class UserController {

@Autowired
private UserImpl userimpl;

@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";
}

}
index.html

Title Spring boot+Thymeleaf!
8.界面显示

注:后续功能再写!
小编这是Java web项目,@Controller注解是界面、@RestController是写接口
哪里又不对的给提醒


作者:沐荔
来源:CSDN
QQ群:810853011

作者:沐荔
来源:CSDN
原文:https://blog.csdn.net/qq_41920732/article/details/85936063
版权声明:本文为博主原创文章,转载请附上博文链接!前言

Spring boot + Mybatis + Thymeleaf + Druid +mySql

开发环境(小编使用的版本)

JDK版本 :1.8及以上 (JDK1.8);
开发工具 :Intellij IDEA (IDEA2018.2);
服务器 :Tomcat(务必比JDK版本高,小编不在解释(Jar包不用配置、War需要配置)) (Tomcat9) ;
JRE包 :Maven仓库 (Maven3.6);
数据库 :MySql(MySql5.5) ;
正题

Spring boot :2.1.1RELEASE ;

Thymeleaf

Mybatis

阿里云的连接池 : Druid ;

步骤

1.创建Springboot:

2.创建项目文件结构

3.POM依赖

如果使用阿里云的连接池不选择JDBC,小编用的阿里云这里不选择

点击Finish;
注:可能Maven中无Jar包需要从仓库下载,需要耐心等待(可以去听首歌)

4.项目结构

5.POM

<?xml version="1.0" encoding="UTF-8"?>


4.0.0

org.springframework.boot
spring-boot-starter-parent
2.1.1.RELEASE


com.spring
boot
0.0.1-SNAPSHOT
boot
Demo project for Spring Boot

<properties>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <!-- Springboot 热部署 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
    </dependency>
    <!-- 阿里的Druid连接池 -->
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>druid-spring-boot-starter</artifactId>
        <version>1.1.10</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.mybatis.spring.boot</groupId>
        <artifactId>mybatis-spring-boot-starter</artifactId>
        <version>1.3.2</version>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>
注:IDEA失效解决方法

6.小编使用的application.properties文件,项目启动识别两种格式的文件properties和yml文件:

#缓存设置为false, 修改之后马上生效
spring.thymeleaf.cache=false
spring.thymeleaf.encoding=UTF-8
#spring.thymeleaf.prefix=classpath:/templates/
#spring.thymeleaf.suffix=.html

server.port=8080
server.tomcat.uriEncoding=utf-8

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;

public class User {

public Integer uid;
public String uname;
public String upassword;

public Integer getUid() {
    return uid;
}

public void setUid(Integer uid) {
    this.uid = uid;
}

public String getUanme() {
    return uname;
}

public void setUanme(String uanme) {
    this.uname = uanme;
}

public String getUpassword() {
    return upassword;
}

public void setUpassword(String upassword) {
    this.upassword = upassword;
}

@Override
public String toString() {
    return "User{" +
            "uid=" + uid +
            ", uname='" + uname + '\'' +
            ", upassword='" + upassword + '\'' +
            '}';
}

}
UserDao.java

注解的形式,小编感觉比XML好用

package com.spring.boot.dao;

import com.spring.boot.bean.User;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface UserDao {

@Select("select * from user")
public List<User> AllUser();

@Update("<script> " + "update user" +
        "<set>"+  "<if test='uname!=null'>uname=#{uname},</if>"+
        "<if test='upassword!=null'>upassword=#{upassword},</if>"+
        "</set>"+ "where uid=#{uid}"+
        " </script> ")
public int Update(User user);

}
UserService.java

package com.spring.boot.service;

import com.spring.boot.bean.User;

import java.util.List;

public interface UserService {

public List<User> AllUser();

public int Update(User user);

}

UserImpl.java
主要是注解问题Service可以命名,主要还是看自己的日常使用

package com.spring.boot.service.impl;

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;

import java.util.List;

@Service
public class UserImpl implements UserService {

@Autowired
private UserDao userDao;

@Override
public List<User> AllUser() {

    return userDao.AllUser();
}

@Override
public int Update(User user) {
    return userDao.Update(user);
}

}
注:userDao报红解决方法

UserController.java

package com.spring.boot.controller;

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;

@Controller
public class UserController {

@Autowired
private UserImpl userimpl;

@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";
}

}
index.html

Title Spring boot+Thymeleaf!
8.界面显示

注:后续功能再写!
小编这是Java web项目,@Controller注解是界面、@RestController是写接口
哪里又不对的给提醒


作者:沐荔
来源:CSDN
QQ群:810853011

作者:沐荔
来源:CSDN
原文:https://blog.csdn.net/qq_41920732/article/details/85936063
版权声明:本文为博主原创文章,转载请附上博文链接!前言

Spring boot + Mybatis + Thymeleaf + Druid +mySql

开发环境(小编使用的版本)

JDK版本 :1.8及以上 (JDK1.8);
开发工具 :Intellij IDEA (IDEA2018.2);
服务器 :Tomcat(务必比JDK版本高,小编不在解释(Jar包不用配置、War需要配置)) (Tomcat9) ;
JRE包 :Maven仓库 (Maven3.6);
数据库 :MySql(MySql5.5) ;
正题

Spring boot :2.1.1RELEASE ;

Thymeleaf

Mybatis

阿里云的连接池 : Druid ;

步骤

1.创建Springboot:

2.创建项目文件结构

3.POM依赖

如果使用阿里云的连接池不选择JDBC,小编用的阿里云这里不选择

点击Finish;
注:可能Maven中无Jar包需要从仓库下载,需要耐心等待(可以去听首歌)

4.项目结构

5.POM

<?xml version="1.0" encoding="UTF-8"?>


4.0.0

org.springframework.boot
spring-boot-starter-parent
2.1.1.RELEASE


com.spring
boot
0.0.1-SNAPSHOT
boot
Demo project for Spring Boot

<properties>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <!-- Springboot 热部署 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
    </dependency>
    <!-- 阿里的Druid连接池 -->
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>druid-spring-boot-starter</artifactId>
        <version>1.1.10</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.mybatis.spring.boot</groupId>
        <artifactId>mybatis-spring-boot-starter</artifactId>
        <version>1.3.2</version>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>
注:IDEA失效解决方法

6.小编使用的application.properties文件,项目启动识别两种格式的文件properties和yml文件:

#缓存设置为false, 修改之后马上生效
spring.thymeleaf.cache=false
spring.thymeleaf.encoding=UTF-8
#spring.thymeleaf.prefix=classpath:/templates/
#spring.thymeleaf.suffix=.html

server.port=8080
server.tomcat.uriEncoding=utf-8

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;

public class User {

public Integer uid;
public String uname;
public String upassword;

public Integer getUid() {
    return uid;
}

public void setUid(Integer uid) {
    this.uid = uid;
}

public String getUanme() {
    return uname;
}

public void setUanme(String uanme) {
    this.uname = uanme;
}

public String getUpassword() {
    return upassword;
}

public void setUpassword(String upassword) {
    this.upassword = upassword;
}

@Override
public String toString() {
    return "User{" +
            "uid=" + uid +
            ", uname='" + uname + '\'' +
            ", upassword='" + upassword + '\'' +
            '}';
}

}
UserDao.java

注解的形式,小编感觉比XML好用

package com.spring.boot.dao;

import com.spring.boot.bean.User;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface UserDao {

@Select("select * from user")
public List<User> AllUser();

@Update("<script> " + "update user" +
        "<set>"+  "<if test='uname!=null'>uname=#{uname},</if>"+
        "<if test='upassword!=null'>upassword=#{upassword},</if>"+
        "</set>"+ "where uid=#{uid}"+
        " </script> ")
public int Update(User user);

}
UserService.java

package com.spring.boot.service;

import com.spring.boot.bean.User;

import java.util.List;

public interface UserService {

public List<User> AllUser();

public int Update(User user);

}

UserImpl.java
主要是注解问题Service可以命名,主要还是看自己的日常使用

package com.spring.boot.service.impl;

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;

import java.util.List;

@Service
public class UserImpl implements UserService {

@Autowired
private UserDao userDao;

@Override
public List<User> AllUser() {

    return userDao.AllUser();
}

@Override
public int Update(User user) {
    return userDao.Update(user);
}

}
注:userDao报红解决方法

UserController.java

package com.spring.boot.controller;

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;

@Controller
public class UserController {

@Autowired
private UserImpl userimpl;

@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";
}

}
index.html

Title Spring boot+Thymeleaf!
8.界面显示

注:后续功能再写!
小编这是Java web项目,@Controller注解是界面、@RestController是写接口
哪里又不对的给提醒


作者:沐荔
来源:CSDN
QQ群:810853011

作者:沐荔
来源:CSDN
原文:https://blog.csdn.net/qq_41920732/article/details/85936063
版权声明:本文为博主原创文章,转载请附上博文链接!前言

Spring boot + Mybatis + Thymeleaf + Druid +mySql

开发环境(小编使用的版本)

JDK版本 :1.8及以上 (JDK1.8);
开发工具 :Intellij IDEA (IDEA2018.2);
服务器 :Tomcat(务必比JDK版本高,小编不在解释(Jar包不用配置、War需要配置)) (Tomcat9) ;
JRE包 :Maven仓库 (Maven3.6);
数据库 :MySql(MySql5.5) ;
正题

Spring boot :2.1.1RELEASE ;

Thymeleaf

Mybatis

阿里云的连接池 : Druid ;

步骤

1.创建Springboot:

2.创建项目文件结构

3.POM依赖

如果使用阿里云的连接池不选择JDBC,小编用的阿里云这里不选择

点击Finish;
注:可能Maven中无Jar包需要从仓库下载,需要耐心等待(可以去听首歌)

4.项目结构

5.POM

<?xml version="1.0" encoding="UTF-8"?>


4.0.0

org.springframework.boot
spring-boot-starter-parent
2.1.1.RELEASE


com.spring
boot
0.0.1-SNAPSHOT
boot
Demo project for Spring Boot

<properties>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <!-- Springboot 热部署 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
    </dependency>
    <!-- 阿里的Druid连接池 -->
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>druid-spring-boot-starter</artifactId>
        <version>1.1.10</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.mybatis.spring.boot</groupId>
        <artifactId>mybatis-spring-boot-starter</artifactId>
        <version>1.3.2</version>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>
注:IDEA失效解决方法

6.小编使用的application.properties文件,项目启动识别两种格式的文件properties和yml文件:

#缓存设置为false, 修改之后马上生效
spring.thymeleaf.cache=false
spring.thymeleaf.encoding=UTF-8
#spring.thymeleaf.prefix=classpath:/templates/
#spring.thymeleaf.suffix=.html

server.port=8080
server.tomcat.uriEncoding=utf-8

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;

public class User {

public Integer uid;
public String uname;
public String upassword;

public Integer getUid() {
    return uid;
}

public void setUid(Integer uid) {
    this.uid = uid;
}

public String getUanme() {
    return uname;
}

public void setUanme(String uanme) {
    this.uname = uanme;
}

public String getUpassword() {
    return upassword;
}

public void setUpassword(String upassword) {
    this.upassword = upassword;
}

@Override
public String toString() {
    return "User{" +
            "uid=" + uid +
            ", uname='" + uname + '\'' +
            ", upassword='" + upassword + '\'' +
            '}';
}

}
UserDao.java

注解的形式,小编感觉比XML好用

package com.spring.boot.dao;

import com.spring.boot.bean.User;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface UserDao {

@Select("select * from user")
public List<User> AllUser();

@Update("<script> " + "update user" +
        "<set>"+  "<if test='uname!=null'>uname=#{uname},</if>"+
        "<if test='upassword!=null'>upassword=#{upassword},</if>"+
        "</set>"+ "where uid=#{uid}"+
        " </script> ")
public int Update(User user);

}
UserService.java

package com.spring.boot.service;

import com.spring.boot.bean.User;

import java.util.List;

public interface UserService {

public List<User> AllUser();

public int Update(User user);

}

UserImpl.java
主要是注解问题Service可以命名,主要还是看自己的日常使用

package com.spring.boot.service.impl;

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;

import java.util.List;

@Service
public class UserImpl implements UserService {

@Autowired
private UserDao userDao;

@Override
public List<User> AllUser() {

    return userDao.AllUser();
}

@Override
public int Update(User user) {
    return userDao.Update(user);
}

}
注:userDao报红解决方法

UserController.java

package com.spring.boot.controller;

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;

@Controller
public class UserController {

@Autowired
private UserImpl userimpl;

@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";
}

}
index.html

Title Spring boot+Thymeleaf!
8.界面显示

注:后续功能再写!
小编这是Java web项目,@Controller注解是界面、@RestController是写接口
哪里又不对的给提醒


作者:沐荔
来源:CSDN
QQ群:810853011

作者:沐荔
来源:CSDN
原文:https://blog.csdn.net/qq_41920732/article/details/85936063
版权声明:本文为博主原创文章,转载请附上博文链接!前言

Spring boot + Mybatis + Thymeleaf + Druid +mySql

开发环境(小编使用的版本)

JDK版本 :1.8及以上 (JDK1.8);
开发工具 :Intellij IDEA (IDEA2018.2);
服务器 :Tomcat(务必比JDK版本高,小编不在解释(Jar包不用配置、War需要配置)) (Tomcat9) ;
JRE包 :Maven仓库 (Maven3.6);
数据库 :MySql(MySql5.5) ;
正题

Spring boot :2.1.1RELEASE ;

Thymeleaf

Mybatis

阿里云的连接池 : Druid ;

步骤

1.创建Springboot:

2.创建项目文件结构

3.POM依赖

如果使用阿里云的连接池不选择JDBC,小编用的阿里云这里不选择

点击Finish;
注:可能Maven中无Jar包需要从仓库下载,需要耐心等待(可以去听首歌)

4.项目结构

5.POM

<?xml version="1.0" encoding="UTF-8"?>


4.0.0

org.springframework.boot
spring-boot-starter-parent
2.1.1.RELEASE


com.spring
boot
0.0.1-SNAPSHOT
boot
Demo project for Spring Boot

<properties>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <!-- Springboot 热部署 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
    </dependency>
    <!-- 阿里的Druid连接池 -->
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>druid-spring-boot-starter</artifactId>
        <version>1.1.10</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.mybatis.spring.boot</groupId>
        <artifactId>mybatis-spring-boot-starter</artifactId>
        <version>1.3.2</version>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>
注:IDEA失效解决方法

6.小编使用的application.properties文件,项目启动识别两种格式的文件properties和yml文件:

#缓存设置为false, 修改之后马上生效
spring.thymeleaf.cache=false
spring.thymeleaf.encoding=UTF-8
#spring.thymeleaf.prefix=classpath:/templates/
#spring.thymeleaf.suffix=.html

server.port=8080
server.tomcat.uriEncoding=utf-8

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;

public class User {

public Integer uid;
public String uname;
public String upassword;

public Integer getUid() {
    return uid;
}

public void setUid(Integer uid) {
    this.uid = uid;
}

public String getUanme() {
    return uname;
}

public void setUanme(String uanme) {
    this.uname = uanme;
}

public String getUpassword() {
    return upassword;
}

public void setUpassword(String upassword) {
    this.upassword = upassword;
}

@Override
public String toString() {
    return "User{" +
            "uid=" + uid +
            ", uname='" + uname + '\'' +
            ", upassword='" + upassword + '\'' +
            '}';
}

}
UserDao.java

注解的形式,小编感觉比XML好用

package com.spring.boot.dao;

import com.spring.boot.bean.User;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface UserDao {

@Select("select * from user")
public List<User> AllUser();

@Update("<script> " + "update user" +
        "<set>"+  "<if test='uname!=null'>uname=#{uname},</if>"+
        "<if test='upassword!=null'>upassword=#{upassword},</if>"+
        "</set>"+ "where uid=#{uid}"+
        " </script> ")
public int Update(User user);

}
UserService.java

package com.spring.boot.service;

import com.spring.boot.bean.User;

import java.util.List;

public interface UserService {

public List<User> AllUser();

public int Update(User user);

}

UserImpl.java
主要是注解问题Service可以命名,主要还是看自己的日常使用

package com.spring.boot.service.impl;

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;

import java.util.List;

@Service
public class UserImpl implements UserService {

@Autowired
private UserDao userDao;

@Override
public List<User> AllUser() {

    return userDao.AllUser();
}

@Override
public int Update(User user) {
    return userDao.Update(user);
}

}
注:userDao报红解决方法

UserController.java

package com.spring.boot.controller;

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;

@Controller
public class UserController {

@Autowired
private UserImpl userimpl;

@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";
}

}
index.html

Title Spring boot+Thymeleaf!
8.界面显示

注:后续功能再写!
小编这是Java web项目,@Controller注解是界面、@RestController是写接口
哪里又不对的给提醒


作者:沐荔
来源:CSDN
QQ群:810853011

作者:沐荔
来源:CSDN
原文:https://blog.csdn.net/qq_41920732/article/details/85936063
版权声明:本文为博主原创文章,转载请附上博文链接!前言

Spring boot + Mybatis + Thymeleaf + Druid +mySql

开发环境(小编使用的版本)

JDK版本 :1.8及以上 (JDK1.8);
开发工具 :Intellij IDEA (IDEA2018.2);
服务器 :Tomcat(务必比JDK版本高,小编不在解释(Jar包不用配置、War需要配置)) (Tomcat9) ;
JRE包 :Maven仓库 (Maven3.6);
数据库 :MySql(MySql5.5) ;
正题

Spring boot :2.1.1RELEASE ;

Thymeleaf

Mybatis

阿里云的连接池 : Druid ;

步骤

1.创建Springboot:

2.创建项目文件结构

3.POM依赖

如果使用阿里云的连接池不选择JDBC,小编用的阿里云这里不选择

点击Finish;
注:可能Maven中无Jar包需要从仓库下载,需要耐心等待(可以去听首歌)

4.项目结构

5.POM

<?xml version="1.0" encoding="UTF-8"?>


4.0.0

org.springframework.boot
spring-boot-starter-parent
2.1.1.RELEASE


com.spring
boot
0.0.1-SNAPSHOT
boot
Demo project for Spring Boot

<properties>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <!-- Springboot 热部署 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
    </dependency>
    <!-- 阿里的Druid连接池 -->
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>druid-spring-boot-starter</artifactId>
        <version>1.1.10</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.mybatis.spring.boot</groupId>
        <artifactId>mybatis-spring-boot-starter</artifactId>
        <version>1.3.2</version>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>
注:IDEA失效解决方法

6.小编使用的application.properties文件,项目启动识别两种格式的文件properties和yml文件:

#缓存设置为false, 修改之后马上生效
spring.thymeleaf.cache=false
spring.thymeleaf.encoding=UTF-8
#spring.thymeleaf.prefix=classpath:/templates/
#spring.thymeleaf.suffix=.html

server.port=8080
server.tomcat.uriEncoding=utf-8

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;

public class User {

public Integer uid;
public String uname;
public String upassword;

public Integer getUid() {
    return uid;
}

public void setUid(Integer uid) {
    this.uid = uid;
}

public String getUanme() {
    return uname;
}

public void setUanme(String uanme) {
    this.uname = uanme;
}

public String getUpassword() {
    return upassword;
}

public void setUpassword(String upassword) {
    this.upassword = upassword;
}

@Override
public String toString() {
    return "User{" +
            "uid=" + uid +
            ", uname='" + uname + '\'' +
            ", upassword='" + upassword + '\'' +
            '}';
}

}
UserDao.java

注解的形式,小编感觉比XML好用

package com.spring.boot.dao;

import com.spring.boot.bean.User;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface UserDao {

@Select("select * from user")
public List<User> AllUser();

@Update("<script> " + "update user" +
        "<set>"+  "<if test='uname!=null'>uname=#{uname},</if>"+
        "<if test='upassword!=null'>upassword=#{upassword},</if>"+
        "</set>"+ "where uid=#{uid}"+
        " </script> ")
public int Update(User user);

}
UserService.java

package com.spring.boot.service;

import com.spring.boot.bean.User;

import java.util.List;

public interface UserService {

public List<User> AllUser();

public int Update(User user);

}

UserImpl.java
主要是注解问题Service可以命名,主要还是看自己的日常使用

package com.spring.boot.service.impl;

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;

import java.util.List;

@Service
public class UserImpl implements UserService {

@Autowired
private UserDao userDao;

@Override
public List<User> AllUser() {

    return userDao.AllUser();
}

@Override
public int Update(User user) {
    return userDao.Update(user);
}

}
注:userDao报红解决方法

UserController.java

package com.spring.boot.controller;

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;

@Controller
public class UserController {

@Autowired
private UserImpl userimpl;

@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";
}

}
index.html

Title Spring boot+Thymeleaf!
8.界面显示

注:后续功能再写!
小编这是Java web项目,@Controller注解是界面、@RestController是写接口
哪里又不对的给提醒


作者:沐荔
来源:CSDN
QQ群:810853011

作者:沐荔
来源:CSDN
原文:https://blog.csdn.net/qq_41920732/article/details/85936063
版权声明:本文为博主原创文章,转载请附上博文链接!前言

Spring boot + Mybatis + Thymeleaf + Druid +mySql

开发环境(小编使用的版本)

JDK版本 :1.8及以上 (JDK1.8);
开发工具 :Intellij IDEA (IDEA2018.2);
服务器 :Tomcat(务必比JDK版本高,小编不在解释(Jar包不用配置、War需要配置)) (Tomcat9) ;
JRE包 :Maven仓库 (Maven3.6);
数据库 :MySql(MySql5.5) ;
正题

Spring boot :2.1.1RELEASE ;

Thymeleaf

Mybatis

阿里云的连接池 : Druid ;

步骤

1.创建Springboot:

2.创建项目文件结构

3.POM依赖

如果使用阿里云的连接池不选择JDBC,小编用的阿里云这里不选择

点击Finish;
注:可能Maven中无Jar包需要从仓库下载,需要耐心等待(可以去听首歌)

4.项目结构

5.POM

<?xml version="1.0" encoding="UTF-8"?>


4.0.0

org.springframework.boot
spring-boot-starter-parent
2.1.1.RELEASE


com.spring
boot
0.0.1-SNAPSHOT
boot
Demo project for Spring Boot

<properties>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <!-- Springboot 热部署 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
    </dependency>
    <!-- 阿里的Druid连接池 -->
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>druid-spring-boot-starter</artifactId>
        <version>1.1.10</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.mybatis.spring.boot</groupId>
        <artifactId>mybatis-spring-boot-starter</artifactId>
        <version>1.3.2</version>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>
注:IDEA失效解决方法

6.小编使用的application.properties文件,项目启动识别两种格式的文件properties和yml文件:

#缓存设置为false, 修改之后马上生效
spring.thymeleaf.cache=false
spring.thymeleaf.encoding=UTF-8
#spring.thymeleaf.prefix=classpath:/templates/
#spring.thymeleaf.suffix=.html

server.port=8080
server.tomcat.uriEncoding=utf-8

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;

public class User {

public Integer uid;
public String uname;
public String upassword;

public Integer getUid() {
    return uid;
}

public void setUid(Integer uid) {
    this.uid = uid;
}

public String getUanme() {
    return uname;
}

public void setUanme(String uanme) {
    this.uname = uanme;
}

public String getUpassword() {
    return upassword;
}

public void setUpassword(String upassword) {
    this.upassword = upassword;
}

@Override
public String toString() {
    return "User{" +
            "uid=" + uid +
            ", uname='" + uname + '\'' +
            ", upassword='" + upassword + '\'' +
            '}';
}

}
UserDao.java

注解的形式,小编感觉比XML好用

package com.spring.boot.dao;

import com.spring.boot.bean.User;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface UserDao {

@Select("select * from user")
public List<User> AllUser();

@Update("<script> " + "update user" +
        "<set>"+  "<if test='uname!=null'>uname=#{uname},</if>"+
        "<if test='upassword!=null'>upassword=#{upassword},</if>"+
        "</set>"+ "where uid=#{uid}"+
        " </script> ")
public int Update(User user);

}
UserService.java

package com.spring.boot.service;

import com.spring.boot.bean.User;

import java.util.List;

public interface UserService {

public List<User> AllUser();

public int Update(User user);

}

UserImpl.java
主要是注解问题Service可以命名,主要还是看自己的日常使用

package com.spring.boot.service.impl;

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;

import java.util.List;

@Service
public class UserImpl implements UserService {

@Autowired
private UserDao userDao;

@Override
public List<User> AllUser() {

    return userDao.AllUser();
}

@Override
public int Update(User user) {
    return userDao.Update(user);
}

}
注:userDao报红解决方法

UserController.java

package com.spring.boot.controller;

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;

@Controller
public class UserController {

@Autowired
private UserImpl userimpl;

@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";
}

}
index.html

Title Spring boot+Thymeleaf!
8.界面显示

注:后续功能再写!
小编这是Java web项目,@Controller注解是界面、@RestController是写接口
哪里又不对的给提醒


作者:沐荔
来源:CSDN
QQ群:810853011

作者:沐荔
来源:CSDN
原文:https://blog.csdn.net/qq_41920732/article/details/85936063
版权声明:本文为博主原创文章,转载请附上博文链接!前言

Spring boot + Mybatis + Thymeleaf + Druid +mySql

开发环境(小编使用的版本)

JDK版本 :1.8及以上 (JDK1.8);
开发工具 :Intellij IDEA (IDEA2018.2);
服务器 :Tomcat(务必比JDK版本高,小编不在解释(Jar包不用配置、War需要配置)) (Tomcat9) ;
JRE包 :Maven仓库 (Maven3.6);
数据库 :MySql(MySql5.5) ;
正题

Spring boot :2.1.1RELEASE ;

Thymeleaf

Mybatis

阿里云的连接池 : Druid ;

步骤

1.创建Springboot:

2.创建项目文件结构

3.POM依赖

如果使用阿里云的连接池不选择JDBC,小编用的阿里云这里不选择

点击Finish;
注:可能Maven中无Jar包需要从仓库下载,需要耐心等待(可以去听首歌)

4.项目结构

5.POM

<?xml version="1.0" encoding="UTF-8"?>


4.0.0

org.springframework.boot
spring-boot-starter-parent
2.1.1.RELEASE


com.spring
boot
0.0.1-SNAPSHOT
boot
Demo project for Spring Boot

<properties>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <!-- Springboot 热部署 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
    </dependency>
    <!-- 阿里的Druid连接池 -->
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>druid-spring-boot-starter</artifactId>
        <version>1.1.10</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.mybatis.spring.boot</groupId>
        <artifactId>mybatis-spring-boot-starter</artifactId>
        <version>1.3.2</version>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>
注:IDEA失效解决方法

6.小编使用的application.properties文件,项目启动识别两种格式的文件properties和yml文件:

#缓存设置为false, 修改之后马上生效
spring.thymeleaf.cache=false
spring.thymeleaf.encoding=UTF-8
#spring.thymeleaf.prefix=classpath:/templates/
#spring.thymeleaf.suffix=.html

server.port=8080
server.tomcat.uriEncoding=utf-8

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;

public class User {

public Integer uid;
public String uname;
public String upassword;

public Integer getUid() {
    return uid;
}

public void setUid(Integer uid) {
    this.uid = uid;
}

public String getUanme() {
    return uname;
}

public void setUanme(String uanme) {
    this.uname = uanme;
}

public String getUpassword() {
    return upassword;
}

public void setUpassword(String upassword) {
    this.upassword = upassword;
}

@Override
public String toString() {
    return "User{" +
            "uid=" + uid +
            ", uname='" + uname + '\'' +
            ", upassword='" + upassword + '\'' +
            '}';
}

}
UserDao.java

注解的形式,小编感觉比XML好用

package com.spring.boot.dao;

import com.spring.boot.bean.User;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface UserDao {

@Select("select * from user")
public List<User> AllUser();

@Update("<script> " + "update user" +
        "<set>"+  "<if test='uname!=null'>uname=#{uname},</if>"+
        "<if test='upassword!=null'>upassword=#{upassword},</if>"+
        "</set>"+ "where uid=#{uid}"+
        " </script> ")
public int Update(User user);

}
UserService.java

package com.spring.boot.service;

import com.spring.boot.bean.User;

import java.util.List;

public interface UserService {

public List<User> AllUser();

public int Update(User user);

}

UserImpl.java
主要是注解问题Service可以命名,主要还是看自己的日常使用

package com.spring.boot.service.impl;

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;

import java.util.List;

@Service
public class UserImpl implements UserService {

@Autowired
private UserDao userDao;

@Override
public List<User> AllUser() {

    return userDao.AllUser();
}

@Override
public int Update(User user) {
    return userDao.Update(user);
}

}
注:userDao报红解决方法

UserController.java

package com.spring.boot.controller;

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;

@Controller
public class UserController {

@Autowired
private UserImpl userimpl;

@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";
}

}
index.html

Title Spring boot+Thymeleaf!
8.界面显示

注:后续功能再写!
小编这是Java web项目,@Controller注解是界面、@RestController是写接口
哪里又不对的给提醒


作者:沐荔
来源:CSDN
QQ群:810853011

作者:沐荔
来源:CSDN
原文:https://blog.csdn.net/qq_41920732/article/details/85936063
版权声明:本文为博主原创文章,转载请附上博文链接!前言

Spring boot + Mybatis + Thymeleaf + Druid +mySql

开发环境(小编使用的版本)

JDK版本 :1.8及以上 (JDK1.8);
开发工具 :Intellij IDEA (IDEA2018.2);
服务器 :Tomcat(务必比JDK版本高,小编不在解释(Jar包不用配置、War需要配置)) (Tomcat9) ;
JRE包 :Maven仓库 (Maven3.6);
数据库 :MySql(MySql5.5) ;
正题

Spring boot :2.1.1RELEASE ;

Thymeleaf

Mybatis

阿里云的连接池 : Druid ;

步骤

1.创建Springboot:

2.创建项目文件结构

3.POM依赖

如果使用阿里云的连接池不选择JDBC,小编用的阿里云这里不选择

点击Finish;
注:可能Maven中无Jar包需要从仓库下载,需要耐心等待(可以去听首歌)

4.项目结构

5.POM

<?xml version="1.0" encoding="UTF-8"?>


4.0.0

org.springframework.boot
spring-boot-starter-parent
2.1.1.RELEASE


com.spring
boot
0.0.1-SNAPSHOT
boot
Demo project for Spring Boot

<properties>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <!-- Springboot 热部署 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
    </dependency>
    <!-- 阿里的Druid连接池 -->
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>druid-spring-boot-starter</artifactId>
        <version>1.1.10</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.mybatis.spring.boot</groupId>
        <artifactId>mybatis-spring-boot-starter</artifactId>
        <version>1.3.2</version>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>
注:IDEA失效解决方法

6.小编使用的application.properties文件,项目启动识别两种格式的文件properties和yml文件:

#缓存设置为false, 修改之后马上生效
spring.thymeleaf.cache=false
spring.thymeleaf.encoding=UTF-8
#spring.thymeleaf.prefix=classpath:/templates/
#spring.thymeleaf.suffix=.html

server.port=8080
server.tomcat.uriEncoding=utf-8

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;

public class User {

public Integer uid;
public String uname;
public String upassword;

public Integer getUid() {
    return uid;
}

public void setUid(Integer uid) {
    this.uid = uid;
}

public String getUanme() {
    return uname;
}

public void setUanme(String uanme) {
    this.uname = uanme;
}

public String getUpassword() {
    return upassword;
}

public void setUpassword(String upassword) {
    this.upassword = upassword;
}

@Override
public String toString() {
    return "User{" +
            "uid=" + uid +
            ", uname='" + uname + '\'' +
            ", upassword='" + upassword + '\'' +
            '}';
}

}
UserDao.java

注解的形式,小编感觉比XML好用

package com.spring.boot.dao;

import com.spring.boot.bean.User;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface UserDao {

@Select("select * from user")
public List<User> AllUser();

@Update("<script> " + "update user" +
        "<set>"+  "<if test='uname!=null'>uname=#{uname},</if>"+
        "<if test='upassword!=null'>upassword=#{upassword},</if>"+
        "</set>"+ "where uid=#{uid}"+
        " </script> ")
public int Update(User user);

}
UserService.java

package com.spring.boot.service;

import com.spring.boot.bean.User;

import java.util.List;

public interface UserService {

public List<User> AllUser();

public int Update(User user);

}

UserImpl.java
主要是注解问题Service可以命名,主要还是看自己的日常使用

package com.spring.boot.service.impl;

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;

import java.util.List;

@Service
public class UserImpl implements UserService {

@Autowired
private UserDao userDao;

@Override
public List<User> AllUser() {

    return userDao.AllUser();
}

@Override
public int Update(User user) {
    return userDao.Update(user);
}

}
注:userDao报红解决方法

UserController.java

package com.spring.boot.controller;

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;

@Controller
public class UserController {

@Autowired
private UserImpl userimpl;

@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";
}

}
index.html

Title Spring boot+Thymeleaf!
8.界面显示

注:后续功能再写!
小编这是Java web项目,@Controller注解是界面、@RestController是写接口
哪里又不对的给提醒


作者:沐荔
来源:CSDN
QQ群:810853011

作者:沐荔
来源:CSDN
原文:https://blog.csdn.net/qq_41920732/article/details/85936063
版权声明:本文为博主原创文章,转载请附上博文链接!前言

Spring boot + Mybatis + Thymeleaf + Druid +mySql

开发环境(小编使用的版本)

JDK版本 :1.8及以上 (JDK1.8);
开发工具 :Intellij IDEA (IDEA2018.2);
服务器 :Tomcat(务必比JDK版本高,小编不在解释(Jar包不用配置、War需要配置)) (Tomcat9) ;
JRE包 :Maven仓库 (Maven3.6);
数据库 :MySql(MySql5.5) ;
正题

Spring boot :2.1.1RELEASE ;

Thymeleaf

Mybatis

阿里云的连接池 : Druid ;

步骤

1.创建Springboot:

2.创建项目文件结构

3.POM依赖

如果使用阿里云的连接池不选择JDBC,小编用的阿里云这里不选择

点击Finish;
注:可能Maven中无Jar包需要从仓库下载,需要耐心等待(可以去听首歌)

4.项目结构

5.POM

<?xml version="1.0" encoding="UTF-8"?>


4.0.0

org.springframework.boot
spring-boot-starter-parent
2.1.1.RELEASE


com.spring
boot
0.0.1-SNAPSHOT
boot
Demo project for Spring Boot

<properties>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <!-- Springboot 热部署 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
    </dependency>
    <!-- 阿里的Druid连接池 -->
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>druid-spring-boot-starter</artifactId>
        <version>1.1.10</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.mybatis.spring.boot</groupId>
        <artifactId>mybatis-spring-boot-starter</artifactId>
        <version>1.3.2</version>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>
注:IDEA失效解决方法

6.小编使用的application.properties文件,项目启动识别两种格式的文件properties和yml文件:

#缓存设置为false, 修改之后马上生效
spring.thymeleaf.cache=false
spring.thymeleaf.encoding=UTF-8
#spring.thymeleaf.prefix=classpath:/templates/
#spring.thymeleaf.suffix=.html

server.port=8080
server.tomcat.uriEncoding=utf-8

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;

public class User {

public Integer uid;
public String uname;
public String upassword;

public Integer getUid() {
    return uid;
}

public void setUid(Integer uid) {
    this.uid = uid;
}

public String getUanme() {
    return uname;
}

public void setUanme(String uanme) {
    this.uname = uanme;
}

public String getUpassword() {
    return upassword;
}

public void setUpassword(String upassword) {
    this.upassword = upassword;
}

@Override
public String toString() {
    return "User{" +
            "uid=" + uid +
            ", uname='" + uname + '\'' +
            ", upassword='" + upassword + '\'' +
            '}';
}

}
UserDao.java

注解的形式,小编感觉比XML好用

package com.spring.boot.dao;

import com.spring.boot.bean.User;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface UserDao {

@Select("select * from user")
public List<User> AllUser();

@Update("<script> " + "update user" +
        "<set>"+  "<if test='uname!=null'>uname=#{uname},</if>"+
        "<if test='upassword!=null'>upassword=#{upassword},</if>"+
        "</set>"+ "where uid=#{uid}"+
        " </script> ")
public int Update(User user);

}
UserService.java

package com.spring.boot.service;

import com.spring.boot.bean.User;

import java.util.List;

public interface UserService {

public List<User> AllUser();

public int Update(User user);

}

UserImpl.java
主要是注解问题Service可以命名,主要还是看自己的日常使用

package com.spring.boot.service.impl;

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;

import java.util.List;

@Service
public class UserImpl implements UserService {

@Autowired
private UserDao userDao;

@Override
public List<User> AllUser() {

    return userDao.AllUser();
}

@Override
public int Update(User user) {
    return userDao.Update(user);
}

}
注:userDao报红解决方法

UserController.java

package com.spring.boot.controller;

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;

@Controller
public class UserController {

@Autowired
private UserImpl userimpl;

@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";
}

}
index.html

Title Spring boot+Thymeleaf!
8.界面显示

注:后续功能再写!
小编这是Java web项目,@Controller注解是界面、@RestController是写接口
哪里又不对的给提醒


作者:沐荔
来源:CSDN
QQ群:810853011

作者:沐荔
来源:CSDN
原文:https://blog.csdn.net/qq_41920732/article/details/85936063
版权声明:本文为博主原创文章,转载请附上博文链接!前言

Spring boot + Mybatis + Thymeleaf + Druid +mySql

开发环境(小编使用的版本)

JDK版本 :1.8及以上 (JDK1.8);
开发工具 :Intellij IDEA (IDEA2018.2);
服务器 :Tomcat(务必比JDK版本高,小编不在解释(Jar包不用配置、War需要配置)) (Tomcat9) ;
JRE包 :Maven仓库 (Maven3.6);
数据库 :MySql(MySql5.5) ;
正题

Spring boot :2.1.1RELEASE ;

Thymeleaf

Mybatis

阿里云的连接池 : Druid ;

步骤

1.创建Springboot:

2.创建项目文件结构

3.POM依赖

如果使用阿里云的连接池不选择JDBC,小编用的阿里云这里不选择

点击Finish;
注:可能Maven中无Jar包需要从仓库下载,需要耐心等待(可以去听首歌)

4.项目结构

5.POM

<?xml version="1.0" encoding="UTF-8"?>


4.0.0

org.springframework.boot
spring-boot-starter-parent
2.1.1.RELEASE


com.spring
boot
0.0.1-SNAPSHOT
boot
Demo project for Spring Boot

<properties>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <!-- Springboot 热部署 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
    </dependency>
    <!-- 阿里的Druid连接池 -->
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>druid-spring-boot-starter</artifactId>
        <version>1.1.10</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.mybatis.spring.boot</groupId>
        <artifactId>mybatis-spring-boot-starter</artifactId>
        <version>1.3.2</version>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>
注:IDEA失效解决方法

6.小编使用的application.properties文件,项目启动识别两种格式的文件properties和yml文件:

#缓存设置为false, 修改之后马上生效
spring.thymeleaf.cache=false
spring.thymeleaf.encoding=UTF-8
#spring.thymeleaf.prefix=classpath:/templates/
#spring.thymeleaf.suffix=.html

server.port=8080
server.tomcat.uriEncoding=utf-8

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;

public class User {

public Integer uid;
public String uname;
public String upassword;

public Integer getUid() {
    return uid;
}

public void setUid(Integer uid) {
    this.uid = uid;
}

public String getUanme() {
    return uname;
}

public void setUanme(String uanme) {
    this.uname = uanme;
}

public String getUpassword() {
    return upassword;
}

public void setUpassword(String upassword) {
    this.upassword = upassword;
}

@Override
public String toString() {
    return "User{" +
            "uid=" + uid +
            ", uname='" + uname + '\'' +
            ", upassword='" + upassword + '\'' +
            '}';
}

}
UserDao.java

注解的形式,小编感觉比XML好用

package com.spring.boot.dao;

import com.spring.boot.bean.User;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface UserDao {

@Select("select * from user")
public List<User> AllUser();

@Update("<script> " + "update user" +
        "<set>"+  "<if test='uname!=null'>uname=#{uname},</if>"+
        "<if test='upassword!=null'>upassword=#{upassword},</if>"+
        "</set>"+ "where uid=#{uid}"+
        " </script> ")
public int Update(User user);

}
UserService.java

package com.spring.boot.service;

import com.spring.boot.bean.User;

import java.util.List;

public interface UserService {

public List<User> AllUser();

public int Update(User user);

}

UserImpl.java
主要是注解问题Service可以命名,主要还是看自己的日常使用

package com.spring.boot.service.impl;

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;

import java.util.List;

@Service
public class UserImpl implements UserService {

@Autowired
private UserDao userDao;

@Override
public List<User> AllUser() {

    return userDao.AllUser();
}

@Override
public int Update(User user) {
    return userDao.Update(user);
}

}
注:userDao报红解决方法

UserController.java

package com.spring.boot.controller;

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;

@Controller
public class UserController {

@Autowired
private UserImpl userimpl;

@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";
}

}
index.html

Title Spring boot+Thymeleaf!
8.界面显示

注:后续功能再写!
小编这是Java web项目,@Controller注解是界面、@RestController是写接口
哪里又不对的给提醒


作者:沐荔
来源:CSDN
QQ群:810853011

作者:沐荔
来源:CSDN
原文:https://blog.csdn.net/qq_41920732/article/details/85936063
版权声明:本文为博主原创文章,转载请附上博文链接!前言

Spring boot + Mybatis + Thymeleaf + Druid +mySql

开发环境(小编使用的版本)

JDK版本 :1.8及以上 (JDK1.8);
开发工具 :Intellij IDEA (IDEA2018.2);
服务器 :Tomcat(务必比JDK版本高,小编不在解释(Jar包不用配置、War需要配置)) (Tomcat9) ;
JRE包 :Maven仓库 (Maven3.6);
数据库 :MySql(MySql5.5) ;
正题

Spring boot :2.1.1RELEASE ;

Thymeleaf

Mybatis

阿里云的连接池 : Druid ;

步骤

1.创建Springboot:

2.创建项目文件结构

3.POM依赖

如果使用阿里云的连接池不选择JDBC,小编用的阿里云这里不选择

点击Finish;
注:可能Maven中无Jar包需要从仓库下载,需要耐心等待(可以去听首歌)

4.项目结构

5.POM

<?xml version="1.0" encoding="UTF-8"?>


4.0.0

org.springframework.boot
spring-boot-starter-parent
2.1.1.RELEASE


com.spring
boot
0.0.1-SNAPSHOT
boot
Demo project for Spring Boot

<properties>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <!-- Springboot 热部署 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
    </dependency>
    <!-- 阿里的Druid连接池 -->
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>druid-spring-boot-starter</artifactId>
        <version>1.1.10</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.mybatis.spring.boot</groupId>
        <artifactId>mybatis-spring-boot-starter</artifactId>
        <version>1.3.2</version>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>
注:IDEA失效解决方法

6.小编使用的application.properties文件,项目启动识别两种格式的文件properties和yml文件:

#缓存设置为false, 修改之后马上生效
spring.thymeleaf.cache=false
spring.thymeleaf.encoding=UTF-8
#spring.thymeleaf.prefix=classpath:/templates/
#spring.thymeleaf.suffix=.html

server.port=8080
server.tomcat.uriEncoding=utf-8

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;

public class User {

public Integer uid;
public String uname;
public String upassword;

public Integer getUid() {
    return uid;
}

public void setUid(Integer uid) {
    this.uid = uid;
}

public String getUanme() {
    return uname;
}

public void setUanme(String uanme) {
    this.uname = uanme;
}

public String getUpassword() {
    return upassword;
}

public void setUpassword(String upassword) {
    this.upassword = upassword;
}

@Override
public String toString() {
    return "User{" +
            "uid=" + uid +
            ", uname='" + uname + '\'' +
            ", upassword='" + upassword + '\'' +
            '}';
}

}
UserDao.java

注解的形式,小编感觉比XML好用

package com.spring.boot.dao;

import com.spring.boot.bean.User;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface UserDao {

@Select("select * from user")
public List<User> AllUser();

@Update("<script> " + "update user" +
        "<set>"+  "<if test='uname!=null'>uname=#{uname},</if>"+
        "<if test='upassword!=null'>upassword=#{upassword},</if>"+
        "</set>"+ "where uid=#{uid}"+
        " </script> ")
public int Update(User user);

}
UserService.java

package com.spring.boot.service;

import com.spring.boot.bean.User;

import java.util.List;

public interface UserService {

public List<User> AllUser();

public int Update(User user);

}

UserImpl.java
主要是注解问题Service可以命名,主要还是看自己的日常使用

package com.spring.boot.service.impl;

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;

import java.util.List;

@Service
public class UserImpl implements UserService {

@Autowired
private UserDao userDao;

@Override
public List<User> AllUser() {

    return userDao.AllUser();
}

@Override
public int Update(User user) {
    return userDao.Update(user);
}

}
注:userDao报红解决方法

UserController.java

package com.spring.boot.controller;

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;

@Controller
public class UserController {

@Autowired
private UserImpl userimpl;

@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";
}

}
index.html

Title Spring boot+Thymeleaf!
8.界面显示

注:后续功能再写!
小编这是Java web项目,@Controller注解是界面、@RestController是写接口
哪里又不对的给提醒


作者:沐荔
来源:CSDN
QQ群:810853011

作者:沐荔
来源:CSDN
原文:https://blog.csdn.net/qq_41920732/article/details/85936063
版权声明:本文为博主原创文章,转载请附上博文链接!前言

Spring boot + Mybatis + Thymeleaf + Druid +mySql

开发环境(小编使用的版本)

JDK版本 :1.8及以上 (JDK1.8);
开发工具 :Intellij IDEA (IDEA2018.2);
服务器 :Tomcat(务必比JDK版本高,小编不在解释(Jar包不用配置、War需要配置)) (Tomcat9) ;
JRE包 :Maven仓库 (Maven3.6);
数据库 :MySql(MySql5.5) ;
正题

Spring boot :2.1.1RELEASE ;

Thymeleaf

Mybatis

阿里云的连接池 : Druid ;

步骤

1.创建Springboot:

2.创建项目文件结构

3.POM依赖

如果使用阿里云的连接池不选择JDBC,小编用的阿里云这里不选择

点击Finish;
注:可能Maven中无Jar包需要从仓库下载,需要耐心等待(可以去听首歌)

4.项目结构

5.POM

<?xml version="1.0" encoding="UTF-8"?>


4.0.0

org.springframework.boot
spring-boot-starter-parent
2.1.1.RELEASE


com.spring
boot
0.0.1-SNAPSHOT
boot
Demo project for Spring Boot

<properties>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <!-- Springboot 热部署 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
    </dependency>
    <!-- 阿里的Druid连接池 -->
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>druid-spring-boot-starter</artifactId>
        <version>1.1.10</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.mybatis.spring.boot</groupId>
        <artifactId>mybatis-spring-boot-starter</artifactId>
        <version>1.3.2</version>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>
注:IDEA失效解决方法

6.小编使用的application.properties文件,项目启动识别两种格式的文件properties和yml文件:

#缓存设置为false, 修改之后马上生效
spring.thymeleaf.cache=false
spring.thymeleaf.encoding=UTF-8
#spring.thymeleaf.prefix=classpath:/templates/
#spring.thymeleaf.suffix=.html

server.port=8080
server.tomcat.uriEncoding=utf-8

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;

public class User {

public Integer uid;
public String uname;
public String upassword;

public Integer getUid() {
    return uid;
}

public void setUid(Integer uid) {
    this.uid = uid;
}

public String getUanme() {
    return uname;
}

public void setUanme(String uanme) {
    this.uname = uanme;
}

public String getUpassword() {
    return upassword;
}

public void setUpassword(String upassword) {
    this.upassword = upassword;
}

@Override
public String toString() {
    return "User{" +
            "uid=" + uid +
            ", uname='" + uname + '\'' +
            ", upassword='" + upassword + '\'' +
            '}';
}

}
UserDao.java

注解的形式,小编感觉比XML好用

package com.spring.boot.dao;

import com.spring.boot.bean.User;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface UserDao {

@Select("select * from user")
public List<User> AllUser();

@Update("<script> " + "update user" +
        "<set>"+  "<if test='uname!=null'>uname=#{uname},</if>"+
        "<if test='upassword!=null'>upassword=#{upassword},</if>"+
        "</set>"+ "where uid=#{uid}"+
        " </script> ")
public int Update(User user);

}
UserService.java

package com.spring.boot.service;

import com.spring.boot.bean.User;

import java.util.List;

public interface UserService {

public List<User> AllUser();

public int Update(User user);

}

UserImpl.java
主要是注解问题Service可以命名,主要还是看自己的日常使用

package com.spring.boot.service.impl;

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;

import java.util.List;

@Service
public class UserImpl implements UserService {

@Autowired
private UserDao userDao;

@Override
public List<User> AllUser() {

    return userDao.AllUser();
}

@Override
public int Update(User user) {
    return userDao.Update(user);
}

}
注:userDao报红解决方法

UserController.java

package com.spring.boot.controller;

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;

@Controller
public class UserController {

@Autowired
private UserImpl userimpl;

@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";
}

}
index.html

Title Spring boot+Thymeleaf!
8.界面显示

注:后续功能再写!
小编这是Java web项目,@Controller注解是界面、@RestController是写接口
哪里又不对的给提醒


作者:沐荔
来源:CSDN
QQ群:810853011

作者:沐荔
来源:CSDN
原文:https://blog.csdn.net/qq_41920732/article/details/85936063
版权声明:本文为博主原创文章,转载请附上博文链接!前言

Spring boot + Mybatis + Thymeleaf + Druid +mySql

开发环境(小编使用的版本)

JDK版本 :1.8及以上 (JDK1.8);
开发工具 :Intellij IDEA (IDEA2018.2);
服务器 :Tomcat(务必比JDK版本高,小编不在解释(Jar包不用配置、War需要配置)) (Tomcat9) ;
JRE包 :Maven仓库 (Maven3.6);
数据库 :MySql(MySql5.5) ;
正题

Spring boot :2.1.1RELEASE ;

Thymeleaf

Mybatis

阿里云的连接池 : Druid ;

步骤

1.创建Springboot:

2.创建项目文件结构

3.POM依赖

如果使用阿里云的连接池不选择JDBC,小编用的阿里云这里不选择

点击Finish;
注:可能Maven中无Jar包需要从仓库下载,需要耐心等待(可以去听首歌)

4.项目结构

5.POM

<?xml version="1.0" encoding="UTF-8"?>


4.0.0

org.springframework.boot
spring-boot-starter-parent
2.1.1.RELEASE


com.spring
boot
0.0.1-SNAPSHOT
boot
Demo project for Spring Boot

<properties>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <!-- Springboot 热部署 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
    </dependency>
    <!-- 阿里的Druid连接池 -->
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>druid-spring-boot-starter</artifactId>
        <version>1.1.10</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.mybatis.spring.boot</groupId>
        <artifactId>mybatis-spring-boot-starter</artifactId>
        <version>1.3.2</version>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>
注:IDEA失效解决方法

6.小编使用的application.properties文件,项目启动识别两种格式的文件properties和yml文件:

#缓存设置为false, 修改之后马上生效
spring.thymeleaf.cache=false
spring.thymeleaf.encoding=UTF-8
#spring.thymeleaf.prefix=classpath:/templates/
#spring.thymeleaf.suffix=.html

server.port=8080
server.tomcat.uriEncoding=utf-8

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;

public class User {

public Integer uid;
public String uname;
public String upassword;

public Integer getUid() {
    return uid;
}

public void setUid(Integer uid) {
    this.uid = uid;
}

public String getUanme() {
    return uname;
}

public void setUanme(String uanme) {
    this.uname = uanme;
}

public String getUpassword() {
    return upassword;
}

public void setUpassword(String upassword) {
    this.upassword = upassword;
}

@Override
public String toString() {
    return "User{" +
            "uid=" + uid +
            ", uname='" + uname + '\'' +
            ", upassword='" + upassword + '\'' +
            '}';
}

}
UserDao.java

注解的形式,小编感觉比XML好用

package com.spring.boot.dao;

import com.spring.boot.bean.User;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface UserDao {

@Select("select * from user")
public List<User> AllUser();

@Update("<script> " + "update user" +
        "<set>"+  "<if test='uname!=null'>uname=#{uname},</if>"+
        "<if test='upassword!=null'>upassword=#{upassword},</if>"+
        "</set>"+ "where uid=#{uid}"+
        " </script> ")
public int Update(User user);

}
UserService.java

package com.spring.boot.service;

import com.spring.boot.bean.User;

import java.util.List;

public interface UserService {

public List<User> AllUser();

public int Update(User user);

}

UserImpl.java
主要是注解问题Service可以命名,主要还是看自己的日常使用

package com.spring.boot.service.impl;

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;

import java.util.List;

@Service
public class UserImpl implements UserService {

@Autowired
private UserDao userDao;

@Override
public List<User> AllUser() {

    return userDao.AllUser();
}

@Override
public int Update(User user) {
    return userDao.Update(user);
}

}
注:userDao报红解决方法

UserController.java

package com.spring.boot.controller;

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;

@Controller
public class UserController {

@Autowired
private UserImpl userimpl;

@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";
}

}
index.html

Title Spring boot+Thymeleaf!
8.界面显示

注:后续功能再写!
小编这是Java web项目,@Controller注解是界面、@RestController是写接口
哪里又不对的给提醒


作者:沐荔
来源:CSDN
QQ群:810853011

作者:沐荔
来源:CSDN
原文:https://blog.csdn.net/qq_41920732/article/details/85936063
版权声明:本文为博主原创文章,转载请附上博文链接!前言

Spring boot + Mybatis + Thymeleaf + Druid +mySql

开发环境(小编使用的版本)

JDK版本 :1.8及以上 (JDK1.8);
开发工具 :Intellij IDEA (IDEA2018.2);
服务器 :Tomcat(务必比JDK版本高,小编不在解释(Jar包不用配置、War需要配置)) (Tomcat9) ;
JRE包 :Maven仓库 (Maven3.6);
数据库 :MySql(MySql5.5) ;
正题

Spring boot :2.1.1RELEASE ;

Thymeleaf

Mybatis

阿里云的连接池 : Druid ;

步骤

1.创建Springboot:

2.创建项目文件结构

3.POM依赖

如果使用阿里云的连接池不选择JDBC,小编用的阿里云这里不选择

点击Finish;
注:可能Maven中无Jar包需要从仓库下载,需要耐心等待(可以去听首歌)

4.项目结构

5.POM

<?xml version="1.0" encoding="UTF-8"?>


4.0.0

org.springframework.boot
spring-boot-starter-parent
2.1.1.RELEASE


com.spring
boot
0.0.1-SNAPSHOT
boot
Demo project for Spring Boot

<properties>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <!-- Springboot 热部署 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
    </dependency>
    <!-- 阿里的Druid连接池 -->
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>druid-spring-boot-starter</artifactId>
        <version>1.1.10</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.mybatis.spring.boot</groupId>
        <artifactId>mybatis-spring-boot-starter</artifactId>
        <version>1.3.2</version>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>
注:IDEA失效解决方法

6.小编使用的application.properties文件,项目启动识别两种格式的文件properties和yml文件:

#缓存设置为false, 修改之后马上生效
spring.thymeleaf.cache=false
spring.thymeleaf.encoding=UTF-8
#spring.thymeleaf.prefix=classpath:/templates/
#spring.thymeleaf.suffix=.html

server.port=8080
server.tomcat.uriEncoding=utf-8

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;

public class User {

public Integer uid;
public String uname;
public String upassword;

public Integer getUid() {
    return uid;
}

public void setUid(Integer uid) {
    this.uid = uid;
}

public String getUanme() {
    return uname;
}

public void setUanme(String uanme) {
    this.uname = uanme;
}

public String getUpassword() {
    return upassword;
}

public void setUpassword(String upassword) {
    this.upassword = upassword;
}

@Override
public String toString() {
    return "User{" +
            "uid=" + uid +
            ", uname='" + uname + '\'' +
            ", upassword='" + upassword + '\'' +
            '}';
}

}
UserDao.java

注解的形式,小编感觉比XML好用

package com.spring.boot.dao;

import com.spring.boot.bean.User;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface UserDao {

@Select("select * from user")
public List<User> AllUser();

@Update("<script> " + "update user" +
        "<set>"+  "<if test='uname!=null'>uname=#{uname},</if>"+
        "<if test='upassword!=null'>upassword=#{upassword},</if>"+
        "</set>"+ "where uid=#{uid}"+
        " </script> ")
public int Update(User user);

}
UserService.java

package com.spring.boot.service;

import com.spring.boot.bean.User;

import java.util.List;

public interface UserService {

public List<User> AllUser();

public int Update(User user);

}

UserImpl.java
主要是注解问题Service可以命名,主要还是看自己的日常使用

package com.spring.boot.service.impl;

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;

import java.util.List;

@Service
public class UserImpl implements UserService {

@Autowired
private UserDao userDao;

@Override
public List<User> AllUser() {

    return userDao.AllUser();
}

@Override
public int Update(User user) {
    return userDao.Update(user);
}

}
注:userDao报红解决方法

UserController.java

package com.spring.boot.controller;

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;

@Controller
public class UserController {

@Autowired
private UserImpl userimpl;

@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";
}

}
index.html

Title Spring boot+Thymeleaf!
8.界面显示

注:后续功能再写!
小编这是Java web项目,@Controller注解是界面、@RestController是写接口
哪里又不对的给提醒

--------------------- 
作者:沐荔
来源:CSDN 
QQ群:810853011

作者:沐荔
来源:CSDN
原文:https://blog.csdn.net/qq_41920732/article/details/85936063
版权声明:本文为博主原创文章,转载请附上博文链接!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值