当前位置:首页 > Java技术 > spring + springMVC + spring Data + jpa + maven 项目框架搭建

spring + springMVC + spring Data + jpa + maven 项目框架搭建

2022年08月05日 15:05:43Java技术4

首先看一下项目结构:

spring + springMVC + spring Data + jpa + maven 项目框架搭建 _ JavaClub全栈架构师技术笔记

所用到的jar(pom.xml):

<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.ajie.wechat</groupId>
    <artifactId>ajie-wechat</artifactId>
    <packaging>jar</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>ajie-wechat</name>
    <url>http://maven.apache.org</url>
    
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>4.1.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>4.1.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>4.1.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>4.1.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>4.1.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>4.1.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>4.1.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>4.1.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>4.1.3.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>4.3.11.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>4.3.11.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-ehcache</artifactId>
            <version>4.3.11.Final</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.35</version>
        </dependency>
        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>1.2.2</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.12</version>
        </dependency>
        <dependency>
            <groupId>com.jolbox</groupId>
            <artifactId>bonecp</artifactId>
            <version>0.8.0.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>com.jolbox</groupId>
            <artifactId>bonecp-spring</artifactId>
            <version>0.8.0.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>com.jolbox</groupId>
            <artifactId>bonecp-provider</artifactId>
            <version>0.8.0-alpha1</version>
        </dependency>
        <dependency>
            <groupId>taglibs</groupId>
            <artifactId>standard</artifactId>
            <version>1.1.2</version>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>1.8.7</version>
        </dependency>
        <dependency>
            <groupId>cglib</groupId>
            <artifactId>cglib-nodep</artifactId>
            <version>3.2.0</version>
        </dependency>
        <dependency>
            <groupId>commons-collections</groupId>
            <artifactId>commons-collections</artifactId>
            <version>3.2.1</version>
        </dependency>
        <dependency>
            <groupId>ant</groupId>
            <artifactId>ant</artifactId>
            <version>1.6.5</version>
        </dependency>
        <dependency>
            <groupId>org.apache.avro</groupId>
            <artifactId>avro</artifactId>
            <version>1.7.7</version>
        </dependency>
        <dependency>
            <groupId>commons-beanutils</groupId>
            <artifactId>commons-beanutils</artifactId>
            <version>1.9.2</version>
        </dependency>
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.3.1</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.4</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.4</version>
        </dependency>
        <dependency>
            <groupId>dom4j</groupId>
            <artifactId>dom4j</artifactId>
            <version>1.6.1</version>
        </dependency>
        <dependency>
            <groupId>net.sf.ezmorph</groupId>
            <artifactId>ezmorph</artifactId>
            <version>1.0.6</version>
        </dependency>
        <dependency>
            <groupId>org.freemarker</groupId>
            <artifactId>freemarker</artifactId>
            <version>2.3.23</version>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>18.0</version>
        </dependency>
        <dependency>
            <groupId>org.javassist</groupId>
            <artifactId>javassist</artifactId>
            <version>3.20.0-GA</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.logging</groupId>
            <artifactId>jboss-logging</artifactId>
            <version>3.3.0.Final</version>
        </dependency>
        <!-- jackson -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.5.0</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>2.5.0</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>2.5.0</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-jpa -->
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-jpa</artifactId>
            <version>1.7.1.RELEASE</version>
        </dependency>
        
    </dependencies>
    <build>
        <plugins>
            <!-- 编码和编译 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <encoding>utf8</encoding>
                </configuration>
            </plugin>
        </plugins>
        <finalName>ajie-wechat</finalName>
    </build>
</project>

 

