spring data jpa 拦截 20C

spring boot项目,数据层spring data jpa
现在想在数据层把个人信息的敏感字段加密?因为项目过大,如何事项在查询语句执行之前增加拦截,将查询参数进行加密,及获取数据后将查询数据进行解密。

3个回答

建议将敏感字段置空,或者通过不同接口返回,对于数据安全上可以使用oauth、jwt等技术通过token来获取敏感,因为即使你数据进行了加密。前端仍然需要解密,不但浪费性能,还会加大工作量,望采纳!

tingyk
村西头最帅的仔 加这个功能,是甲方的需求,为了防止DB直接在数据库内获取数据。
一年多之前 回复

简单的对方法进行aop方式的处理,还是有其他需要特别注意的地方?

可以了解下 AttributeConverter 看看是否满足需求哈,示例代码见下文,示例为将实体类中定义的 Instant 类型转换为 Date 类型以存入数据库。
(同理的,字符串转字符串也可以定义,此时,dbData 为加密后的数据,实体中属性为未加密数据即可)

定义 Converter

 public class InstantDateAttributeConverter implements AttributeConverter<Instant, Date> {
    @Override
    public Date convertToDatabaseColumn(Instant attribute) {
        return Optional.ofNullable(attribute)
                .map(Date::from)
                .orElse(null);
    }

    @Override
    public Instant convertToEntityAttribute(Date dbData) {
        return Optional.ofNullable(dbData)
                .map(Date::toInstant)
                .orElse(null);
    }
}

使用 Converter (当然要在 JPA 的实体类中使用哈)

