zoukankan      html  css  js  c++  java
  • springboot搭建环境整合jsp页面整合mybatis

    1.pom文件依赖

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.hive</groupId>
    <artifactId>myspringboot</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>myspringboot Maven Webapp</name>
    <url>http://maven.apache.org</url>
    <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.4.3.RELEASE</version>
    </parent>
    <dependencies>
    <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>3.8.1</version>
    <scope>test</scope>
    </dependency>

    <!-- web支持: 1、web mvc; 2、restful; 3、jackjson支持; 4、aop ........ -->
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <!-- servlet 依赖. -->
    <dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <scope>provided</scope>
    </dependency>
    <dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-lang3</artifactId>
    <version>3.3.2</version>
    </dependency>
    <!-- 添加fastjson 依赖包. -->
    <dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>fastjson</artifactId>
    <version>1.2.15</version>
    </dependency>
    <dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jstl</artifactId>
    </dependency>
    <dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-core</artifactId>
    <version>3.1.0.RELEASE</version>
    </dependency>
    <!-- tomcat 的支持.-->
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
    <scope>provided</scope>
    </dependency>
    <dependency>
    <groupId>org.apache.tomcat.embed</groupId>
    <artifactId>tomcat-embed-jasper</artifactId>
    <scope>provided</scope>
    </dependency>
    <!-- mysql 数据库驱动. -->
    <dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    </dependency>
    <!--
    spring-boot mybatis依赖:

    请不要使用1.0.0版本,因为还不支持拦截器插件,
    1.1.1 是博主写帖子时候的版本,大家使用最新版本即可
    -->
    <dependency>
    <groupId>org.mybatis.spring.boot</groupId>
    <artifactId>mybatis-spring-boot-starter</artifactId>
    <version>1.1.1</version>
    </dependency>
    <!-- datasource heroku -->
    <!-- <dependency> -->
    <!-- <groupId>com.zaxxer</groupId> -->
    <!-- <artifactId>HikariCP-java6</artifactId> -->
    <!-- <exclusions> -->
    <!-- <exclusion> -->
    <!-- <artifactId>tools</artifactId> -->
    <!-- <groupId>com.sun</groupId> -->
    <!-- </exclusion> -->
    <!-- </exclusions> -->
    <!-- </dependency> -->
    <!-- aspectJ -->
    <dependency>
    <groupId>org.aspectj</groupId>
    <artifactId>aspectjweaver</artifactId>
    </dependency>
    <dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-commons</artifactId>
    </dependency>
    <!-- <dependency> -->
    <!-- <groupId>org.springframework.hateoas</groupId> -->
    <!-- <artifactId>spring-hateoas</artifactId> -->
    <!-- </dependency> -->
    <!-- javax -->
    <dependency>
    <groupId>javax.inject</groupId>
    <artifactId>javax.inject</artifactId>
    <version>1</version>
    </dependency>
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jdbc</artifactId>
    </dependency>
    <dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-api</artifactId>
    <version>7.0</version>
    <scope>provided</scope>
    </dependency>
    <dependency>
    <groupId>org.glassfish.web</groupId>
    <artifactId>javax.servlet.jsp.jstl</artifactId>
    <version>1.2.2</version>
    </dependency>
    <dependency>
    <groupId>javax.mail</groupId>
    <artifactId>mail</artifactId>
    <version>1.4.7</version>
    </dependency>

    <!--
    MyBatis提供了拦截器接口,我们可以实现自己的拦截器,
    将其作为一个plugin装入到SqlSessionFactory中。
    Github上有位开发者写了一个分页插件,我觉得使用起来还可以,挺方便的。
    Github项目地址: https://github.com/pagehelper/Mybatis-PageHelper
    -->
    <dependency>
    <groupId>com.github.pagehelper</groupId>
    <artifactId>pagehelper</artifactId>
    <version>4.1.0</version>
    </dependency>
    <!-- 添加MySQL数据库驱动依赖包. -->
    <dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    </dependency>

    <dependency>
    <groupId>commons-dbcp</groupId>
    <artifactId>commons-dbcp</artifactId>
    <version>1.4</version>
    </dependency>
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-freemarker</artifactId>
    <version>1.4.1.RELEASE</version>
    </dependency>

    <!-- 添加Spring-data-jpa依赖. -->
    <!-- <dependency> -->
    <!-- <groupId>org.springframework.boot</groupId> -->
    <!-- <artifactId>spring-boot-starter-data-jpa</artifactId> -->
    <!-- </dependency> -->
    <!-- spring boot devtools 依赖包. -->
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <optional>true</optional>
    <scope>true</scope>
    </dependency>
    </dependencies>
    <build>
    <plugins>
    <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
    <!--fork : 如果没有该项配置,肯呢个devtools不会起作用,即应用不会restart -->
    <fork>true</fork>
    </configuration>
    </plugin>
    </plugins>
    </build>
    <!-- <finalName>myspringboot</finalName> -->
    </project>

    2.application.yml

    server:
    port: 8001

    spring:
    application:
    name: myspringboot
    datasource:
    url: jdbc:mysql://192.168.103.169:3306/dmcdb?useUnicode=true&characterEncoding=utf-8
    username: root
    password: 123
    driverClassName: com.mysql.jdbc.Driver

    mybatis:
    mapperLocations: classpath:mybatis/mapper/*.xml
    typeAliasesPackage: com.hive.entity
    configLocation: classpath:mybatis/mybatis-config.xml

    3.application.properties

    spring.mvc.view.prefix=/WEB-INF/jsp/

    spring.mvc.view.suffix=.jsp

    4.注意静态资源js默认放入这个static路径下

    5.Aplication.java代码:

    package com;

    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.context.annotation.ComponentScan;
    import org.springframework.context.annotation.Configuration;
    @Configuration
    @ComponentScan(basePackages ={"com.hive.*"})
    @EnableAutoConfiguration
    @SpringBootApplication
    public class Aplication {
    public static void main(String[] args) {
    SpringApplication.run(Aplication.class, args);
    }
    }

    6.Mapper代码:

    package com.hive.mapper;

    import com.hive.entity.DevUser;
    import com.hive.entity.DevUserExample;
    import java.util.List;

    import org.apache.ibatis.annotations.Mapper;
    import org.apache.ibatis.annotations.Param;
    @Mapper
    public interface DevUserMapper {
    int countByExample(DevUserExample example);

    int deleteByExample(DevUserExample example);

    int deleteByPrimaryKey(Long id);

    int insert(DevUser record);

    int insertSelective(DevUser record);

    List<DevUser> selectByExample(DevUserExample example);

    DevUser selectByPrimaryKey(Long id);

    int updateByExampleSelective(@Param("record") DevUser record, @Param("example") DevUserExample example);

    int updateByExample(@Param("record") DevUser record, @Param("example") DevUserExample example);

    int updateByPrimaryKeySelective(DevUser record);

    int updateByPrimaryKey(DevUser record);
    }

  • 相关阅读:
    线程的中断
    线程间的协作机制
    iOS app内打开safari完成google的OAuth2认证
    iOS ipa 重签名 resign
    iOS rebuild from bitcode对ipa大小的影响
    iOS URL Cache文章推荐 (待完成)
    iOS 推荐几篇关于Objective-c 动态语言的文章
    iOS Code Sign On Copy
    设计模式好文章汇总(不断更新中)
    Json 文件中value的基本类型
  • 原文地址:https://www.cnblogs.com/lvgg/p/6933963.html
Copyright © 2011-2022 走看看