spring配置文件(applicationContext.xml):

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:cache="http://www.springframework.org/schema/cache"
    xmlns:jaxws="http://cxf.apache.org/jaxws"
    xmlns:jpa="http://www.springframework.org/schema/data/jpa"
    xsi:schemaLocation="
                    http://www.springframework.org/schema/beans
                    http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
                    http://www.springframework.org/schema/tx 
                    http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
                    http://www.springframework.org/schema/aop 
                    http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
                    http://www.springframework.org/schema/context      
                    http://www.springframework.org/schema/context/spring-context-3.1.xsd
                    http://www.springframework.org/schema/cache 
                    http://www.springframework.org/schema/cache/spring-cache-3.1.xsd
                    http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd 
                    http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd" 
                    default-lazy-init="true">

    <!-- 启动组件扫描,排除@Controller组件,该组件由SpringMVC配置文件扫描 -->
    <context:component-scan base-package="com.ajie.wechat">
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
    </context:component-scan>

    <!-- 属性文件位置 -->
    <context:property-placeholder location="classpath:jdbc.properties" />

    
    <!-- 数据源 -->
    <bean id="dataSource" class="com.jolbox.bonecp.BoneCPDataSource"
        destroy-method="close">
        <!-- 数据库驱动 -->
        <property name="driverClass" value="${jdbc.driverClassName}" />
        <!-- 相应驱动的jdbcUrl-->
        <property name="jdbcUrl" value="${jdbc.url}" />
        <!-- 数据库的用户名 -->
        <property name="username" value="${jdbc.username}" />
        <!-- 数据库的密码 -->
        <property name="password" value="${jdbc.password}" />
    </bean>

    <!-- JPA实体管理器工厂 -->
    <bean id="entityManagerFactory"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="jpaVendorAdapter" ref="hibernateJpaVendorAdapter" />
        <!-- 加入定制化包路径 -->
        <property name="packagesToScan" value="com.ajie.wechat.model" />

        <property name="jpaProperties">
            <props>
                <prop key="hibernate.current_session_context_class">thread</prop>
                <prop key="hibernate.hbm2ddl.auto">update</prop><!-- validate/update/create -->
                <prop key="hibernate.show_sql">false</prop>
                <prop key="hibernate.format_sql">false</prop>
                
                <!-- 建表的命名规则 -->
                <prop key="hibernate.ejb.naming_strategy">org.hibernate.cfg.ImprovedNamingStrategy</prop>
                
            </props>
        </property>
    </bean>
    
    <!-- 设置JPA实现厂商的特定属性 -->
    <bean id="hibernateJpaVendorAdapter"
        class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
        <property name="databasePlatform" value="${hibernate.dialect}"/>
    </bean>
    
    <!-- Jpa 事务配置 -->
    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory"/>
    </bean>

    <!-- Spring Data Jpa配置 -->
    <jpa:repositories base-package="com.ajie.wechat"  transaction-manager-ref="transactionManager" entity-manager-factory-ref="entityManagerFactory"/>
    
    <!-- 使用annotation定义事务 -->
    <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" />
</beans>

 

springMVC配置文件(spring-mvc.xml):

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation=" 
                http://www.springframework.org/schema/beans 
                http://www.springframework.org/schema/beans/spring-beans-3.1.xsd 
                http://www.springframework.org/schema/context 
                http://www.springframework.org/schema/context/spring-context-3.1.xsd 
                http://www.springframework.org/schema/mvc 
                http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd" >
    
    <!-- 启用SpringMVC的注解功能,它会自动注册HandlerMapping、HandlerAdapter、ExceptionResolver的相关实例 -->
    <mvc:annotation-driven />
    <!-- SpringMVC的扫描范围 -->
    <context:component-scan base-package="com.ajie.wechat.controller" use-default-filters="false">
        <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
        <context:include-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice"/>
    </context:component-scan>
    
    <!-- 默认访问跳转到登录页面,即定义无Controller的path<->view直接映射 
    <mvc:view-controller path="/" view-name="redirect:/login"/>
    -->
    
    <!-- 静态文件访问 -->
    <!-- <mvc:resources mapping="/resources/**" location="/resources/" /> -->
    
    <!-- 用于返回json格式 -->
    <bean id="mappingJacksonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">    
        <property name="supportedMediaTypes">    
            <list>
                <value>application/x-www-form-urlencoded;charset=UTF-8</value>
            </list>
        </property>
    </bean>
 
     <!-- 完成请求和注解POJO的映射 -->
    <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
         <property name="messageConverters">
            <list>
                <ref bean="mappingJacksonHttpMessageConverter" />
            </list>
        </property>
    </bean>
    
    <!-- 配置SpringMVC的视图解析器 --> 
    <!-- 其viewClass属性的默认值就是org.springframework.web.servlet.view.JstlView -->  
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <!-- <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> -->
        <property name="prefix" value="/" />
        <property name="suffix" value=".html" />
    </bean>
    
    <!-- 总错误处理-->