@Convert(converter = InstantDateAttributeConverter.class)
private Instant modifiedTime;
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
Spring集成Hibernate,使用JPA注解方式,新增数据无法提交
<div class="iteye-blog-content-contain" style="font-size: 14px;"> <p>环境:</p> <p style="padding-left: 60px;">spring 3.1</p> <p style="padding-left: 60px;">hibernate 4.2.8 final </p> <p style="padding-left: 60px;">mysql 5.6</p> <p>问题描述:</p> <p style="padding-left: 30px;">调用controller的查询方法,可以正常返回数据</p> <p style="padding-left: 30px;">调用controller的创建方法,即:新增数据,控制台打印出了读取和修改序号表的sql,但是没有打印插入数据的sql,数据库表中也没有新增数据。</p> <p style="padding-left: 30px;">怀疑是spring控制的事务没有提交,但是排查了两三天,从网上找了各种方法,都没有解决问题。</p> <p style="padding-left: 30px;">请各位大侠拉小弟一把,实在是找不到事务为什么没有提交。</p> <p> </p> <p style="padding-left: 30px;">web.xml</p> <p style="padding-left: 30px;"> </p> <pre name="code" class="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;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_2_5.xsd" id="WebApp_ID" version="2.5"&gt; &lt;!-- 欢迎界面 --&gt; &lt;welcome-file-list&gt; &lt;welcome-file&gt;index.html&lt;/welcome-file&gt; &lt;/welcome-file-list&gt; &lt;!-- spring框架 --&gt; &lt;listener&gt; &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt; &lt;/listener&gt; &lt;!-- 上下文配置 --&gt; &lt;context-param&gt; &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt; &lt;param-value&gt; /WEB-INF/applicationContext.xml, /WEB-INF/config/**/*.xml &lt;/param-value&gt; &lt;/context-param&gt; &lt;!-- spring mvc --&gt; &lt;servlet&gt; &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt; &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt; &lt;load-on-startup&gt;1&lt;/load-on-startup&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt; &lt;!-- 拦截所有url --&gt; &lt;url-pattern&gt;/&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; &lt;!-- 回话有效期30分钟 --&gt; &lt;session-config&gt; &lt;session-timeout&gt;30&lt;/session-timeout&gt; &lt;/session-config&gt; &lt;!-- log4j日志 --&gt; &lt;listener&gt; &lt;listener-class&gt;org.springframework.web.util.Log4jConfigListener&lt;/listener-class&gt; &lt;/listener&gt; &lt;!-- log4j日志配置 --&gt; &lt;context-param&gt; &lt;param-name&gt;log4jConfigLocation&lt;/param-name&gt; &lt;param-value&gt;/WEB-INF/properties/log4j.properties&lt;/param-value&gt; &lt;/context-param&gt; &lt;/web-app&gt;</pre> <p> applicationContext.xml</p> <p> </p> <p style="padding-left: 30px;"> </p> <pre name="code" class="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"&gt; &lt;!-- 注解配置 --&gt; &lt;context:annotation-config /&gt; &lt;!--允许使用注解方式配置事务 --&gt; &lt;tx:annotation-driven transaction-manager="transactionManager" /&gt; &lt;!-- 自动扫描的包名 --&gt; &lt;context:component-scan base-package="com.lxl" /&gt; &lt;!-- 对标注@PersistenceContext的类经行增强,引入代理后的EntityManager实例 --&gt; &lt;bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" /&gt; &lt;!-- 对标注@Repository的类经行增强,将EntityManager异常转换为SpringDAO体系的异常 --&gt; &lt;bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" /&gt; &lt;!-- 属性文件 --&gt; &lt;context:property-placeholder location="/WEB-INF/properties/**/*.properties" /&gt; &lt;!-- 数据源 --&gt; &lt;bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt; &lt;property name="driverClassName" value="${jdbc.driverClassName}" /&gt; &lt;property name="url" value="${jdbc.url}" /&gt; &lt;property name="username" value="${jdbc.username}" /&gt; &lt;property name="password" value="${jdbc.password}" /&gt; &lt;/bean&gt; &lt;!-- JPA 实体管理工厂 --&gt; &lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt; &lt;property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml" /&gt; &lt;property name="dataSource" ref="dataSource" /&gt; &lt;property name="persistenceUnitName" value="ServicePlatform" /&gt; &lt;property name="jpaVendorAdapter"&gt; &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"&gt; &lt;property name="showSql" value="true" /&gt; &lt;property name="generateDdl" value="true" /&gt; &lt;property name="databasePlatform" value="org.hibernate.dialect.MySQL5Dialect" /&gt; &lt;/bean&gt; &lt;/property&gt; &lt;/bean&gt; &lt;!-- JPA 事务管理 --&gt; &lt;bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"&gt; &lt;property name="dataSource" ref="dataSource" /&gt; &lt;property name="entityManagerFactory" ref="entityManagerFactory" /&gt; &lt;/bean&gt; &lt;/beans&gt;</pre> <p> dispatcher-servlet.xml</p> <p> </p> <p style="padding-left: 30px;"> </p> <pre name="code" class="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"&gt; &lt;!-- 默认的注解映射的支持 --&gt; &lt;mvc:annotation-driven /&gt; &lt;!-- 自动扫描的包名 --&gt; &lt;context:component-scan base-package="com.lxl" /&gt; &lt;!-- 配置一下对json数据的转换 &lt;bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"&gt; &lt;property name="messageConverters"&gt; &lt;list&gt; &lt;bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"&gt;&lt;/bean&gt; &lt;/list&gt; &lt;/property&gt; &lt;/bean&gt; --&gt; &lt;!-- 视图解析器 --&gt; &lt;bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt; &lt;property name="prefix" value="/view" /&gt; &lt;property name="suffix" value=".jsp" /&gt; &lt;/bean&gt; &lt;!-- 对静态资源文件的访问 方案一 (二选一) --&gt; &lt;mvc:default-servlet-handler /&gt; &lt;!-- 对静态资源文件的访问 方案二 (二选一) &lt;mvc:resources mapping="/images/**" location="/images/" cache-period="31556926"/&gt; &lt;mvc:resources mapping="/js/**" location="/js/" cache-period="31556926"/&gt; &lt;mvc:resources mapping="/css/**" location="/css/" cache-period="31556926"/&gt; --&gt; &lt;/beans&gt;</pre> <p> </p> <p> </p> <p style="padding-left: 30px;">persistence.xml</p> <p style="padding-left: 30px;"> </p> <pre name="code" class="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"&gt; &lt;persistence-unit name="ServicePlatform" transaction-type="RESOURCE_LOCAL"&gt; &lt;/persistence-unit&gt; &lt;/persistence&gt; </pre> <p> </p> <p> </p> <p style="padding-left: 30px;">实体bean</p> <p style="padding-left: 30px;"> </p> <pre name="code" class="java">package com.lxl.bsp.identity.entity; import java.io.Serializable; import java.sql.Timestamp; 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 = "bd_id") public class Identity implements Serializable { private static final long serialVersionUID = -8763611811485844772L; @Id @GeneratedValue(strategy = GenerationType.TABLE) private Long id; @Column(length = 100) private String code; private Long value; @Column(length = 10) private String prefix; @Column(length = 10) private String suffix; @Column(length = 255) private String description; private Integer length; @Column(length = 30) private String creator; @Column(name = "create_date") private Timestamp createDate; @Column(length = 30) private String modifier; @Column(name = "modify_Date") private Timestamp modifyDate; private Boolean dr; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getCode() { return code; } public void setCode(String code) { this.code = code; } public Long getValue() { return value; } public void setValue(Long value) { this.value = value; } public String getPrefix() { return prefix; } public void setPrefix(String prefix) { this.prefix = prefix; } public String getSuffix() { return suffix; } public void setSuffix(String suffix) { this.suffix = suffix; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public Integer getLength() { return length; } public void setLength(Integer length) { this.length = length; } public String getCreator() { return creator; } public void setCreator(String creator) { this.creator = creator; } public Timestamp getCreateDate() { return createDate; } public void setCreateDate(Timestamp createDate) { this.createDate = createDate; } public String getModifier() { return modifier; } public void setModifier(String modifier) { this.modifier = modifier; } public Timestamp getModifyDate() { return modifyDate; } public void setModifyDate(Timestamp modifyDate) { this.modifyDate = modifyDate; } public Boolean getDr() { return dr; } public void setDr(Boolean dr) { this.dr = dr; } @Override public String toString() { return "Identity [id=" + id + ", code=" + code + ", value=" + value + ", prefix=" + prefix + ", suffix=" + suffix + ", description=" + description + ", length=" + length + ", creator=" + creator + ", createDate=" + createDate + ", modifier=" + modifier + ", modifyDate=" + modifyDate + ", dr=" + dr + "]"; } } </pre> <p> </p> <p> </p> <p style="padding-left: 30px;">IdentityDaoImpl.java</p> <p style="padding-left: 30px;"> </p> <pre name="code" class="java">package com.lxl.bsp.identity.dao; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import com.lxl.bsp.api.exception.ServicePlatformException; import com.lxl.bsp.identity.entity.Identity; @Repository public class IdentityDaoImpl implements IIdentityDao { @PersistenceContext private EntityManager em; @Transactional(propagation = Propagation.REQUIRED) public Identity create(Identity data) { em.persist(data); return data; } @Override public Identity retriver(String id) throws ServicePlatformException { Long pk = Long.valueOf(id); return em.find(Identity.class, pk); } @Override public Identity update(Identity data) throws ServicePlatformException { em.persist(data); return data; } @Override public void delete(String id) throws ServicePlatformException { em.remove(retriver(id)); } } </pre> <p> IdentityController.java</p> <p> </p> <p style="padding-left: 30px;"> </p> <pre name="code" class="java">package com.lxl.bsp.identity.controller; import java.sql.Timestamp; import java.util.Calendar; import javax.annotation.Resource; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import com.lxl.bsp.api.exception.ServicePlatformException; import com.lxl.bsp.identity.dao.IIdentityDao; import com.lxl.bsp.identity.entity.Identity; @Controller @RequestMapping("identity") public class IdentityController { private static Log log = LogFactory.getLog(IdentityController.class); @Resource private IIdentityDao dao; @RequestMapping("retriver") @ResponseBody public Identity retriver(@RequestParam String id) throws ServicePlatformException { return dao.retriver(id); } @RequestMapping("create") @ResponseBody public Identity create() throws ServicePlatformException { int i = 1; Identity data = new Identity(); data.setCode("code" + i); Calendar c = Calendar.getInstance(); data.setCreateDate(new Timestamp(c.getTime().getTime())); data.setCreator("creator" + i); data.setDescription("description" + i); data.setDr(false); // data.setId("id" + Integer.toString(i)); data.setLength(30); data.setModifier("modifier" + i); data.setModifyDate(new Timestamp(c.getTime().getTime())); data.setPrefix("prefix"); data.setSuffix("suffix"); data.setValue(0L); Identity returnData = dao.create(data); log.debug(returnData); return returnData; } @RequestMapping("update") @ResponseBody public Identity update() throws ServicePlatformException { int i = 1; Identity data = new Identity(); data.setCode("1"); Calendar c = Calendar.getInstance(); data.setCreateDate(new Timestamp(c.getTime().getTime())); data.setCreator("creator" + i); data.setDescription("description" + i); data.setDr(false); // data.setId("id" + Integer.toString(i)); data.setLength(30); data.setModifier("modifier" + i); data.setModifyDate(new Timestamp(c.getTime().getTime())); data.setPrefix("prefix"); data.setSuffix("suffix"); data.setValue(0L); Identity returnData = dao.update(data); log.debug(returnData); return returnData; } @RequestMapping("delete") public void delete(@RequestParam String id) throws ServicePlatformException { dao.delete(id); } } </pre> <p> </p> <p> </p> <p style="padding-left: 30px;">数据表结构DDL</p> <p style="padding-left: 30px;"> </p> <pre name="code" class="sql">-- ---------------------------- -- Table structure for bd_id -- ---------------------------- DROP TABLE IF EXISTS `bd_id`; CREATE TABLE `bd_id` ( `id` bigint(30) NOT NULL, `code` varchar(100) DEFAULT NULL, `create_date` datetime DEFAULT NULL, `creator` varchar(30) DEFAULT NULL, `description` varchar(255) DEFAULT NULL, `dr` tinyint(1) DEFAULT NULL, `length` int(11) DEFAULT NULL, `modifier` varchar(30) DEFAULT NULL, `modify_Date` datetime DEFAULT NULL, `prefix` varchar(10) DEFAULT NULL, `suffix` varchar(10) DEFAULT NULL, `value` bigint(20) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;</pre> <p> </p> <p> </p> <p style="padding-left: 30px;">附件中是项目压缩包,只要电脑上安装了数据库,解压即可运行,数据库名称是osd</p> <p> </p> </div>
关于SpringBoot+myBatis实体的字段返回前端后格式变化的问题
我的架构是 springBoot(1.5.9)+myBatis ,连接池用的是阿里的druid,以下是配置信息: 启动类: import java.sql.SQLException; import java.util.HashMap; import java.util.Map; import org.apache.ibatis.plugin.Interceptor; import org.apache.ibatis.session.SqlSessionFactory; import org.mybatis.spring.SqlSessionFactoryBean; import org.mybatis.spring.annotation.MapperScan; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.boot.web.servlet.ServletRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import com.alibaba.druid.pool.DruidDataSource; import com.alibaba.druid.support.http.StatViewServlet; import com.alibaba.druid.support.http.WebStatFilter; import com.github.pagehelper.PageHelper; /** * * @author wangxufei * */ @SpringBootApplication @EnableAutoConfiguration @MapperScan("com.mofangge.mapper") public class MfgAgencyApplication { @Value("${spring.datasource.username}") private String userName; @Value("${spring.datasource.password}") private String password; @Value("${spring.datasource.url}") private String url; @Bean public ServletRegistrationBean druidServletRegistrationBean() { ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(); servletRegistrationBean.setServlet(new StatViewServlet()); servletRegistrationBean.addUrlMappings("/druid/*"); return servletRegistrationBean; } /** * 注册DruidFilter拦截 * * @return */ @Bean public FilterRegistrationBean duridFilterRegistrationBean() { FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(); filterRegistrationBean.setFilter(new WebStatFilter()); Map<String, String> initParams = new HashMap<String, String>(); // 设置忽略请求 initParams.put("exclusions", "*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*"); filterRegistrationBean.setInitParameters(initParams); filterRegistrationBean.addUrlPatterns("/*"); return filterRegistrationBean; } /** * 配置DruidDataSource * * @return * @throws SQLException */ @Bean public DruidDataSource druidDataSource() throws SQLException { DruidDataSource druidDataSource = new DruidDataSource(); druidDataSource.setUsername(userName); druidDataSource.setPassword(password); druidDataSource.setUrl(url); druidDataSource.setMaxActive(100); druidDataSource.setFilters("stat,wall"); druidDataSource.setInitialSize(10); return druidDataSource; } @Bean public SqlSessionFactory sqlSessionFactoryBean() throws Exception { SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean(); sqlSessionFactoryBean.setDataSource(druidDataSource()); PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); sqlSessionFactoryBean.setMapperLocations(resolver.getResources("classpath:/mybatis/*.xml")); sqlSessionFactoryBean.setTypeAliasesPackage("com.mofangge.model,com.mofangge.dto"); Interceptor[] interceptors = {new PageHelper()}; sqlSessionFactoryBean.setPlugins(interceptors); return sqlSessionFactoryBean.getObject(); } public static void main(String[] args) { SpringApplication.run(MfgAgencyApplication.class, args); } } properties文件: #server #server.port=8080 server.port=8081 #server.port=8099 #server.servlet-path=/agency ## log logging.level.org.springframework.web: error logging.level.com.mofangge:info logging.file:mfg-agency.log # JPA (JpaBaseConfiguration, HibernateJpaAutoConfiguration) spring.data.jpa.repositories.enabled=true spring.jpa.database=mysql spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect spring.jpa.generate-ddl=false spring.jpa.hibernate.ddl-auto=none spring.jpa.open-in-view=true spring.jpa.show-sql=false 现在遇到的问题是: 实体类中的格式 返回到页面后,字段格式变化了,如下图: 实体: ![图片说明](https://img-ask.csdn.net/upload/201803/08/1520520274_791208.png) 数据库: ![图片说明](https://img-ask.csdn.net/upload/201803/08/1520520307_858101.png) 返回到页面后的值(controller注解了@RestController): ![图片说明](https://img-ask.csdn.net/upload/201803/08/1520520354_282352.png) 第二个字母 应该是大写C 结果变成了小写c。 而且有个现象是: 如果你的字段是 sName 那么前端拿到的是sname 如果你的字段是seName 那么前端拿到的就是seName **不会变化** 也就是说 如果驼峰前字母是2个或2个以上 他就按照原来的格式了,不知道具体是什么原因,求大佬教导。 ps: 我试过很多种方法,只有一种有效果 就是给字段注解 @JsonProperty 但是这种方法会造成我的返回值里会有2个 sname 一个是sname 一个是sName 2个字段都是同样的值 给我一种复制的感觉。。
JAVAEE、SSM框架,报错:HTTP Status 500 求大神解决!
![这是页面报错信息](https://img-ask.csdn.net/upload/201707/31/1501509503_963548.png) ![这是所引用的jar包,并额外引入了tomcat的jar包](https://img-ask.csdn.net/upload/201707/31/1501509660_138809.png) <?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" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> <filter> <filter-name>encodingFilter</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> </filter> <filter-mapping> <filter-name>encodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <servlet> <servlet-name>springmvc</servlet-name> <servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:NETCTOSS.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springmvc</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> </web-app> 这是 web.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:context="http://www.springframework.org/schema/context" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:util="http://www.springframework.org/schema/util" 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.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd"> <!-- 配置组件扫描 --> <context:component-scan base-package="cn.tedu.netctoss"/> <!-- 配置MVC注解扫描 --> <mvc:annotation-driven /> <!-- 配置视图解析器 --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/"/> <property name="suffix" value=".jsp"/> </bean> <!-- 配置拦截器 --> <mvc:interceptors> <mvc:interceptor> <mvc:mapping path="/**"/> <mvc:exclude-mapping path="/toLogin.do"/> <bean class="cn.tedu.nectoss.interceptors.SessionInterceptor"/> </mvc:interceptor> </mvc:interceptors> <!-- 读取db.properties文件 --> <util:properties id="db" location="classpath:db.properties" /> <!-- 配置连接池 --> <bean id="ds" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="#{db.driver}"/> <property name="url" value="#{db.url}"/> <property name="username" value="#{db.user}"/> <property name="password" value="#{db.pwd}"/> </bean> <!-- 配置SqlSessionFactoryBean --> <bean id="ssfb" class="org.mybatis.spring.SqlSessionFactoryBean"> <!-- 指定连接池 --> <property name="dataSource" ref="ds"/> <!-- 指定映射文件 --> <property name="mapperLocations" value="cn/tedu/netctoss/entity/mapper/*.xml"/> </bean> <!-- 配置MapperScannerConfigurer *--> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <!-- 指定映射器所在的包名 --> <property name="basePackage" value="cn.tedu.netctoss.dao"/> <!-- 指定注解类 ****--> <!-- <property name="annotationClass" value=""/> --> </bean> </beans> 这是容器的设置 ![项目结构](https://img-ask.csdn.net/upload/201707/31/1501510038_931664.png) 另外:我用的是jdk1.6(系统有双jdk 1.6和1.8) 也试过高版本的spring-webmvc 还是报错 测试文件全部通过,包括dao层,Servlet层 但一在tomcat上跑就不行 ![Controller代码](https://img-ask.csdn.net/upload/201707/31/1501510216_810696.png) ![唯一的jsp文件](https://img-ask.csdn.net/upload/201707/31/1501510290_591488.png)
springMVC+ehcache 配置没有问题,但是缓存不起作用
照着网上的例子用springMVC+ehcache 基于注解的方式 实现缓存功能,配置 没有报错,但是 却不能实现 缓存。 :( 后来 我又用原先成功实现缓存的springAOP拦截器的方式, 也还是不能实现缓存,我觉得 可能是有些冲突或者是被拦截了。 具体代码如下,大家看看吧(这里用了springMVC+mybatis+ehcache): spring-config.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:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:aop="http://www.springframework.org/schema/aop" 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/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-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/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd" default-lazy-init="true"> <context:annotation-config /> <context:component-scan base-package="com.myword"> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" /> </context:component-scan> <!-- 载入properties文件 --> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="location" value="classpath:db.properties" /> </bean> <!-- 配置数据源(使用c3p0连接池 --> <!-- driverClass : 连接数据库的驱动; jdbcUrl : 连接数据库的URL ; user : 数据库用户名 ; password : 数据库用户密码 ; acquireIncrement : 当数据库缺乏连接时,需要增加多少新连接 ; idleConnectionTestPeriod : 连接在多久未使用之后自动关闭 ; maxPoolSize : 能够创建的最大连接数; maxStatements :一个链接能执行的最大sql语句数 ; minPoolSize : 创建的最小连接数 ; --> <!-- <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" > <property name="driverClassName" value="${db.driverClassName}"> </property> <property name="url" value="${db.url}"> </property> <property name="username" value="${db.username}"> </property> <property name="password" value="${db.password}"> </property> </bean> --> <!-- --> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <property name="driverClass" value="${db.driverClassName}" /> <property name="jdbcUrl" value="${db.url}" /> <property name="user" value="${db.username}" /> <property name="password" value="${db.password}" /> <property name="acquireIncrement" value="10" /> <property name="idleConnectionTestPeriod" value="60" /> <property name="maxPoolSize" value="100" /> <property name="maxStatements" value="50" /> <property name="minPoolSize" value="10" /> </bean> <!-- 配置sqlSessionFactory, 当使用MapperFactoryBean时configLocation没有必要添加 --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="configLocation"> <value>classpath:mybatis.xml</value> </property> <property name="dataSource" ref="dataSource" /> <property name="mapperLocations"> <list> <value>classpath:com/myword/mapper/*.xml</value> </list> </property> </bean> <!-- 扫描mapper接口--> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer" > <property name="basePackage" value="com.myword.mapper"></property> </bean> <!-- 配置事务管理器 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /> </bean> <!-- 开启使用注解配置事务 --> <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/> </beans> spring-mvc.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:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p" xmlns:ehcache="http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring" xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd"> <context:component-scan base-package="com.myword" > <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service"/> </context:component-scan> <!-- 开启springmvc的注解支持 --> <mvc:annotation-driven /> <!-- 防止静态资源被过滤器拦截 --> <mvc:resources mapping="/extjs4/**" location="/extjs4/" /> <mvc:resources mapping="/app/**" location="/app/" /> <mvc:resources mapping="/res/**" location="/res/" /> <mvc:resources mapping="/console.js" location="/console.js" /> <mvc:resources mapping="/app.js" location="/app.js" /> <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <property name="defaultEncoding" value="utf-8"/> <property name="maxUploadSize" value="800000000"/> </bean> <bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"> <property name="ignoreAcceptHeader" value="true" /> <property name="defaultContentType" value="text/html" /> <property name="order" value="1" /> <!--扩展名至mimeType的映射,即 /user.json => application/json--> <property name="mediaTypes"> <map> <entry key="json" value="application/json" /> <entry key="xml" value="application/xml" /> </map> </property> <property name="viewResolvers"> <list> <bean class="org.springframework.web.servlet.view.BeanNameViewResolver" /> <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=".jsp" /> <!--重定向返回默认添加后缀--> </bean> </list> </property> <property name="defaultViews"> <list> <bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" /> </list> </property> </bean> <ehcache:annotation-driven /> <ehcache:config cache-manager="cacheManager"> <ehcache:evict-expired-elements interval="60" /> </ehcache:config> <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"> <property name="configLocation" > <value>classpath:ehcache.xml</value> </property> </bean> 主要的配置 就是这两个,其他导入的 ehcache.xml和mybatis.xml就没有贴出来了。 service 的javabean: @Service public class UsersServI implements UsersServ{ @Autowired private UsersMapper usersMapper; @Cacheable("baseCache") public List<Users> getUsersAll(UsersExample example) { System.out.println("======ok======"); return usersMapper.selectByExample(example); } action 中的打印处理: Cache baseCache = manager.getCache("baseCache"); System.out.println("Cache named baseCache:"+baseCache); System.out.println("============one==============="); UsersExample example = new UsersExample(); usersServ.getUsersAll(example); System.out.println("============two==============="); usersServ.getUsersAll(example); 结果发现 执行后 后台打印出: Cache named baseCache:[ name = baseCache status = STATUS_ALIVE eternal = false overflowToDisk = true maxEntriesLocalHeap = 10000 maxEntriesLocalDisk = 0 memoryStoreEvictionPolicy = LRU timeToLiveSeconds = 600000 timeToIdleSeconds = 300000 persistence = none diskExpiryThreadIntervalSeconds = 120 cacheEventListeners: net.sf.ehcache.statistics.LiveCacheStatisticsWrapper hitCount = 0 memoryStoreHitCount = 0 diskStoreHitCount = 0 missCountNotFound = 0 missCountExpired = 0 maxBytesLocalHeap = 0 overflowToOffHeap = false maxBytesLocalOffHeap = 0 maxBytesLocalDisk = 0 pinned = false ] ============one=============== ======ok====== ============two=============== ======ok====== 第一个打印"Cache named ..."说明ehcache配置是成功的,ehcache.xml中的cache name 也被打印出来了。 但是 后面getUsersAll方法却被执行了两次 说明 ehcache根本没有起作用。到底哪里出问题了呀?
Spring + Hibernate4 无法将数据写入数据【请教】
<div class="iteye-blog-content-contain" style="font-size: 14px;"> <p class="MsoNormal" style="text-align: center;" align="center"> </p> <p class="MsoNormal"><span lang="EN-US"> 问题:</span></p> <p class="MsoNormal"><span lang="EN-US">通过Junit单元测试Service可以将数据写入数据库;但部署却无法向数据库写入数据。</span></p> <h1> <strong><span lang="EN-US">1、</span></strong><span lang="EN-US"><strong>环境</strong>:</span> </h1> <p class="MsoListParagraph" style="margin-left: 18.0pt; text-indent: 0cm;"><span lang="EN-US">Spring 3.1.2</span></p> <p class="MsoListParagraph" style="margin-left: 18.0pt; text-indent: 0cm;"><span lang="EN-US">Hibernate 4.1.4</span></p> <p class="MsoListParagraph" style="margin-left: 18.0pt; text-indent: 0cm;"><span lang="EN-US">Jdk1.6</span></p> <h1>2、配置:</h1> <p class="MsoListParagraph">&lt;!--[if !supportLists]--&gt;<strong><span lang="EN-US">1<span lang="EN-US">     </span></span></strong>&lt;!--[endif]--&gt;<strong><span lang="EN-US"> </span></strong></p> <p class="MsoListParagraph">&lt;!--[if !supportLists]--&gt;<strong><span lang="EN-US">2<span lang="EN-US">     </span></span></strong>&lt;!--[endif]--&gt;<strong><span lang="EN-US"> </span></strong></p> <h2> <span lang="EN-US">2.1、</span><span lang="EN-US">Web.xml</span> </h2> <p class="MsoNormal" align="left"><span lang="EN-US">&lt;?</span><span lang="EN-US">xml</span><span lang="EN-US"> <span lang="EN-US">version</span>=<em><span lang="EN-US">"1.0"</span></em> <span lang="EN-US">encoding</span>=<em><span lang="EN-US">"UTF-8"</span></em><span lang="EN-US">?&gt;</span></span></p> <p class="MsoNormal" align="left"><span lang="EN-US"> </span></p> <p class="MsoNormal" align="left"><span lang="EN-US">&lt;</span><span lang="EN-US">web-app</span><span lang="EN-US"> <span lang="EN-US">xmlns:xsi</span>=<em><span lang="EN-US">"http://www.w3.org/2001/XMLSchema-instance"</span></em> <span lang="EN-US">xmlns</span>=<em><span lang="EN-US">"http://java.sun.com/xml/ns/javaee"</span></em> <span lang="EN-US">xmlns:web</span>=<em><span lang="EN-US">"http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"</span></em> <span lang="EN-US">xsi:schemaLocation</span>=<em><span lang="EN-US">"http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"</span></em> <span lang="EN-US">id</span>=<em><span lang="EN-US">"WebApp_ID"</span></em> <span lang="EN-US">version</span>=<em><span lang="EN-US">"2.5"</span></em><span lang="EN-US">&gt;</span></span></p> <p class="MsoNormal" align="left"><span lang="EN-US">     </span><span lang="EN-US">&lt;</span><span lang="EN-US">display-name</span><span lang="EN-US">&gt;</span><span style="text-decoration: underline;"><span lang="EN-US">springmvc</span></span><span lang="EN-US">&lt;/</span><span lang="EN-US">display-name</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">     </span><span lang="EN-US">&lt;</span><span lang="EN-US">welcome-file-list</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">        </span><span lang="EN-US">&lt;</span><span lang="EN-US">welcome-file</span><span lang="EN-US">&gt;</span><span lang="EN-US">index.html</span><span lang="EN-US">&lt;/</span><span lang="EN-US">welcome-file</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">        </span><span lang="EN-US">&lt;</span><span lang="EN-US">welcome-file</span><span lang="EN-US">&gt;</span><span lang="EN-US">index.htm</span><span lang="EN-US">&lt;/</span><span lang="EN-US">welcome-file</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">        </span><span lang="EN-US">&lt;</span><span lang="EN-US">welcome-file</span><span lang="EN-US">&gt;</span><span lang="EN-US">index.jsp</span><span lang="EN-US">&lt;/</span><span lang="EN-US">welcome-file</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">     </span><span lang="EN-US">&lt;/</span><span lang="EN-US">welcome-file-list</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">     </span></p> <p class="MsoNormal" align="left"><span lang="EN-US">     </span><span lang="EN-US">&lt;!-- Spring ApplicationContext</span><span lang="EN-US">配置文件的路径</span><span lang="EN-US">,</span><span lang="EN-US">可使用通配符</span><span lang="EN-US">,</span><span lang="EN-US">多个路径用</span><span lang="EN-US">,</span><span lang="EN-US">号分隔</span><span lang="EN-US">此参数用于后面的</span><span lang="EN-US">Spring Context Loader --&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">     </span><span lang="EN-US">&lt;</span><span lang="EN-US">context-param</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">       </span><span lang="EN-US">&lt;</span><span lang="EN-US">param-name</span><span lang="EN-US">&gt;</span><span lang="EN-US">contextConfigLocation</span><span lang="EN-US">&lt;/</span><span lang="EN-US">param-name</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">       </span><span lang="EN-US">&lt;</span><span lang="EN-US">param-value</span><span lang="EN-US">&gt;</span><span style="text-decoration: underline;"><span lang="EN-US">classpath</span></span><span lang="EN-US">*:/applicationContext.xml</span><span lang="EN-US">&lt;/</span><span lang="EN-US">param-value</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">     </span><span lang="EN-US">&lt;/</span><span lang="EN-US">context-param</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">     </span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;</span><span lang="EN-US">listener</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">        </span><span lang="EN-US">&lt;</span><span lang="EN-US">listener-class</span><span lang="EN-US">&gt;</span><span lang="EN-US">org.springframework.web.context.ContextLoaderListener</span><span lang="EN-US">&lt;/</span><span lang="EN-US">listener-class</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;/</span><span lang="EN-US">listener</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;!--<span style="text-decoration: underline;">Dispathcer</span> <span style="text-decoration: underline;">Servlet</span> --&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;</span><span lang="EN-US">servlet</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">        </span><span lang="EN-US">&lt;</span><span lang="EN-US">servlet-name</span><span lang="EN-US">&gt;</span><span lang="EN-US">spring-<span style="text-decoration: underline;">mvc</span></span><span lang="EN-US">&lt;/</span><span lang="EN-US">servlet-name</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">        </span><span lang="EN-US">&lt;</span><span lang="EN-US">servlet-class</span><span lang="EN-US">&gt;</span><span lang="EN-US">org.springframework.web.servlet.DispatcherServlet</span><span lang="EN-US">&lt;/</span><span lang="EN-US">servlet-class</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">        </span><span lang="EN-US">&lt;</span><span lang="EN-US">init-param</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">            </span><span lang="EN-US">&lt;</span><span lang="EN-US">param-name</span><span lang="EN-US">&gt;</span><span lang="EN-US">contextConfigLocation</span><span lang="EN-US">&lt;/</span><span lang="EN-US">param-name</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">            </span><span lang="EN-US">&lt;</span><span lang="EN-US">param-value</span><span lang="EN-US">&gt;</span><span lang="EN-US">/WEB-INF/spring-mvc.xml</span><span lang="EN-US">&lt;/</span><span lang="EN-US">param-value</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">        </span><span lang="EN-US">&lt;/</span><span lang="EN-US">init-param</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">        </span><span lang="EN-US">&lt;</span><span lang="EN-US">load-on-startup</span><span lang="EN-US">&gt;</span><span lang="EN-US">1</span><span lang="EN-US">&lt;/</span><span lang="EN-US">load-on-startup</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;/</span><span lang="EN-US">servlet</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;!-- Spring MVC <span style="text-decoration: underline;">Servlet</span> </span><span lang="EN-US">拦截</span><span lang="EN-US">.do</span><span lang="EN-US">结尾的请求</span><span lang="EN-US">--&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;</span><span lang="EN-US">servlet-mapping</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">        </span><span lang="EN-US">&lt;</span><span lang="EN-US">servlet-name</span><span lang="EN-US">&gt;</span><span lang="EN-US">spring-<span style="text-decoration: underline;">mvc</span></span><span lang="EN-US">&lt;/</span><span lang="EN-US">servlet-name</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">        </span><span lang="EN-US">&lt;</span><span lang="EN-US">url-pattern</span><span lang="EN-US">&gt;</span><span lang="EN-US">*.do</span><span lang="EN-US">&lt;/</span><span lang="EN-US">url-pattern</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;/</span><span lang="EN-US">servlet-mapping</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;!-- Filter </span><span lang="EN-US">定义</span><span lang="EN-US"> --&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;</span><span lang="EN-US">filter</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">        </span><span lang="EN-US">&lt;</span><span lang="EN-US">filter-name</span><span lang="EN-US">&gt;</span><span lang="EN-US">encodingFilter</span><span lang="EN-US">&lt;/</span><span lang="EN-US">filter-name</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">        </span><span lang="EN-US">&lt;</span><span lang="EN-US">filter-class</span><span lang="EN-US">&gt;</span><span lang="EN-US">org.springframework.web.filter.CharacterEncodingFilter</span><span lang="EN-US">&lt;/</span><span lang="EN-US">filter-class</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">        </span><span lang="EN-US">&lt;</span><span lang="EN-US">init-param</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">            </span><span lang="EN-US">&lt;</span><span lang="EN-US">param-name</span><span lang="EN-US">&gt;</span><span lang="EN-US">encoding</span><span lang="EN-US">&lt;/</span><span lang="EN-US">param-name</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">            </span><span lang="EN-US">&lt;</span><span lang="EN-US">param-value</span><span lang="EN-US">&gt;</span><span lang="EN-US">UTF-8</span><span lang="EN-US">&lt;/</span><span lang="EN-US">param-value</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">        </span><span lang="EN-US">&lt;/</span><span lang="EN-US">init-param</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">        </span><span lang="EN-US">&lt;</span><span lang="EN-US">init-param</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">            </span><span lang="EN-US">&lt;</span><span lang="EN-US">param-name</span><span lang="EN-US">&gt;</span><span lang="EN-US">forceEncoding</span><span lang="EN-US">&lt;/</span><span lang="EN-US">param-name</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">            </span><span lang="EN-US">&lt;</span><span lang="EN-US">param-value</span><span lang="EN-US">&gt;</span><span lang="EN-US">true</span><span lang="EN-US">&lt;/</span><span lang="EN-US">param-value</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">        </span><span lang="EN-US">&lt;/</span><span lang="EN-US">init-param</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;/</span><span lang="EN-US">filter</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;</span><span lang="EN-US">filter-mapping</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">        </span><span lang="EN-US">&lt;</span><span lang="EN-US">filter-name</span><span lang="EN-US">&gt;</span><span lang="EN-US">encodingFilter</span><span lang="EN-US">&lt;/</span><span lang="EN-US">filter-name</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">        </span><span lang="EN-US">&lt;</span><span lang="EN-US">url-pattern</span><span lang="EN-US">&gt;</span><span lang="EN-US">/*</span><span lang="EN-US">&lt;/</span><span lang="EN-US">url-pattern</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;/</span><span lang="EN-US">filter-mapping</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span></p> <p class="MsoNormal" align="left"><span lang="EN-US">   </span><span lang="EN-US">&lt;!--openSessionInView--&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">   </span><span lang="EN-US">&lt;</span><span lang="EN-US">filter</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">       </span><span lang="EN-US">&lt;</span><span lang="EN-US">filter-name</span><span lang="EN-US">&gt;</span><span lang="EN-US">openSessionInView</span><span lang="EN-US">&lt;/</span><span lang="EN-US">filter-name</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;</span><span lang="EN-US">filter-class</span><span lang="EN-US">&gt;</span><span lang="EN-US">org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</span><span lang="EN-US">&lt;/</span><span lang="EN-US">filter-class</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">       </span><span lang="EN-US">&lt;</span><span lang="EN-US">init-param</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">           </span><span lang="EN-US">&lt;</span><span lang="EN-US">param-name</span><span lang="EN-US">&gt;</span><span lang="EN-US">sessionFactoryBeanName</span><span lang="EN-US">&lt;/</span><span lang="EN-US">param-name</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">           </span><span lang="EN-US">&lt;</span><span lang="EN-US">param-value</span><span lang="EN-US">&gt;</span><span lang="EN-US">sessionFactory</span><span lang="EN-US">&lt;/</span><span lang="EN-US">param-value</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">       </span><span lang="EN-US">&lt;/</span><span lang="EN-US">init-param</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;/</span><span lang="EN-US">filter</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US"> </span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;</span><span lang="EN-US">filter-mapping</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">       </span><span lang="EN-US">&lt;</span><span lang="EN-US">filter-name</span><span lang="EN-US">&gt;</span><span lang="EN-US">openSessionInView</span><span lang="EN-US">&lt;/</span><span lang="EN-US">filter-name</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">       </span><span lang="EN-US">&lt;</span><span lang="EN-US">url-pattern</span><span lang="EN-US">&gt;</span><span lang="EN-US">/*</span><span lang="EN-US">&lt;/</span><span lang="EN-US">url-pattern</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;/</span><span lang="EN-US">filter-mapping</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US"> </span></p> <p class="MsoListParagraph" style="margin-left: 18.0pt; text-indent: 0cm;"><span lang="EN-US">&lt;/</span><span lang="EN-US">web-app</span><span lang="EN-US">&gt;</span></p> <h2> <span lang="EN-US">2.2<span lang="EN-US">     </span></span><span lang="EN-US">applicationContext.xml</span> </h2> <p class="MsoNormal"><span lang="EN-US">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">&lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:util="http://www.springframework.org/schema/util" xmlns:aop="http://www.springframework.org/schema/aop" 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/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd "&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">          &lt;!--</span><span lang="EN-US">扫描并自动装配</span><span lang="EN-US"> --&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">         &lt;context:annotation-config /&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">         &lt;context:component-scan base-package="com.sp" /&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">         </span></p> <p class="MsoNormal"><span lang="EN-US">   &lt;bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                   &lt;property name="locations"&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                            &lt;value&gt;classpath:application.properties&lt;/value&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                   &lt;/property&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">         &lt;/bean&gt;</span></p> <p class="MsoNormal"><span lang="EN-US"> </span></p> <p class="MsoNormal"><span lang="EN-US">   &lt;!-- </span><span lang="EN-US">数据源配置</span><span lang="EN-US"> --&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">    &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">        &lt;!-- Connection Info --&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">        &lt;property name="driverClassName" value="${jdbc.driver}" /&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">        &lt;property name="url" value="${jdbc.url}" /&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">        &lt;property name="username" value="${jdbc.username}" /&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">        &lt;property name="password" value="${jdbc.password}" /&gt;</span></p> <p class="MsoNormal"><span lang="EN-US"> </span></p> <p class="MsoNormal"><span lang="EN-US">        &lt;!-- Connection Pooling Info --&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">        &lt;property name="maxActive" value="${dbcp.maxActive}" /&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">        &lt;property name="maxIdle" value="${dbcp.maxIdle}" /&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">        &lt;property name="defaultAutoCommit" value="false" /&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">        </span></p> <p class="MsoNormal"><span lang="EN-US">        &lt;!-- </span><span lang="EN-US">连接</span><span lang="EN-US">Idle</span><span lang="EN-US">一个小时后超时</span><span lang="EN-US"> --&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">        &lt;property name="timeBetweenEvictionRunsMillis" value="3600000" /&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">        &lt;property name="minEvictableIdleTimeMillis" value="3600000" /&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">    &lt;/bean&gt;</span></p> <p class="MsoNormal"><span lang="EN-US"> </span></p> <p class="MsoNormal"><span lang="EN-US">         &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                   &lt;property name="dataSource" ref="dataSource"&gt;&lt;/property&gt;              </span></p> <p class="MsoNormal"><span lang="EN-US">                   &lt;property name="hibernateProperties"&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                            &lt;props&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                                     &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/prop&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                                     &lt;prop key="hibernate.hbm2ddl.auto"&gt;update&lt;/prop&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                                     &lt;prop key="hibernate.connection.autocommit"&gt;true&lt;/prop&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                                     &lt;prop key="hibernate.current_session_context_class"&gt;org.springframework.orm.hibernate4.SpringSessionContext&lt;/prop&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                                     &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                                     &lt;prop key="hibernate.format_sql"&gt;true&lt;/prop&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                            &lt;/props&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                   &lt;/property&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                   </span></p> <p class="MsoNormal"><span lang="EN-US">                   &lt;property name="packagesToScan"&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                            &lt;list&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                                     &lt;value&gt;com.sp.dao&lt;/value&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                                     &lt;value&gt;com.sp.entity.dict&lt;/value&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                            &lt;/list&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                   &lt;/property&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">         &lt;/bean&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">         </span></p> <p class="MsoNormal"><span lang="EN-US">         &lt;bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager" abstract="false" lazy-init="default" autowire="default"&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                   &lt;property name="sessionFactory"&gt;&lt;ref bean="sessionFactory" /&gt;&lt;/property&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">         &lt;/bean&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">         </span></p> <p class="MsoNormal"><span lang="EN-US">         &lt;!-- </span><span lang="EN-US">事务管理配置</span><span lang="EN-US"> --&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">         &lt;!--&lt;tx:annotation-driven transaction-manager="transactionManager"&gt;&lt;/tx:annotation-driven&gt;--&gt; </span></p> <p class="MsoNormal"><span lang="EN-US">         &lt;tx:advice id="txAdvice" transaction-manager="transactionManager"&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                   &lt;tx:attributes&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                            &lt;tx:method name="insert*" read-only="false" propagation="REQUIRED" /&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                            &lt;tx:method name="get*" read-only="false" propagation="REQUIRED" /&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">            &lt;tx:method name="add*" read-only="false" propagation="REQUIRED" /&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">            &lt;tx:method name="update*" read-only="false" propagation="REQUIRED" /&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">            &lt;tx:method name="delete*" read-only="false" propagation="REQUIRED" /&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                   &lt;/tx:attributes&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">         &lt;/tx:advice&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">         </span></p> <p class="MsoNormal"><span lang="EN-US">         &lt;aop:config&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                   &lt;aop:advisor pointcut="execution(* com.sp.service.*.*(..))"  advice-ref="txAdvice"/&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">         &lt;/aop:config&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">&lt;/beans&gt;</span></p> <p class="MsoNormal"><span lang="EN-US"> </span></p> <h2> <span lang="EN-US">2.3<span lang="EN-US"> </span></span><span lang="EN-US">spring-mvc.xml</span> </h2> <p class="MsoNormal"><span lang="EN-US">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">&lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"</span></p> <p class="MsoNormal"><span lang="EN-US">         xmlns:context="http://www.springframework.org/schema/context"</span></p> <p class="MsoNormal"><span lang="EN-US">         xmlns:mvc="http://www.springframework.org/schema/mvc"</span></p> <p class="MsoNormal"><span lang="EN-US">         xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd</span></p> <p class="MsoNormal"><span lang="EN-US">                   http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd</span></p> <p class="MsoNormal"><span lang="EN-US">        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd"&gt;</span></p> <p class="MsoNormal"><span lang="EN-US"> </span></p> <p class="MsoNormal"><span lang="EN-US">         &lt;!-- </span><span lang="EN-US">启动注解驱动的</span><span lang="EN-US">SpringMVC</span><span lang="EN-US">功能,注册请求</span><span lang="EN-US">URL</span><span lang="EN-US">和注解</span><span lang="EN-US">POJO</span><span lang="EN-US">类方法的映射</span><span lang="EN-US"> --&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">         &lt;mvc:annotation-driven /&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">         </span></p> <p class="MsoNormal"><span lang="EN-US">         &lt;!-- </span><span lang="EN-US">自动扫描且只扫描</span><span lang="EN-US">@Controller --&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">         &lt;context:component-scan base-package="com.sp.web" use-default-filters="false"&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                   &lt;context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" /&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">         &lt;/context:component-scan&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">         </span></p> <p class="MsoNormal"><span lang="EN-US">         &lt;context:component-scan base-package="com.sp.dao.impl"&gt;&lt;/context:component-scan&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">         &lt;context:component-scan base-package="com.sp.service.impl"&gt;&lt;/context:component-scan&gt;</span></p> <p class="MsoNormal"><span lang="EN-US"> </span></p> <p class="MsoNormal"><span lang="EN-US">         &lt;mvc:default-servlet-handler /&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                   </span></p> <p class="MsoNormal"><span lang="EN-US">         &lt;!-- </span><span lang="EN-US">对模型视图名称的解析,在请求时模型视图名称添加后缀。定义</span><span lang="EN-US">JSP --&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">         &lt;bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                   &lt;property name="prefix" value="/WEB-INF/views/" /&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">                   &lt;property name="suffix" value=".jsp" /&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">         &lt;/bean&gt;</span></p> <p class="MsoNormal"><span lang="EN-US"> </span></p> <p class="MsoNormal"><span lang="EN-US">         &lt;!-- </span><span lang="EN-US">支持上传文件</span><span lang="EN-US"> --&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">         &lt;bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver" /&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">&lt;/beans&gt;</span></p> <p class="MsoNormal"><span lang="EN-US"> </span></p> <h2> <span lang="EN-US">2.4<span lang="EN-US">  </span></span><span lang="EN-US">hibernate.cfg.xml</span> </h2> <p class="MsoNormal" align="left"><span lang="EN-US">&lt;?</span><span lang="EN-US">xml</span><span lang="EN-US"> <span lang="EN-US">version</span>=<em><span lang="EN-US">'1.0'</span></em> <span lang="EN-US">encoding</span>=<em><span lang="EN-US">'utf-8'</span></em><span lang="EN-US">?&gt;</span></span></p> <p class="MsoNormal" align="left"><span lang="EN-US">&lt;!</span><span lang="EN-US">DOCTYPE</span><span lang="EN-US"> <span lang="EN-US">hibernate-configuration</span> <span lang="EN-US">PUBLIC</span></span></p> <p class="MsoNormal" align="left"><span lang="EN-US">     <span lang="EN-US">"-//Hibernate/Hibernate Configuration DTD 3.0//EN"</span></span></p> <p class="MsoNormal" align="left"><span lang="EN-US">     <span lang="EN-US">"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"</span><span lang="EN-US">&gt;</span></span></p> <p class="MsoNormal" align="left"><span lang="EN-US">        </span></p> <p class="MsoNormal" align="left"><span lang="EN-US">&lt;</span><span lang="EN-US">hibernate-configuration</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">  </span><span lang="EN-US">&lt;</span><span lang="EN-US">session-factory</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;!-- Database connection settings--&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;</span><span lang="EN-US">property</span><span lang="EN-US"> <span lang="EN-US">name</span>=<em><span lang="EN-US">"connection.driver_class"</span></em><span lang="EN-US">&gt;</span>com.mysql.jdbc.Driver<span lang="EN-US">&lt;/</span><span lang="EN-US">property</span><span lang="EN-US">&gt;</span></span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;</span><span lang="EN-US">property</span><span lang="EN-US"> <span lang="EN-US">name</span>=<em><span lang="EN-US">"connection.url"</span></em><span lang="EN-US">&gt;</span>jdbc:mysql://<span style="text-decoration: underline;">localhost</span>:3306/test<span lang="EN-US">&lt;/</span><span lang="EN-US">property</span><span lang="EN-US">&gt;</span></span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;</span><span lang="EN-US">property</span><span lang="EN-US"> <span lang="EN-US">name</span>=<em><span lang="EN-US">"connection.username"</span></em><span lang="EN-US">&gt;</span>root<span lang="EN-US">&lt;/</span><span lang="EN-US">property</span><span lang="EN-US">&gt;</span></span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;</span><span lang="EN-US">property</span><span lang="EN-US"> <span lang="EN-US">name</span>=<em><span lang="EN-US">"connection.password"</span></em><span lang="EN-US">&gt;</span>password<span lang="EN-US">&lt;/</span><span lang="EN-US">property</span><span lang="EN-US">&gt;</span></span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;!-- JDBC connection pool (use the built-in) --&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;</span><span lang="EN-US">property</span><span lang="EN-US"> <span lang="EN-US">name</span>=<em><span lang="EN-US">"connection.pool_size"</span></em><span lang="EN-US">&gt;</span>1<span lang="EN-US">&lt;/</span><span lang="EN-US">property</span><span lang="EN-US">&gt;</span></span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;!-- SQL dialect </span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    &lt;property name="dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/property&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    --&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;!-- Enable Hibernate's automatic session context management --&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;!-- &lt;property name="current_session_context_class"&gt;thread&lt;/property&gt; --&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US"> </span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;!-- Disable the second-level cache  --&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;!-- &lt;property name="cache.provider_class"&gt;org.hibernate.cache.internal.NoCacheProvider&lt;/property&gt;--&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;!-- Echo all executed SQL to <span style="text-decoration: underline;">stdout</span> --&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;</span><span lang="EN-US">property</span><span lang="EN-US"> <span lang="EN-US">name</span>=<em><span lang="EN-US">"show_sql"</span></em><span lang="EN-US">&gt;</span>true<span lang="EN-US">&lt;/</span><span lang="EN-US">property</span><span lang="EN-US">&gt;</span></span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;</span><span lang="EN-US">property</span><span lang="EN-US"> <span lang="EN-US">name</span>=<em><span lang="EN-US">"format_sql"</span></em><span lang="EN-US">&gt;</span>true<span lang="EN-US">&lt;/</span><span lang="EN-US">property</span><span lang="EN-US">&gt;</span></span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;!-- Drop and re-create the database schema on startup--&gt;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;</span><span lang="EN-US">property</span><span lang="EN-US"> <span lang="EN-US">name</span>=<em><span lang="EN-US">"hbm2ddl.auto"</span></em><span lang="EN-US">&gt;</span>update<span lang="EN-US">&lt;/</span><span lang="EN-US">property</span><span lang="EN-US">&gt;</span></span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">&lt;</span><span lang="EN-US">property</span><span lang="EN-US"> <span lang="EN-US">name</span>=<em><span lang="EN-US">"javax.persistence.validation.mode"</span></em><span lang="EN-US">&gt;</span>none<span lang="EN-US">&lt;/</span><span lang="EN-US">property</span><span lang="EN-US">&gt;</span></span></p> <p class="MsoNormal" align="left"><span lang="EN-US">     </span></p> <p class="MsoNormal" align="left"><span lang="EN-US">  </span><span lang="EN-US">&lt;/</span><span lang="EN-US">session-factory</span><span lang="EN-US">&gt;</span></p> <p class="MsoNormal"><span lang="EN-US">&lt;/</span><span lang="EN-US">hibernate-configuration</span><span lang="EN-US">&gt;</span></p> <p class="MsoListParagraph" style="margin-left: 18.0pt; text-indent: 0cm;"><strong><span lang="EN-US"> </span></strong></p> <h1> <span lang="EN-US">3<span lang="EN-US">         </span></span><span lang="EN-US">代码:</span> </h1> <p class="MsoListParagraph">&lt;!--[if !supportLists]--&gt;<strong><span lang="EN-US">1<span lang="EN-US">     </span></span></strong>&lt;!--[endif]--&gt;<strong><span lang="EN-US"> </span></strong></p> <p class="MsoListParagraph">&lt;!--[if !supportLists]--&gt;<strong><span lang="EN-US">2<span lang="EN-US">     </span></span></strong>&lt;!--[endif]--&gt;<strong><span lang="EN-US"> </span></strong></p> <p class="MsoListParagraph">&lt;!--[if !supportLists]--&gt;<strong><span lang="EN-US">3<span lang="EN-US">     </span></span></strong>&lt;!--[endif]--&gt;<strong><span lang="EN-US"> </span></strong></p> <h2> <span lang="EN-US">3.1<span lang="EN-US">  </span></span><span lang="EN-US">Service</span><span lang="EN-US">层:</span> </h2> <p class="MsoNormal" align="left"><span lang="EN-US">@Component</span><span lang="EN-US">(</span><span lang="EN-US">"userService"</span><span lang="EN-US">)</span></p> <p class="MsoNormal" align="left"><strong><span lang="EN-US">public</span></strong><strong><span lang="EN-US">class</span></strong><span lang="EN-US"> UserServiceImpl </span><strong><span lang="EN-US">implements</span></strong><span lang="EN-US"> UserService{</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">@<span lang="EN-US">Autowired</span></span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><strong><span lang="EN-US">private</span></strong><span lang="EN-US"> UserDao </span><span lang="EN-US">userDao</span><span lang="EN-US">;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US"> </span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">@<span lang="EN-US">Autowired</span></span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><strong><span lang="EN-US">private</span></strong><span lang="EN-US"> FormValidator </span><span lang="EN-US">validator</span><span lang="EN-US">;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">@Override</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><strong><span lang="EN-US">public</span></strong><span lang="EN-US"> String userLogin(UserModel user) {</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">       String password = </span><span lang="EN-US">userDao</span><span lang="EN-US">.userLogin(user);</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">       </span><strong><span lang="EN-US">if</span></strong><span lang="EN-US">(password.equals(user.getPassword())){</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">           </span><strong><span lang="EN-US">return</span></strong><span lang="EN-US">"sucess"</span><span lang="EN-US">;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">       }</span><strong><span lang="EN-US">else</span></strong><span lang="EN-US">{</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">           </span><strong><span lang="EN-US">return</span></strong><span lang="EN-US">"false"</span><span lang="EN-US">;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">       }</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    }</span></p> <p class="MsoNormal" align="left"><span lang="EN-US"> </span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">@Override</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><strong><span lang="EN-US">public</span></strong><span lang="EN-US"> List&lt;ProjectType&gt; getAllProjectTypes(){</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">       List&lt;ProjectType&gt; projectType = </span><span lang="EN-US">userDao</span><span lang="EN-US">.getAllProjectTypes();</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">       </span><strong><span lang="EN-US">return</span></strong><span lang="EN-US"> projectType;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    }</span></p> <p class="MsoNormal" align="left"><span lang="EN-US"> </span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">//</span><span lang="EN-US">添加《项目类型》</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">@Override</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><strong><span lang="EN-US">public</span></strong><span lang="EN-US"> String addProjectType(</span><span lang="EN-US">@ModelAttribute</span><span lang="EN-US">(</span><span lang="EN-US">"newProjectType"</span><span lang="EN-US">)ProjectType projectType,BindingResult result,SessionStatus status){</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">       </span><span lang="EN-US">validator</span><span lang="EN-US">.validate(projectType, result);</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">       </span><strong><span lang="EN-US">if</span></strong><span lang="EN-US">(result.hasErrors()){</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">           </span><strong><span lang="EN-US">return</span></strong><span lang="EN-US">"newProjectType"</span><span lang="EN-US">;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">       }</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">       </span><span lang="EN-US">userDao</span><span lang="EN-US">.save(projectType);</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">       </span><span lang="EN-US">//status.setComplete();</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">       </span><strong><span lang="EN-US">return</span></strong><span lang="EN-US">"redirect:showProjectTypes.do"</span><span lang="EN-US">;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    }</span></p> <p class="MsoNormal" align="left"><span lang="EN-US"> </span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">//</span><span lang="EN-US">添加《项目类型》</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><span lang="EN-US">@Override</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    </span><strong><span lang="EN-US">public</span></strong><span lang="EN-US"> String addProjectType(ProjectType projectType) {</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">       </span><span lang="EN-US">userDao</span><span lang="EN-US">.save(projectType);</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">       </span><strong><span lang="EN-US">return</span></strong><span lang="EN-US">"redirect:showProjectTypes.do"</span><span lang="EN-US">;</span></p> <p class="MsoNormal" align="left"><span lang="EN-US">    }</span></p> <p class="MsoNormal"><span lang="EN-US">}</span></p> <h2> <span lang="EN-US">3.2<span lang="EN-US">   </span></span><span lang="EN-US">Control</span><span lang="EN-US">层</span> </h2> <p class="MsoNormal"><span lang="EN-US">@Controller</span></p> <p class="MsoNormal"><span lang="EN-US">@RequestMapping(value = "/user")</span></p> <p class="MsoNormal"><span lang="EN-US">public class UserController {</span></p> <p class="MsoNormal"><span lang="EN-US"> </span></p> <p class="MsoNormal"><span lang="EN-US">         @Autowired</span></p> <p class="MsoNormal"><span lang="EN-US">         private UserService userService;</span></p> <p class="MsoNormal"><span lang="EN-US">         </span></p> <p class="MsoNormal"><span lang="EN-US">    @Autowired</span></p> <p class="MsoNormal"><span lang="EN-US">    private FormValidator validator;</span></p> <p class="MsoNormal"><span lang="EN-US">    </span></p> <p class="MsoNormal"><span lang="EN-US">         @RequestMapping(value = "/login",method=RequestMethod.POST)</span></p> <p class="MsoNormal"><span lang="EN-US">         protected String handle(UserModel user,BindingResult result, Model model){</span></p> <p class="MsoNormal"><span lang="EN-US">                   String flag = userService.userLogin(user);</span></p> <p class="MsoNormal"><span lang="EN-US">                   System.out.println("flag:" + flag);</span></p> <p class="MsoNormal"><span lang="EN-US">                   if ("sucess".equals(flag)){</span></p> <p class="MsoNormal"><span lang="EN-US">                            return "sucess";</span></p> <p class="MsoNormal"><span lang="EN-US">                   }</span></p> <p class="MsoNormal"><span lang="EN-US">                   return "test1";</span></p> <p class="MsoNormal"><span lang="EN-US">         }</span></p> <p class="MsoNormal"><span lang="EN-US">         </span></p> <p class="MsoNormal"><span lang="EN-US">         @RequestMapping(value = "/showProjectTypes")</span></p> <p class="MsoNormal"><span lang="EN-US">         protected ModelAndView getAllProjectTypes(){</span></p> <p class="MsoNormal"><span lang="EN-US">                   ModelAndView mav = new ModelAndView("showProjectTypes");</span></p> <p class="MsoNormal"><span lang="EN-US">                   List&lt;ProjectType&gt; projectTypes = userService.getAllProjectTypes();</span></p> <p class="MsoNormal"><span lang="EN-US">                   mav.addObject("SEARCH_PROJECTTYPE_RESULTS_KEY", projectTypes);</span></p> <p class="MsoNormal"><span lang="EN-US">                   return mav;</span></p> <p class="MsoNormal"><span lang="EN-US">         }</span></p> <p class="MsoNormal"><span lang="EN-US">         </span></p> <p class="MsoNormal"><span lang="EN-US">         @RequestMapping(value = "/addProjectType",method=RequestMethod.GET)</span></p> <p class="MsoNormal"><span lang="EN-US">         protected ModelAndView newProjectTypeForm(){</span></p> <p class="MsoNormal"><span lang="EN-US">                   ModelAndView mav = new ModelAndView("newProjectType");</span></p> <p class="MsoNormal"><span lang="EN-US">                   ProjectType projectType = new ProjectType();</span></p> <p class="MsoNormal"><span lang="EN-US">                   mav.getModelMap().put("newProjectType", projectType);</span></p> <p class="MsoNormal"><span lang="EN-US">                   return mav;</span></p> <p class="MsoNormal"><span lang="EN-US">         }</span></p> <p class="MsoNormal"><span lang="EN-US">         </span></p> <p class="MsoNormal"><span lang="EN-US">         @RequestMapping(value = "/saveProjectType",method=RequestMethod.POST)</span></p> <p class="MsoNormal"><span lang="EN-US">         protected String addProjectType(@ModelAttribute("newProjectType")ProjectType projectType,BindingResult result,SessionStatus status){</span></p> <p class="MsoNormal"><span lang="EN-US">                   //return userService.addProjectType(projectType, result, status);</span></p> <p class="MsoNormal"><span lang="EN-US">                   return userService.addProjectType(projectType);</span></p> <p class="MsoNormal"><span lang="EN-US">         }</span></p> <p class="MsoNormal"><span lang="EN-US">}</span></p> <p class="MsoNormal"><span lang="EN-US"> </span></p> <h2> <span lang="EN-US">3.3<span lang="EN-US">    </span></span><span lang="EN-US">DAO</span><span lang="EN-US">@Component("userDao")</span> </h2> <p class="MsoNormal"><span lang="EN-US">public class UserDaoImpl implements UserDao{</span></p> <p class="MsoNormal"><span lang="EN-US">         @Autowired</span></p> <p class="MsoNormal"><span lang="EN-US">         private SessionFactory sessionFactory;</span></p> <p class="MsoNormal"><span lang="EN-US">    </span></p> <p class="MsoNormal"><span lang="EN-US">    public ProjectType getById(int id)</span></p> <p class="MsoNormal"><span lang="EN-US">    {</span></p> <p class="MsoNormal"><span lang="EN-US">        return (ProjectType) sessionFactory.getCurrentSession().get(ProjectType.class, id);</span></p> <p class="MsoNormal"><span lang="EN-US">    }</span></p> <p class="MsoNormal"><span lang="EN-US">    </span></p> <p class="MsoNormal"><span lang="EN-US">         @Override</span></p> <p class="MsoNormal"><span lang="EN-US">         public String userLogin(UserModel user) {</span></p> <p class="MsoNormal"><span lang="EN-US">                   return "123456";</span></p> <p class="MsoNormal"><span lang="EN-US">         }</span></p> <p class="MsoNormal"><span lang="EN-US"> </span></p> <p class="MsoNormal"><span lang="EN-US">         //</span><span lang="EN-US">获取数据</span></p> <p class="MsoNormal"><span lang="EN-US">         @Override</span></p> <p class="MsoNormal"><span lang="EN-US">         @SuppressWarnings("unchecked")</span></p> <p class="MsoNormal"><span lang="EN-US">         public List&lt;ProjectType&gt; getAllProjectTypes() {</span></p> <p class="MsoNormal"><span lang="EN-US">                   Criteria ceriteria = sessionFactory.getCurrentSession().createCriteria(ProjectType.class);</span></p> <p class="MsoNormal"><span lang="EN-US">                   return ceriteria.list();</span></p> <p class="MsoNormal"><span lang="EN-US">         }</span></p> <p class="MsoNormal"><span lang="EN-US"> </span></p> <p class="MsoNormal"><span lang="EN-US">         //</span><span lang="EN-US">新增数据;</span></p> <p class="MsoNormal"><span lang="EN-US">         @Override</span></p> <p class="MsoNormal"><span lang="EN-US">//      @Transactional(readOnly = true, propagation = Propagation.REQUIRED)</span></p> <p class="MsoNormal"><span lang="EN-US">         public int save(ProjectType projectType) {</span></p> <p class="MsoNormal"><span lang="EN-US">                   System.out.println("save:---");</span></p> <p class="MsoNormal"><span lang="EN-US">                   System.out.println(projectType.getIndex());</span></p> <p class="MsoNormal"><span lang="EN-US">                   System.out.println(projectType.getProjectType());</span></p> <p class="MsoNormal"><span lang="EN-US">                   System.out.println(projectType.getProjectTypeAbbr());</span></p> <p class="MsoNormal"><span lang="EN-US">                   </span></p> <p class="MsoNormal"><span lang="EN-US">                   return (Integer) sessionFactory.getCurrentSession().save(projectType);</span></p> <p class="MsoNormal"><span lang="EN-US">         }</span></p> <p> </p> <p class="MsoNormal"><span lang="EN-US">}</span></p> </div>
130 个相见恨晚的超实用网站,一次性分享出来
相见恨晚的超实用网站 持续更新中。。。
Java学习的正确打开方式
在博主认为,对于入门级学习java的最佳学习方法莫过于视频+博客+书籍+总结,前三者博主将淋漓尽致地挥毫于这篇博客文章中,至于总结在于个人,实际上越到后面你会发现学习的最好方式就是阅读参考官方文档其次就是国内的书籍,博客次之,这又是一个层次了,这里暂时不提后面再谈。博主将为各位入门java保驾护航,各位只管冲鸭!!!上天是公平的,只要不辜负时间,时间自然不会辜负你。 何谓学习?博主所理解的学习,它是一个过程,是一个不断累积、不断沉淀、不断总结、善于传达自己的个人见解以及乐于分享的过程。
程序员必须掌握的核心算法有哪些?
由于我之前一直强调数据结构以及算法学习的重要性,所以就有一些读者经常问我,数据结构与算法应该要学习到哪个程度呢?,说实话,这个问题我不知道要怎么回答你,主要取决于你想学习到哪些程度,不过针对这个问题,我稍微总结一下我学过的算法知识点,以及我觉得值得学习的算法。这些算法与数据结构的学习大多数是零散的,并没有一本把他们全部覆盖的书籍。下面是我觉得值得学习的一些算法以及数据结构,当然,我也会整理一些看过...
大学四年自学走来,这些私藏的实用工具/学习网站我贡献出来了
大学四年,看课本是不可能一直看课本的了,对于学习,特别是自学,善于搜索网上的一些资源来辅助,还是非常有必要的,下面我就把这几年私藏的各种资源,网站贡献出来给你们。主要有:电子书搜索、实用工具、在线视频学习网站、非视频学习网站、软件下载、面试/求职必备网站。 注意:文中提到的所有资源,文末我都给你整理好了,你们只管拿去,如果觉得不错,转发、分享就是最大的支持了。 一、电子书搜索 对于大部分程序员...
计算机专业的书普遍都这么贵,你们都是怎么获取资源的?
介绍几个可以下载编程电子书籍的网站。 1.Github Github上编程书资源很多,你可以根据类型和语言去搜索。推荐几个热门的: free-programming-books-zh_CN:58K 星的GitHub,编程语言、WEB、函数、大数据、操作系统、在线课程、数据库相关书籍应有尽有,共有几百本。 Go语言高级编程:涵盖CGO,Go汇编语言,RPC实现,Protobuf插件实现,Web框架实...
小白学 Python 爬虫(25):爬取股票信息
人生苦短,我用 Python 前文传送门: 小白学 Python 爬虫(1):开篇 小白学 Python 爬虫(2):前置准备(一)基本类库的安装 小白学 Python 爬虫(3):前置准备(二)Linux基础入门 小白学 Python 爬虫(4):前置准备(三)Docker基础入门 小白学 Python 爬虫(5):前置准备(四)数据库基础 小白学 Python 爬虫(6):前置准备(...
卸载 x 雷某度!GitHub 标星 1.5w+,从此我只用这款全能高速下载工具!
作者 | Rocky0429 来源 | Python空间 大家好,我是 Rocky0429,一个喜欢在网上收集各种资源的蒟蒻… 网上资源眼花缭乱,下载的方式也同样千奇百怪,比如 BT 下载,磁力链接,网盘资源等等等等,下个资源可真不容易,不一样的方式要用不同的下载软件,因此某比较有名的 x 雷和某度网盘成了我经常使用的工具。 作为一个没有钱的穷鬼,某度网盘几十 kb 的下载速度让我...
《面试宝典》2019年springmvc面试高频题(java)
前言 2019即将过去,伴随我们即将迎来的又是新的一年,过完春节,马上又要迎来新的金三银四面试季。那么,作为程序猿的你,是否真的有所准备的呢,亦或是安于本职工作,继续做好手头上的事情。 当然,不论选择如何,假如你真的准备在之后的金三银四跳槽的话,那么作为一个Java工程师,就不可不看了。如何在几个月的时间里,快速的为即将到来的面试进行充分的准备呢? 1、什么是Spring MVC ?简单...
一名大专同学的四个问题
【前言】   收到一封来信,赶上各种事情拖了几日,利用今天要放下工作的时机,做个回复。   2020年到了,就以这一封信,作为开年标志吧。 【正文】   您好,我是一名现在有很多困惑的大二学生。有一些问题想要向您请教。   先说一下我的基本情况,高考失利,不想复读,来到广州一所大专读计算机应用技术专业。学校是偏艺术类的,计算机专业没有实验室更不用说工作室了。而且学校的学风也不好。但我很想在计算机领...
复习一周,京东+百度一面,不小心都拿了Offer
京东和百度一面都问了啥,面试官百般刁难,可惜我全会。
轻松搭建基于 SpringBoot + Vue 的 Web 商城应用
首先介绍下在本文出现的几个比较重要的概念: 函数计算(Function Compute): 函数计算是一个事件驱动的服务,通过函数计算,用户无需管理服务器等运行情况,只需编写代码并上传。函数计算准备计算资源,并以弹性伸缩的方式运行用户代码,而用户只需根据实际代码运行所消耗的资源进行付费。Fun: Fun 是一个用于支持 Serverless 应用部署的工具,能帮助您便捷地管理函数计算、API ...
Python+OpenCV实时图像处理
目录 1、导入库文件 2、设计GUI 3、调用摄像头 4、实时图像处理 4.1、阈值二值化 4.2、边缘检测 4.3、轮廓检测 4.4、高斯滤波 4.5、色彩转换 4.6、调节对比度 5、退出系统 初学OpenCV图像处理的小伙伴肯定对什么高斯函数、滤波处理、阈值二值化等特性非常头疼,这里给各位分享一个小项目,可通过摄像头实时动态查看各类图像处理的特点,也可对各位调参、测试...
2020年一线城市程序员工资大调查
人才需求 一线城市共发布岗位38115个,招聘120827人。 其中 beijing 22805 guangzhou 25081 shanghai 39614 shenzhen 33327 工资分布 2020年中国一线城市程序员的平均工资为16285元,工资中位数为14583元,其中95%的人的工资位于5000到20000元之间。 和往年数据比较: yea...
为什么猝死的都是程序员,基本上不见产品经理猝死呢?
相信大家时不时听到程序员猝死的消息,但是基本上听不到产品经理猝死的消息,这是为什么呢? 我们先百度搜一下:程序员猝死,出现将近700多万条搜索结果: 搜索一下:产品经理猝死,只有400万条的搜索结果,从搜索结果数量上来看,程序员猝死的搜索结果就比产品经理猝死的搜索结果高了一倍,而且从下图可以看到,首页里面的五条搜索结果,其实只有两条才是符合条件。 所以程序员猝死的概率真的比产品经理大,并不是错...
害怕面试被问HashMap?这一篇就搞定了!
声明:本文以jdk1.8为主! 搞定HashMap 作为一个Java从业者,面试的时候肯定会被问到过HashMap,因为对于HashMap来说,可以说是Java集合中的精髓了,如果你觉得自己对它掌握的还不够好,我想今天这篇文章会非常适合你,至少,看了今天这篇文章,以后不怕面试被问HashMap了 其实在我学习HashMap的过程中,我个人觉得HashMap还是挺复杂的,如果真的想把它搞得明明白...
毕业5年,我问遍了身边的大佬,总结了他们的学习方法
我问了身边10个大佬,总结了他们的学习方法,原来成功都是有迹可循的。
推荐10个堪称神器的学习网站
每天都会收到很多读者的私信,问我:“二哥,有什么推荐的学习网站吗?最近很浮躁,手头的一些网站都看烦了,想看看二哥这里有什么新鲜货。” 今天一早做了个恶梦,梦到被老板辞退了。虽然说在我们公司,只有我辞退老板的份,没有老板辞退我这一说,但是还是被吓得 4 点多都起来了。(主要是因为我掌握着公司所有的核心源码,哈哈哈) 既然 4 点多起来,就得好好利用起来。于是我就挑选了 10 个堪称神器的学习网站,推...
这些软件太强了,Windows必装!尤其程序员!
Windows可谓是大多数人的生产力工具,集娱乐办公于一体,虽然在程序员这个群体中都说苹果是信仰,但是大部分不都是从Windows过来的,而且现在依然有很多的程序员用Windows。 所以,今天我就把我私藏的Windows必装的软件分享给大家,如果有一个你没有用过甚至没有听过,那你就赚了????,这可都是提升你幸福感的高效率生产力工具哦! 走起!???? NO、1 ScreenToGif 屏幕,摄像头和白板...
(总结)阿里面试问了ArrayList,都问了啥?
我是真的没想到,面试官会这样问我ArrayList。
曾经优秀的人,怎么就突然不优秀了。
职场上有很多辛酸事,很多合伙人出局的故事,很多技术骨干被裁员的故事。说来模板都类似,曾经是名校毕业,曾经是优秀员工,曾经被领导表扬,曾经业绩突出,然而突然有一天,因为种种原因,被裁员了,...
大学四年因为知道了这32个网站,我成了别人眼中的大神!
依稀记得,毕业那天,我们导员发给我毕业证的时候对我说“你可是咱们系的风云人物啊”,哎呀,别提当时多开心啦????,嗯,我们导员是所有导员中最帅的一个,真的???? 不过,导员说的是实话,很多人都叫我大神的,为啥,因为我知道这32个网站啊,你说强不强????,这次是绝对的干货,看好啦,走起来! PS:每个网站都是学计算机混互联网必须知道的,真的牛杯,我就不过多介绍了,大家自行探索,觉得没用的,尽管留言吐槽吧???? 社...
Python爬取周杰伦的200首歌+BI可视化分析,青春好像又回来了
友情提醒:文末有福利 近年来程序界最火的事情是什么?,那肯定是Python的兴起。据调研,Python已经成为排名前三的语言,具体排在第几相信各位心中肯定有自己的评判标准,这里不挑口水战了。 那Python到底为什么这么火?首先上手很快,对于新手来说是最简单的入门语言;第二,能爬取信息,并且能做可视化分析。 Python做的可视化分析 最近一直在听周杰伦的歌(可能是小编长大了...
2020年1月中国编程语言排行榜,python是2019增长最快编程语言
编程语言比例 排名 编程语言 最低工资 工资中位数 最低工资 最高工资 人头 人头百分比 1 rust 20713 17500 5042 46250 480 0.14% 2 typescript 18503 22500 6000 30000 1821 0.52% 3 lua 18150 17500 5250 35000 2956 0.84% 4 go 17989 16...
看完这篇HTTP,跟面试官扯皮就没问题了
我是一名程序员,我的主要编程语言是 Java,我更是一名 Web 开发人员,所以我必须要了解 HTTP,所以本篇文章就来带你从 HTTP 入门到进阶,看完让你有一种恍然大悟、醍醐灌顶的感觉。 最初在有网络之前,我们的电脑都是单机的,单机系统是孤立的,我还记得 05 年前那会儿家里有个电脑,想打电脑游戏还得两个人在一个电脑上玩儿,及其不方便。我就想为什么家里人不让上网,我的同学 xxx 家里有网,每...
史上最全的IDEA快捷键总结
现在Idea成了主流开发工具,这篇博客对其使用的快捷键做了总结,希望对大家的开发工作有所帮助。
阿里程序员写了一个新手都写不出的低级bug,被骂惨了。
这种新手都不会范的错,居然被一个工作好几年的小伙子写出来,差点被当场开除了。
谁是华为扫地僧?
是的,华为也有扫地僧!2020年2月11-12日,“养在深闺人不知”的华为2012实验室扫地僧们,将在华为开发者大会2020(Cloud)上,和大家见面。到时,你可以和扫地僧们,吃一个洋...
AI 没让人类失业,搞 AI 的人先失业了
最近和几个 AI 领域的大佬闲聊 根据他们讲的消息和段子 改编出下面这个故事 如有雷同 都是巧合 1. 老王创业失败,被限制高消费 “这里写我跑路的消息实在太夸张了。” 王葱葱哼笑一下,把消息分享给群里。 阿杰也看了消息,笑了笑。在座几位也都笑了。 王葱葱是个有名的人物,21岁那年以全额奖学金进入 KMU 攻读人工智能博士,累计发表论文 40 余篇,个人技术博客更是成为深度学习领域内风向标。 ...
2020年,冯唐49岁:我给20、30岁IT职场年轻人的建议
点击“技术领导力”关注∆每天早上8:30推送 作者|Mr.K 编辑| Emma 来源|技术领导力(ID:jishulingdaoli) 前天的推文《冯唐:职场人35岁以后,方法论比经验重要》,收到了不少读者的反馈,觉得挺受启发。其实,冯唐写了不少关于职场方面的文章,都挺不错的。可惜大家只记住了“春风十里不如你”、“如何避免成为油腻腻的中年人”等不那么正经的文章。 本文整理了冯...
工作十年的数据分析师被炒,没有方向,你根本躲不过中年危机
2020年刚刚开始,就意味着离职潮高峰的到来,我身边就有不少人拿着年终奖离职了,而最让我感到意外的,是一位工作十年的数据分析师也离职了,不同于别人的主动辞职,他是被公司炒掉的。 很多人都说数据分析是个好饭碗,工作不累薪资高、入门简单又好学。然而今年34的他,却真正尝到了中年危机的滋味,平时也有不少人都会私信问我: 数据分析师也有中年危机吗?跟程序员一样是吃青春饭的吗?该怎么保证自己不被公司淘汰...
作为一名大学生,如何在B站上快乐的学习?
B站是个宝,谁用谁知道???? 作为一名大学生,你必须掌握的一项能力就是自学能力,很多看起来很牛X的人,你可以了解下,人家私底下一定是花大量的时间自学的,你可能会说,我也想学习啊,可是嘞,该学习啥嘞,不怕告诉你,互联网时代,最不缺的就是学习资源,最宝贵的是啥? 你可能会说是时间,不,不是时间,而是你的注意力,懂了吧! 那么,你说学习资源多,我咋不知道,那今天我就告诉你一个你必须知道的学习的地方,人称...
那些年,我们信了课本里的那些鬼话
教材永远都是有错误的,从小学到大学,我们不断的学习了很多错误知识。 斑羚飞渡 在我们学习的很多小学课文里,有很多是错误文章,或者说是假课文。像《斑羚飞渡》: 随着镰刀头羊的那声吼叫,整个斑羚群迅速分成两拨,老年斑羚为一拨,年轻斑羚为一拨。 就在这时,我看见,从那拨老斑羚里走出一只公斑羚来。公斑羚朝那拨年轻斑羚示意性地咩了一声,一只半大的斑羚应声走了出来。一老一少走到伤心崖,后退了几步,突...
一个程序在计算机中是如何运行的?超级干货!!!
强烈声明:本文很干,请自备茶水!???? 开门见山,咱不说废话! 你有没有想过,你写的程序,是如何在计算机中运行的吗?比如我们搞Java的,肯定写过这段代码 public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } ...
【蘑菇街技术部年会】程序员与女神共舞,鼻血再次没止住。(文末内推)
蘑菇街技术部的年会,别开生面,一样全是美女。
那个在阿里养猪的工程师,5年了……
简介: 在阿里,走过1825天,没有趴下,依旧斗志满满,被称为“五年陈”。他们会被授予一枚戒指,过程就叫做“授戒仪式”。今天,咱们听听阿里的那些“五年陈”们的故事。 下一个五年,猪圈见! 我就是那个在养猪场里敲代码的工程师,一年多前我和20位工程师去了四川的猪场,出发前总架构师慷慨激昂的说:同学们,中国的养猪产业将因为我们而改变。但到了猪场,发现根本不是那么回事:要个WIFI,没有;...
为什么程序猿都不愿意去外包?
分享外包的组织架构,盈利模式,亲身经历,以及根据一些外包朋友的反馈,写了这篇文章 ,希望对正在找工作的老铁有所帮助
Java校招入职华为,半年后我跑路了
何来 我,一个双非本科弟弟,有幸在 19 届的秋招中得到前东家华为(以下简称 hw)的赏识,当时秋招签订就业协议,说是入了某 java bg,之后一系列组织架构调整原因等等让人无法理解的神操作,最终毕业前夕,被通知调往其他 bg 做嵌入式开发(纯 C 语言)。 由于已至于校招末尾,之前拿到的其他 offer 又无法再收回,一时感到无力回天,只得默默接受。 毕业后,直接入职开始了嵌入式苦旅,由于从未...
让开发效率“飞起”的VS Code 插件
前言VSCode,是一个免费的、开源的跨平台编辑器,也是我最满意的编辑器之一。本文向大家推荐一些我喜欢的vscode插件,不出意外的话,这些插件将对你的工作效率提升有不小的帮助!GitL...
世界上有哪些代码量很少,但很牛逼很经典的算法或项目案例?
点击上方蓝字设为星标下面开始今天的学习~今天分享四个代码量很少,但很牛逼很经典的算法或项目案例。1、no code 项目地址:https://github.com/kelseyhight...
Python全栈 Linux基础之3.Linux常用命令
Linux对文件(包括目录)有很多常用命令,可以加快开发效率:ls是列出当前目录下的文件列表,选项有-a、-l、-h,还可以使用通配符;c功能是跳转目录,可以使用相对路径和绝对路径;mkdir命令创建一个新的目录,有-p选项,rm删除文件或目录,有-f、-r选项;cp用于复制文件,有-i、-r选项,tree命令可以将目录结构显示出来(树状显示),有-d选项,mv用来移动文件/目录,有-i选项;cat查看文件内容,more分屏显示文件内容,grep搜索内容;>、>>将执行结果重定向到一个文件;|用于管道输出。
​两年前不知如何编写代码的我,现在是一名人工智能工程师
全文共3526字,预计学习时长11分钟 图源:Unsplash 经常有小伙伴私信给小芯,我没有编程基础,不会写代码,如何进入AI行业呢?还能赶上AI浪潮吗? 任何时候努力都不算晚。 下面,小芯就给大家讲一个朋友的真实故事,希望能给那些处于迷茫与徘徊中的小伙伴们一丝启发。(下文以第一人称叙述) 图源:Unsplash 正如Elsa所说,职业转换是...
作为一个程序员,内存的这些硬核知识你必须懂!
我们之前讲过CPU,也说了CPU和内存的那点事儿,今天咱就再来说说有关内存,作为一个程序员,你必须要懂的哪那些硬核知识! 大白话聊一聊,很重要! 先来大白话的跟大家聊一聊,我们这里说的内存啊,其实就是说的我们电脑里面的内存条,所以嘞,内存就是内存条,数据要放在这上面才能被cpu读取从而做运算,还有硬盘,就是电脑中的C盘啥的,一个程序需要运行的话需要向内存申请一块独立的内存空间,这个程序本身是存放在...
非典逼出了淘宝和京东,新冠病毒能够逼出什么?
loonggg读完需要5分钟速读仅需 2 分钟大家好,我是你们的校长。我知道大家在家里都憋坏了,大家可能相对于封闭在家里“坐月子”,更希望能够早日上班。今天我带着大家换个思路来聊一个问题...
Spring框架|JdbcTemplate介绍
文章目录一、JdbcTemplate 概述二、创建对象的源码分析三、JdbcTemplate操作数据库 一、JdbcTemplate 概述 在之前的web学习中,学习了手动封装JDBCtemplate,其好处是通过(sql语句+参数)模板化了编程。而真正的JDBCtemplete类,是Spring框架为我们写好的。 它是 Spring 框架中提供的一个对象,是对原始 Jdbc API 对象的简单...
立即提问