springboot+springmvc+mybatis+idea整合

用springboot+springmvc+mybatis+idea整合

  • 首先我的教程非常详细安照流出配置即可本教程适合idea的maven 环境完全搭好的环境
    • 新的改变
    • pom.xml配置
    • 所有文件配置
    • 需要注意的事情
    • 个人介绍

首先我的教程非常详细安照流出配置即可本教程适合idea的maven 环境完全搭好的环境

第一步创建一个maven工程
springboot+springmvc+mybatis+idea整合_第1张图片

新的改变

1.不用勾选Create from archetype
2.点击new
3.编写项目名
springboot+springmvc+mybatis+idea整合_第2张图片
4.点击new

springboot+springmvc+mybatis+idea整合_第3张图片
5.点击Finish
6.项目目录
springboot+springmvc+mybatis+idea整合_第4张图片
2. **全新的配置设计
**1.新建文件夹
springboot+springmvc+mybatis+idea整合_第5张图片
2.建好所有文件夹和文件

springboot+springmvc+mybatis+idea整合_第6张图片

pom.xml配置



    4.0.0

    cn.tx
    tx_springboot_user
    1.0-SNAPSHOT
    
    
        org.springframework.boot
        spring-boot-starter-parent
        2.0.5.RELEASE
        
    
    
        
        
            log4j
            log4j
            1.2.12
        
        
        
            com.alibaba
            fastjson
            1.2.47
        
        
        
            org.mybatis.spring.boot
            mybatis-spring-boot-starter
            1.3.2
        
        
        
            org.springframework.boot
            spring-boot-starter-web
        

        
            org.springframework.boot
            spring-boot-starter-test
            test
        
        
        
            org.springframework.boot
            spring-boot-detools
            true
        
        
        
            org.springframework.boot
            spring-boot-starter-thymeleaf
        
        
        
            mysql
            mysql-connector-java
        

         
              org.springframework.boot
              spring-boot-configuration-processor
              true
          
    


        
           
               
                   org.springframework.boot
                   spring-boot-maven-plugin
               
           

        

所有文件配置

1.DmoController类

package cn.tx.controller;

import cn.tx.domain.Demo;
import cn.tx.service.DemoService;
import cn.tx.service.DemoServiceM;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Controller
@RequestMapping("/demo")
public class DmoController {
     @Autowired
    private DemoServiceM demoService;

     @RequestMapping("/findAll")
    public List findAll(){
         return demoService.findAll();

     }
    @RequestMapping("/login")
    public String login(){
        return "/login";
    }

    @RequestMapping("/logins")
    public String logins(String name){
System.out.println(name+"------------------------------------");
        Demo demo=demoService.findAllLogin(name);
         if(demo !=null){
             return "/index";
         }else{
             return "/login";
         }

    }
}

2.DemoMapper类

package cn.tx.dao;

import cn.tx.domain.Demo;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

@Mapper//可以扫描mapper
public interface DemoMapper {
     public List findAll();

     public Demo findAllLogin(String name);
}

3.Demo实体类

package cn.tx.domain;

public class Demo {
    private int id;
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }
}

4.DemoService类

package cn.tx.service;

import cn.tx.domain.Demo;

import java.util.List;

public interface DemoService {
    public List findAll();
    public Demo findAllLogin(String name);
}

5.DemoServiceM类

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
@Service

@Transactional//事物的注解
public class DemoServiceM implements DemoService {
    @Resource
    private DemoMapper demoMapper;

    @Override
    public List findAll() {
        return demoMapper.findAll();
    }

    @Override
    public Demo findAllLogin(String name) {
        return demoMapper.findAllLogin(name);
    }

6.DemoApplication类

package cn.tx;

import cn.tx.domain.Demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class DemoApplication {
    public static void main(String[] arg){
        SpringApplication.run(DemoApplication.class,arg);
    }
}

7.UserMapper.xmlSQL配置




    
    

8.index.html




    
    Title


登录成功

9.login.html




    
    Title


 
姓名:

10.success.html





    Title




11.application.yml核心配置一般springboot自动帮你配置了但是数据库无法配置springboot共有3种配置文件类型可配置
核心的配置yml只是其中一种而已但是yml可读性强

spring:
  datasource:
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://localhost:3306/stum
    username: root
    passwrod:
mybatis:
  mapper-locations: classpath:mappers/*.xml
  type-aliases-package: cn.tx.domain
server:
  port: 8888

需要注意的事情

1.http://localhost:8888/demo/login我的访问路径供参考
2.jdk最后1.7以上idea的11也可以反正我这没问题

个人介绍

我叫周松,各位看官叫我小周就好本人QQ1017381567,不懂的可以问我

你可能感兴趣的:(小招)