<!--     <bean id="exceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">  
        <property name="defaultErrorView">
            <value>/base/error</value>
        </property>
        <property name="defaultStatusCode">
            <value>500</value>
        </property>
        <property name="warnLogCategory">
            <value>org.springframework.web.servlet.handler.SimpleMappingExceptionResolver</value>  
        </property>
    </bean> -->
    
    <!-- 静态资源加载 -->
    <mvc:resources location="/css/" mapping="/css/**" />
    
    <mvc:resources location="/images/" mapping="/images/**" />
    <mvc:resources location="/ATTACHMENT/" mapping="/ATTACHMENT/**" />
    
</beans>

 

连接数据库配置文件(jdbc.properties):

jdbc.driverClassName=com.mysql.jdbc.Driver

jdbc.url=jdbc\:mysql\://localhost\:3306/ajie?useUnicode\=true&characterEncoding\=UTF-8

jdbc.username=root

jdbc.password=Jovaunn1

hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect

BoneCP.idleConnectionTestPeriod=60

BoneCP.idleMaxAge=60

BoneCP.maxConnectionsPerPartition=5

BoneCP.minConnectionsPerPartition=1

BoneCP.partitionCount=3

BoneCP.acquireIncrement=2  

BoneCP.statementsCacheSize=0 
  
BoneCP.releaseHelperThreads=3

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
  <display-name>Archetype Created Web Application</display-name>
  <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath*:applicationContext*.xml</param-value>
    </context-param>
    
     <!-- 防止发生java.beans.Introspector内存泄露,应将它配置在ContextLoaderListener的前面 -->  
    <!-- 详细描述见http://blog.csdn.net/jadyer/article/details/11991457 -->  
    <listener>  
        <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>  
    </listener>  
    
     <!-- 实例化Spring容器 -->  
    <!-- 应用启动时,该监听器被执行,它会读取Spring相关配置文件,其默认会到WEB-INF中查找applicationContext.xml -->  
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    
    <!-- 配置编码过滤器 -->
    <filter>
        <filter-name>characterEncodingFilter</filter-name>
        <filter-class>
            org.springframework.web.filter.CharacterEncodingFilter
        </filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
        <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>characterEncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    
    <!-- 配置spring管理OpenEntityManagerInViewFilter-->
    <!-- OpenEntityManagerInViewFilter会让session一直到view层调用结束后才关闭
        Spring针对Hibernate的非JPA实现用的是OpenSessionInViewFilter,原理与这个大同小异
     -->
    <filter>
        <filter-name>hibernateFilter</filter-name>
        <filter-class>
            org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter
        </filter-class>
    </filter>
    <filter-mapping>
        <filter-name>hibernateFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    
    <!-- 用默认的servlet来处理资源 -->
    <servlet-mapping>  
        <servlet-name>default</servlet-name> 
        <url-pattern>*.jpg</url-pattern>    
    </servlet-mapping> 
    <servlet-mapping>  
        <servlet-name>default</servlet-name> 
        <url-pattern>*.png</url-pattern>    
    </servlet-mapping>     
    <servlet-mapping>  
        <servlet-name>default</servlet-name> 
        <url-pattern>*.gif</url-pattern>    
    </servlet-mapping> 
    <servlet-mapping>  
        <servlet-name>default</servlet-name> 
        <url-pattern>*.woff</url-pattern>    
    </servlet-mapping> 
    <servlet-mapping>  
        <servlet-name>default</servlet-name> 
        <url-pattern>*.ttf</url-pattern>    
    </servlet-mapping>          
    <servlet-mapping>  
        <servlet-name>default</servlet-name> 
        <url-pattern>*.map</url-pattern>    
    </servlet-mapping>      
    <servlet-mapping>      
        <servlet-name>default</servlet-name>   
        <url-pattern>*.js</url-pattern>   
    </servlet-mapping>  
    <servlet-mapping>       
        <servlet-name>default</servlet-name>      
        <url-pattern>*.css</url-pattern>     
    </servlet-mapping>  
    <servlet-mapping>       
        <servlet-name>default</servlet-name>      
        <url-pattern>*.html</url-pattern>     
    </servlet-mapping>
    
    <!-- SpringMVC核心分发器 -->
    <servlet>
        <servlet-name>dispatcherServlet</servlet-name>
        <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath*:/spring-mvc.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>dispatcherServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
        <welcome-file>/index.html</welcome-file>
    </welcome-file-list>
</web-app>

 

 

下面是程序测试代码(接口使用RESTful风格):

1.model实体 User.java

package com.ajie.wechat.model;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "user")
public class User implements Serializable {

    private static final long serialVersionUID = 7419229779731522702L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "userId")
    private Long id;
    
    @Column(length = 50)
    private String account;
    public Long getId() {
        return id;
    }

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

    public String getAccount() {
        return account;
    }

    public void setAccount(String account) {
        this.account = account;
    }
    public static long getSerialversionuid() {
        return serialVersionUID;
    }
}

 

2.Dao

package com.ajie.wechat.dao;

import org.springframework.data.jpa.repository.JpaRepository;

import com.ajie.wechat.model.User;

public interface UserDao extends JpaRepository<User, Long> {
    
}

3.Service

 

package com.ajie.wechat.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ajie.wechat.dao.UserDao;
import com.ajie.wechat.model.User;

@Service
@Transactional
public class UserService {
    @Autowired
    private UserDao userDao;
    
    public String add(User user){
        userDao.save(user);
        return "添加成功!";
    }
    
    public String addUser(String account){
        User user = new User();
        user.setAccount(account);
        userDao.save(user);
        return "添加成功!";
    }
    
    public User getOneUser(Long id){
        return userDao.findOne(id);
    }
}

 

4.controller层使用@RestController(等同于@Controller + @ResponseBody)

package com.ajie.wechat.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.ajie.wechat.model.User;
import com.ajie.wechat.service.UserService;

@RestController
@RequestMapping(value = "/frame")
public class UserController {
    @Autowired
    private UserService userService;
    
    @RequestMapping(value = "/saveUser",
            method = RequestMethod.POST,
            produces = MediaType.APPLICATION_JSON_VALUE + ";charset=UTF-8")
    public String saveUser(@RequestBody User user){
        return userService.add(user);
    }
    
    @RequestMapping(value = "/saveUser/{account}",
            method = RequestMethod.GET,
            produces = MediaType.APPLICATION_JSON_VALUE + ";charset=UTF-8")
    public String add(@PathVariable String account){
        return userService.addUser(account);
    }
    
    @RequestMapping(value = "/user/{id}",
            method = RequestMethod.GET,
            produces = MediaType.APPLICATION_JSON_VALUE + ";charset=UTF-8")
    public User add(@PathVariable Long id){
        return userService.getOneUser(id);
    }
}

 

 

一些需要注意的地方:

spring的配置:

spring + springMVC + spring Data + jpa + maven 项目框架搭建 _ JavaClub全栈架构师技术笔记

spring + springMVC + spring Data + jpa + maven 项目框架搭建 _ JavaClub全栈架构师技术笔记

 

作者:007少侠
来源链接:https://www.cnblogs.com/007sx/p/5658194.html

版权声明:
1、JavaClub(https://www.javaclub.cn)以学习交流为目的,由作者投稿、网友推荐和小编整理收藏优秀的IT技术及相关内容,包括但不限于文字、图片、音频、视频、软件、程序等,其均来自互联网,本站不享有版权,版权归原作者所有。

2、本站提供的内容仅用于个人学习、研究或欣赏,以及其他非商业性或非盈利性用途,但同时应遵守著作权法及其他相关法律的规定,不得侵犯相关权利人及本网站的合法权利。
3、本网站内容原作者如不愿意在本网站刊登内容,请及时通知本站(javaclubcn@163.com),我们将第一时间核实后及时予以删除。


本文链接:https://www.javaclub.cn/java/17722.html

标签: SpringMVC
分享给朋友:

“spring + springMVC + spring Data + jpa + maven 项目框架搭建” 的相关文章

SpringMVC配置没问题却却找不到页面,页面显示404

SpringMVC配置没问题却却找不到页面,页面显示404

在Artifacts下此工程下新建一个lib文件夹,存放jar包,因为idea新建modules的时候不是直接创建的web项目: 选中lib点加号把jar导入进去,然后重启tomcat 作者:春_ 来源链接:https://b...

SpringBoot和SpringMVC的区别

SpringBoot和SpringMVC的区别

一 面试提问 👨‍💻面试官:SpringBoot和SpringMVC的区别 🙋我: 形式上:SpringBoot是一个自动化配置的工具;SpringMVC是一个web框架 在搭建项目时:SpringMVC需要手动配置xml...

Spring与SpringMVC的区别

Spring是IOC和AOP的容器框架,SpringMVC是基于Spring功能之上添加的Web框架,想用SpringMVC必须先依赖Spring。 简单点的话可以将SpringMVC类比于Struts。 Spring是IOC和AOP的容器框架,SpringMVC是基于Spring功能...

SpringMvc两种实现

SpringMvc两种实现

SpringMvc搭建 了解mvc 什么是MVC MVC是模型(Model)、视图(View)、控制器(Controller)的简写,是一种软件设计规范。 是将业务逻辑、数据、显示分离的方法来组织代码。...

springmvc常见乱码处理

用三层架构做项目时,有时处理不当就经常是乱码问题,我也尝尝为此感到头疼,先说说我的方法,数据库建表用的字符编码方式最好和开发工具使用的字符编码保持一致,utf-8,utf-16等等。 1,响应头导致有乱码 一般都是在doget或者dopost方式中设置编码方式...

Spring MVC 3 深入总结

Spring MVC 3 深入总结

  一、前言: 大家好,Spring3 MVC是非常优秀的MVC框架,由其是在3.0版本发布后,现在有越来越多的团队选择了Spring3 MVC了。Spring3 MVC结构简单,应了那句话简单就是美,而且他强大不失灵活,性能也...

SpringMVC 工作原理详解

SpringMVC 工作原理详解

本文Github开源项目https://github.com/Snailclimb/JavaGuide,只供自己学习总结无商业用途,如有侵权,联系删除 先来看一下什么是 MVC 模式 MVC 是一种设计模式. MVC 的原理图如下: S...

Spring整合SpringMVC时避免Spring加载两次bean的配置方法

Spring整合SpringMVC时避免Spring加载两次bean的配置方法

避免Spring加载两次bean的配置方法 写在前面的话 解决办法 写在前面的话       当Spring整合S...

SpringMVC和Springboot的区别(网摘)

spring boot 我理解就是把 spring spring mvc spring data jpa 等等的一些常用的常用的基础框架组合起来,提供默认的配置,然后提供可插拔的设计,就是各种 starter ,来方便开发者使用这一系列的技术,套用官方的一句话, spring 家族发展...

Springmvc bigdecimal精度丢失问题

一、在实体使用注解的方式 @JsonSerialize(using=ToStringSerializer.class) private BigDecimal minPrice = new BigDecimal(0); 二、使用配置方式 1、实现ObjectMap...

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。