hibernate用annotation怎么设置字段唯一且不能为空?

用户表除了ID为主键还需要用户名字段唯一且不能为空。请问该怎么做。貌似联合主键是允许其中单个字段重复的。用annotation怎么设置呢?请详细说明。

1个回答

unique="true"//这个是在hibernate的配置文件中字段上用的,下面的链接是用注解的情况,你可以点击进去看看
http://www.360doc.com/content/14/0725/15/281812_396983370.shtml

qq86257167
颖辉小居 那请问不为空呢?
4 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
hibernate 动态对表添加字段??怎么做?

使用技术:struts2 hibernate(annotation) spring 用户需求是:在不修改源代码、不重启服务器的情况下,需要对某张表动态添加自定义字段,可以存取数据(持久化) 在网上看到有使用xml成功的 但是我们现在的环境是 使用的annotation 如果使用xml 需要做大幅度改动 有没有其他合适的好方法?或者已经实现这个功能的前辈?麻烦指导下? 我现在是使用的数据库和javabean做一个预留字段,使用的是text,使用一个String存其增加的字段,用特殊符号分割! 貌似提错地方了!!

Hibernate怎样使用Annotation映射视图

<p>最近的项目中有几种用户,用户的字段差别极大,只有id、username、password、userType、name等几个相同的字段,现想做单点登录,采用视图方式,现在针对上面几个字段创建了一个普通视图,命名为View_User,没有主键。</p> <p>然后用MyEclipse的反射工程生成Annotation配置的实体类,共生成两个实体类,如下:</p> <p> </p> <pre name="code" class="java">ViewUser类</pre> <p> </p> <p> </p> <p> </p> <pre name="code" class="java">package com.ninemax.cul.user.entity; import javax.persistence.AttributeOverride; import javax.persistence.AttributeOverrides; import javax.persistence.Column; import javax.persistence.EmbeddedId; import javax.persistence.Entity; import javax.persistence.Table; /** * ViewUser entity. @author MyEclipse Persistence Tools */ @Entity @Table(name = "VIEW_USER") public class ViewUser implements java.io.Serializable { // Fields private ViewUserId id; // Constructors /** default constructor */ public ViewUser() { } /** full constructor */ public ViewUser(ViewUserId id) { this.id = id; } // Property accessors @EmbeddedId @AttributeOverrides({ @AttributeOverride(name = "id", column = @Column(name = "ID", length = 50)), @AttributeOverride(name = "username", column = @Column(name = "USERNAME", length = 32)), @AttributeOverride(name = "password", column = @Column(name = "PASSWORD", length = 32)), @AttributeOverride(name = "userType", column = @Column(name = "USER_TYPE")), @AttributeOverride(name = "name", column = @Column(name = "NAME", length = 65536)), @AttributeOverride(name = "isWorkFlag", column = @Column(name = "IS_WORK_FLAG")) }) public ViewUserId getId() { return this.id; } public void setId(ViewUserId id) { this.id = id; } }</pre> <p> 另外一个类是ViewUserId类:</p> <p> </p> <pre name="code" class="java">package com.ninemax.cul.user.entity; import javax.persistence.Column; import javax.persistence.Embeddable; /** * ViewUserId entity. @author MyEclipse Persistence Tools */ @Embeddable public class ViewUserId implements java.io.Serializable { // Fields private String id; private String username; private String password; private Integer userType; private String name; private Boolean isWorkFlag; // Constructors /** default constructor */ public ViewUserId() { } /** full constructor */ public ViewUserId(String id, String username, String password, Integer userType, String name, Boolean isWorkFlag) { this.id = id; this.username = username; this.password = password; this.userType = userType; this.name = name; this.isWorkFlag = isWorkFlag; } // Property accessors @Column(name = "ID", length = 50) public String getId() { return this.id; } public void setId(String id) { this.id = id; } @Column(name = "USERNAME", length = 32) public String getUsername() { return this.username; } public void setUsername(String username) { this.username = username; } @Column(name = "PASSWORD", length = 32) public String getPassword() { return this.password; } public void setPassword(String password) { this.password = password; } @Column(name = "USER_TYPE") public Integer getUserType() { return this.userType; } public void setUserType(Integer userType) { this.userType = userType; } @Column(name = "NAME", length = 65536) public String getName() { return this.name; } public void setName(String name) { this.name = name; } @Column(name = "IS_WORK_FLAG") public Boolean getIsWorkFlag() { return this.isWorkFlag; } public void setIsWorkFlag(Boolean isWorkFlag) { this.isWorkFlag = isWorkFlag; } public boolean equals(Object other) { // 省略 } public int hashCode() { // 省略 } }</pre> <p> 其实这样程序是可以运行的,问题在于视图中的name是可以为空的,在name为空时Hibernate加载不上来数据(为null),请问怎样才能让Hibernate将含有null字段值的记录也加载上来?</p> <p>网上有人介绍XML配置的解决方式,但我经验不足,没有参照着将Annotation下的解决办法找到,请各位指点一下,谢谢!</p>

为什么有hibernate注解添加具有一对多关系的数据时,外键设置不了

如题,还请各位告知,不胜感激.................... 谢谢了

struts2+hibernate采用annotation进行ManyToOne关联的问题

struts2+hibernate,有实体类User(用户)、Gender(性别),做字典字段的ManyToOne关联,如下: 用户类 [code="java"] import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; import org.hibernate.annotations.Cache; import org.hibernate.annotations.CacheConcurrencyStrategy; @Entity @Table(name = "TB_User") public class User{ Long id; //用户主键 String userName; //姓名 Gender gender; //性别 @Id @GeneratedValue(strategy = GenerationType.IDENTITY) public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName; } // 多对一定义 @ManyToOne(optional = true, fetch = FetchType.EAGER) @JoinColumn(name = "gender", referencedColumnName = "itemId") @Cache(usage = CacheConcurrencyStrategy.READ_WRITE) public Gender getGender() { return gender; } public void setGender(Gender gender) { this.gender = gender; } } [/code] 性别类 [code] import java.io.Serializable; import javax.persistence.Entity; import javax.persistence.Table; @Entity @Table(name = "TB_DICT") public class Gender implements Serializable { Long id; //字典主键 Long dictId; //字典类型编号:1表示性别 Long dictName; //字典类型名称 Long itemId; //项目编号 1:男 2:女 String itemName;//项目名称 @Id @GeneratedValue(strategy = GenerationType.IDENTITY) public Long getId() { return id; } public void setId(Long id) { this.id = id; } public Long getDictId() { return dictId; } public void setDictId(Long dictId) { this.dictId = dictId; } public String getDictName() { return dictName; } public void setDictName(String dictName) { this.dictName = dictName; } public Long getItemId() { return itemId; } public void setItemId(Long itemId) { this.itemId = itemId; } public String getItemName() { return itemName; } public void setItemName(String itemName) { this.itemName = itemName; } } [/code] 页面: [code="html"] <script type="text/javascript"> $().ready(function(){ $("#gender").val('${gender.itemId}')//设置下拉框默认值 } </script> 编号: <input type="text" id="id" name="id" value="${id}"></input><br> 用户名: <input type="text" id="id" name="userName" value="${userName}"><br> 性别: <select id="gender" name="gender.id"> <option value="1">男</option> <option value="2">女</option> </select> [/code] 在页面上用alert('${gender.itemName}')可正确显示当前记录的“性别”中文名称,可见关联关系是建立起来了。但在将某记录的性别从“男”修改为“女”,并保存(执行getSession().saveOrUpdate(user))时,发生如下错误: org.springframework.orm.hibernate3.HibernateSystemException: [color=red]identifier of an instance of accountant.entity.Gender was altered from 3 to 2[/color]; 从错误提示看,hibernate尝试更新gender的ID字段,而主键是不允许更新的,因此出错 这里有两个问题: (1)建立关联只为了查询字典字段的中文名称,更新时只想更新TB_User的gender字段,而不是更新TB_DICT的值,这要如何设置?(是设置cascade参数吗?但CascadeType中似乎没有“NONE”一项) (2)这里提示的“altered from 3 to 2”,3是“男”的id值,2是“女”的item_id值。既然已经设置了referencedColumnName = "itemId",即使要更新TB_DICT的值也应该更新的是item_Id字段,为什么实际会去更新id字段? id dict_id dict_name item_id item_name 3 1 性别 1 男 4 1 性别 2 女 不得其解,请大家帮忙

hibernate保存数据报错

org.springframework.dao.DataIntegrityViolationException: Could not execute JDBC batch update; SQL [insert into ORC_T_BUSINESS_TRACK (BUSI_NUM, BUSI_TYPE, CREATE_DATE, CREATE_USER_NAME, CREATE_USER_NUM, REMARK, ID) values (?, ?, ?, ?, ?, ?, ?)]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:643) at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:104) at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:516) at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754) at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723) at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:394) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:120) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:622) at com.bsteel.shdc.service.OrcTBusinessTrackServiceImpl$$EnhancerByCGLIB$$416c9ca9.saveOrcTBusinessTrack(<generated>) at com.bsteel.shdc.bankservice.finance.redeem.controller.AuditController.signaTure1(AuditController.java:642) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882) at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789) at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) at javax.servlet.http.HttpServlet.service(HttpServlet.java:820) at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1221) at com.bsteel.shdc.manager.permission.filter.AuthFilter.doFilter(AuthFilter.java:101) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1212) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1212) at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:399) at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216) at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182) at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:766) at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:450) at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) at org.mortbay.jetty.Server.handle(Server.java:326) at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542) at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:945) at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:756) at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218) at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404) at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410) at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582) Caused by: org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:96) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:262) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:178) at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321) at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51) at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1206) at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:375) at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137) at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:76) at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:512) ... 47 more Caused by: java.sql.BatchUpdateException: ORA-01401: inserted value too large for column at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:345) at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10844) at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeBatch(NewProxyPreparedStatement.java:1723) at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70) at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268) ... 56 more [color=red][/color]

hibernate4 注解方式映射Date类型时间格式问题

private java.util.Date createTime = null 然后加了注解 @Temporal(TemporalType.TIMESTAMP) sql是自动生成, 数据库中的字段为TIMESTAMP类型 时间格式变成了12-MAY-18 10.05.25.861000 PM 实在是太丑了。这个时间格式怎么调整? 只要指成TemporalType.TIMESTAMP,数据库字段类型性就是TIMESTAMP 指定成TemporalType.TIME的话数据库是Date类型但是插入的是1970/1/1 22:04:30,日期不对。 指定成TemporalType.Date的话又没有时间。 请问数据时间格式怎么指定为2018/5/12 22:05:25类似这样格式呢?

急,hibernate annotation JPA注解下的单向OneToOne问题

2张表A,B A表中有一外键指向B表的主键,用@OneToOne(targetEntity = B.class,fetch = FetchType.LAZY) 注解后,利用hibernate自动生成的表中,B表中也对应出现了A表的外键字段,我现在希望A表中有B的外键但B中不能有A的外键,请问该怎么设置? A:id, name,B_id B:id,name

Hibernate annotation配置下级联保存问题

现在有两个类, B为多对一A类 B类中的字段关联配置为 @ManyToOne(fetch=FetchType.LAZY) @JoinColumn(name="f_a_id")//这个就是A的主键id public A getA(){ return a; } 现在在保存B的时候级联保存了关联的A 我不想存在这样的级联保存关系 请问如何解决?

关于@org.hibernate.annotations.Entity(dynamicUpdate=true,dynamicInsert=true)

[code="java"]@Entity @org.hibernate.annotations.Entity(dynamicUpdate=true,dynamicInsert=true) public class TestA { private int id; private String title; private String content; private Date date; ........... }[/code] [size=large]@org.hibernate.annotations.Entity(dynamicUpdate=true,dynamicInsert=true) 我加了这条Annotation但是做实验更新的时候为什么还是把所有字段给更新了啊?[/size]

hibernate+spring+testng测试,事务遇异常不回滚

直接上代码: @Transactional(transactionManager="transactionManager") @Rollback(false) @ContextConfiguration(locations = {"classpath:datasource-hibernate.xml"}) public class TestHibernate extends AbstractTransactionalTestNGSpringContextTests{ 上面类注解 spring事务配置: ``` <tx:annotation-driven transaction-manager="transactionManager"/> <bean id="userHDao" class="com.tx.test.dao.UserHDao"> <property name="sessionFactory" ref="sessionFactory"/> </bean> ``` 现在情况是只有添加@Rollback(false)才不会回滚,否则全部回滚,我想实现的是遇到异常就回滚,否则就不回滚,求指教

hibernate 多对多 级联删除 注解

有两个类:Survey和Questions,问卷类和题目类,它们是多对多的关系,即:一张试卷可以有多个题目,一个题目可以属于多个试卷,我用两个一对多,数据库用中间表来实现,并有第三个类SurveyQuestions. surveuy类如下: [code="java"]//问卷实体:包括各种属性 @Entity @Table(name="_survey") public class Survey { private int id;// 问卷ID private String name;// 问卷标题 private String des;// 问卷描述或者备注 private boolean state;// 状态:是否开放 private SurveyType surveyType;// 问卷类型 private int count;// 问卷数量限制 private Date createTime;// 问卷创建时间 private Date publishTime;// 问卷发布时间 private Date deadline;// 问卷截止提交日期 private String password;// 问卷访问密码 private boolean grade;//是否是打分问卷 @Id @GeneratedValue public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getDes() { return des; } public void setDes(String des) { this.des = des; } public boolean isState() { return state; } public void setState(boolean state) { this.state = state; } @ManyToOne @JoinColumn(name = "type_id") public SurveyType getSurveyType() { return surveyType; } public void setSurveyType(SurveyType surveyType) { this.surveyType = surveyType; } public int getCount() { return count; } public void setCount(int count) { this.count = count; } public Date getCreateTime() { return createTime; } public void setCreateTime(Date createTime) { this.createTime = createTime; } public Date getPublishTime() { return publishTime; } public void setPublishTime(Date publishTime) { this.publishTime = publishTime; } public Date getDeadline() { return deadline; } public void setDeadline(Date deadline) { this.deadline = deadline; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public boolean isGrade() { return grade; } public void setGrade(boolean grade) { this.grade = grade; }[/code] questions类 [code="java"]<span></span> @Entity @Table(name="_questions") public class Questions { private int id;// 问题主键ID private QuestionType questionType;// 问题类型 private String head;// 问题题目 private String body;// 问题主体 private String answer;// 预留字段,如果是网上答卷,则是答案 private String remarks;// 预留字段,备注 private int number;// 选项个数 @Id @GeneratedValue public int getId() { return id; } public void setId(int id) { this.id = id; } public String getHead() { return head; } public void setHead(String head) { this.head = head; } public String getBody() { return body; } public void setBody(String body) { this.body = body; } public String getAnswer() { return answer; } public void setAnswer(String answer) { this.answer = answer; } public String getRemarks() { return remarks; } public void setRemarks(String remarks) { this.remarks = remarks; } @ManyToOne(fetch=FetchType.LAZY) @JoinColumn(name = "type_id") public QuestionType getQuestionType() { return questionType; } public void setQuestionType(QuestionType questionType) { this.questionType = questionType; } @Column(nullable = true) public int getNumber() { return number; } public void setNumber(int number) { this.number = number; } }[/code] surveyQuestion类 [code="java"]package com.questionnaire.model; import java.util.Date; import java.util.HashSet; import java.util.Set; import javax.persistence.CascadeType; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.Table; @Entity @Table(name = "_surveyquestion") public class SurveyQuestion { private int id;// 问卷题库关联表ID,主键 private Survey survey;// 对应问卷ID,外键 private Questions questions;// 对应题目ID,外键 private int number;// 题号,即该题目在本问卷的题号 @Id @GeneratedValue public int getId() { return id; } public void setId(int id) { this.id = id; } this.userIp = userIp; public int getNumber() { return number; } public void setNumber(int number) { this.number = number; } @ManyToOne(cascade = CascadeType.ALL) @JoinColumn(name = "survey_id") public Survey getSurvey() { return survey; } public void setSurvey(Survey survey) { this.survey = survey; } @ManyToOne(cascade = CascadeType.ALL) @JoinColumn(name = "questions_id") public Questions getQuestions() { return questions; } public void setQuestions(Questions questions) { this.questions = questions; } }[/code] 我想实现删除题目时删除_questions表里的数据,同时删除_surveyQuestion表里的数据。当然survey同样?怎样实现呢?

关于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个字段都是同样的值 给我一种复制的感觉。。

请教hibernate 连续查询问题

我对一个基表查询 A a=find("hql").get(0); 然后a.setProp(555); 然后对换一个字段查询 B b=find("ohterhql").get(0); 在第一次查询时没问题 在b的find时会将a setProp的值持久化到数据库中 这是为什么 hibernate不熟,请教各位 <property name="hibernateProperties"> <props> <prop key="hibernate.dialect"> org.hibernate.dialect.Oracle9iDialect </prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.format_sql">true</prop> <prop key="hibernate.cache.provider_class"> org.hibernate.cache.EhCacheProvider </prop> <prop key="hibernate.cache.use_query_cache">true</prop> </props> </property> </bean> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <!-- 支持 @Transactional 标记 --> <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" /> <!-- =========== openSessionInViewInterceptor ==============--> <bean id="openSessionInViewInterceptor" class="org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor"> <property name="sessionFactory" ref="sessionFactory" /> </bean> hibernate3.2+spring2

sqlresultsetmaping的问题

@Entity @Table(name="car") @SqlResultSetMapping(name="carkey", entities=@EntityResult(entityClass=Car.class, fields = { @FieldResult(name="id", column = "id"), @FieldResult(name="name", column = "name"), @FieldResult(name="dimension.length", column = "length"), @FieldResult(name="dimension.width", column = "width") }), columns = { @ColumnResult(name = "area")}) @NamedNativeQuery(name="carkey",query="select id as id,name as name,length as length,width as width,length*width as area from Car", resultSetMapping="carkey") public class Car implements Serializable { private static final long serialVersionUID = 1L; @Id @Column(name="id") private int id; @Column(name="name") private String name; @ManyToOne(fetch= FetchType.LAZY) @JoinColumns( { @JoinColumn(name="id", referencedColumnName = "id") } ) private Dimension dimension; public Car(int id,String name){ this.id=id; this.name=name; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Dimension getDimension() { return dimension; } public void setDimension(Dimension dimension) { this.dimension = dimension; } } @Entity @Table(name="dimension") public class Dimension implements Serializable { private static final long serialVersionUID = 1L; @Id @Column(name="id") private int id; @Column(name="length") private int length; @Column(name="width") private int width; public Dimension(){ } public Dimension(int id,int length, int width){ this.id=id; this.length=length; this.width=width; } public int getId() { return id; } public void setId(int id) { this.id = id; } public int getLength() { return length; } public void setLength(int length) { this.length = length; } public int getWidth() { return width; } public void setWidth(int width) { this.width = width; } } 报错,如下: log4j:WARN No appenders could be found for logger (org.springframework.core.env.StandardEnvironment). log4j:WARN Please initialize the log4j system properly. Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [spring-demo-cfg.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: SimplePU] Unable to build Hibernate SessionFactory at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:529) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:198) at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:741) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83) at com.demo.test.DemoTest.main(DemoTest.java:19) Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [spring-demo-cfg.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: SimplePU] Unable to build Hibernate SessionFactory at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1512) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:198) at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:438) at org.springframework.beans.factory.BeanFactoryUtils.beansOfTypeIncludingAncestors(BeanFactoryUtils.java:277) at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.detectPersistenceExceptionTranslators(PersistenceExceptionTranslationInterceptor.java:139) at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.<init>(PersistenceExceptionTranslationInterceptor.java:79) at org.springframework.dao.annotation.PersistenceExceptionTranslationAdvisor.<init>(PersistenceExceptionTranslationAdvisor.java:71) at org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor.setBeanFactory(PersistenceExceptionTranslationPostProcessor.java:84) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeAwareMethods(AbstractAutowireCapableBeanFactory.java:1532) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1500) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521) ... 10 more Caused by: javax.persistence.PersistenceException: [PersistenceUnit: SimplePU] Unable to build Hibernate SessionFactory at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:1239) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.access$600(EntityManagerFactoryBuilderImpl.java:120) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:855) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:845) at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:398) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:844) at org.hibernate.jpa.HibernatePersistenceProvider.createContainerEntityManagerFactory(HibernatePersistenceProvider.java:152) at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:67) at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:290) at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:310) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1571) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1509) ... 25 more Caused by: org.hibernate.MappingException: dotted notation reference neither a component nor a many/one to one at org.hibernate.cfg.annotations.ResultsetMappingSecondPass.getSubPropertyIterator(ResultsetMappingSecondPass.java:268) at org.hibernate.cfg.annotations.ResultsetMappingSecondPass.doSecondPass(ResultsetMappingSecondPass.java:112) at org.hibernate.cfg.Configuration.originalSecondPassCompile(Configuration.java:1706) at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1426) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1846) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:852) ... 34 more Caused by: java.lang.ClassCastException: org.hibernate.mapping.SimpleValue cannot be cast to org.hibernate.mapping.Component at org.hibernate.cfg.annotations.ResultsetMappingSecondPass.getSubPropertyIterator(ResultsetMappingSecondPass.java:260) ... 39 more 这个是哪里有问题?

Spring + Hibernate 项目中,查询POJO的时候调用 set方法 会将对应字段修改到数据库里面

下面是配置,求解答 如 public Student querySutdent(id){ Student stu = XXDao.getStudent(id); stu.setSex("男"); return stu; } 会将 stu的 sex 更新数据库里面 [code="java"] <!-- Enable @Transactional support --> <tx:annotation-driven/> <!-- Enable @AspectJ support --> <aop:aspectj-autoproxy/> <!-- Activates scanning of @Autowired --> <context:annotation-config/> <!-- Activates scanning of @service --> <context:component-scan base-package="com.chinadrtv.erp.tc;com.chinadrtv.erp.shipment;com.chinadrtv.erp.ic"/> <tx:advice id="txAdvice"> <tx:attributes> <!-- Read-only commented out to make things easier for end-users --> <tx:method name="build*" read-only="true" propagation="REQUIRED" rollback-for="Throwable"/> <tx:method name="get*" read-only="true" propagation="REQUIRED" rollback-for="Throwable"/> <tx:method name="calculate*" read-only="true" propagation="REQUIRED" rollback-for="Throwable"/> <tx:method name="*" propagation="REQUIRED" rollback-for="Throwable"/> </tx:attributes> </tx:advice> <!-- =================================================================== --> <!-- AOP: Configuration and Aspects --> <!-- =================================================================== --> <aop:config> <aop:advisor id="managerTx" advice-ref="txAdvice" pointcut="execution(* *..service.*Service.*(..))" order="0"/> <aop:advisor id="auditLogTx" advice-ref="txAdvice" pointcut="execution(* *..aop.*Service.*(..))" order="1"/> </aop:config> [/code]

数据库使用CLOB字段类型时

九月 14, 2015 3:06:59 下午 org.apache.catalina.core.StandardWrapperValve invoke 严重: Servlet.service() for servlet [appServlet] in context with path [/UnderwritingApp] threw exception [Handler processing failed; nested exception is java.lang.AbstractMethodError] with root cause java.lang.AbstractMethodError at org.apache.commons.dbcp.DelegatingPreparedStatement.setCharacterStream(DelegatingPreparedStatement.java:328) at org.apache.commons.dbcp.DelegatingPreparedStatement.setCharacterStream(DelegatingPreparedStatement.java:328) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:122) at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81) at com.sun.proxy.$Proxy122.setCharacterStream(Unknown Source) at org.hibernate.type.descriptor.sql.ClobTypeDescriptor$3$1.doBind(ClobTypeDescriptor.java:83) at org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:92) at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:280) at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:275) at org.hibernate.type.AbstractSingleColumnStandardBasicType.nullSafeSet(AbstractSingleColumnStandardBasicType.java:57) at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2747) at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3152) at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:3087) at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3416) at org.hibernate.action.internal.EntityUpdateAction.execute(EntityUpdateAction.java:140) at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:362) at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:354) at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:276) at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:326) at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:52) at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1213) at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:402) at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(JdbcTransaction.java:101) at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:175) at org.springframework.orm.hibernate4.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:468) at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754) at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723) at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:392) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:120) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) at com.sun.proxy.$Proxy103.save(Unknown Source) at com.mobisoft.meapbase.service.underwriting.EmployeeServiceImpl.check(EmployeeServiceImpl.java:107) at com.mobisoft.meapbase.gateway.user.UserController.checkAccount(UserController.java:261) at com.mobisoft.meapbase.gateway.user.UserController.procReq(UserController.java:69) at com.mobisoft.meapbase.gateway.RequestProcBase.Main(RequestProcBase.java:164) at com.mobisoft.meapbase.gateway.RequestProcBase.Main(RequestProcBase.java:72) at com.mobisoft.meapbase.gateway.user.UserController.mobile(UserController.java:53) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:746) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:687) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:915) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:811) at javax.servlet.http.HttpServlet.service(HttpServlet.java:620) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:796) at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745)

查询时,js传参到后台(参数是int类型),后台接收不到,报转换异常,急急急!!!!在线等 !!

严重: Servlet.service() for servlet [springMVC] in context with path [/LINK] threw exception [Request processing failed; nested exception is java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer] with root cause java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer at org.hibernate.type.IntegerType.set(IntegerType.java:64) at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:154) at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:136) at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1769) at org.hibernate.loader.Loader.bindParameterValues(Loader.java:1740) at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1612) at org.hibernate.loader.Loader.doQuery(Loader.java:717) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:270) at org.hibernate.loader.Loader.doList(Loader.java:2294) at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2172) at org.hibernate.loader.Loader.list(Loader.java:2167) at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:119) at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1706) at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:347) at org.springframework.orm.hibernate3.HibernateTemplate$36.doInHibernate(HibernateTemplate.java:1056) at org.springframework.orm.hibernate3.HibernateTemplate$36.doInHibernate(HibernateTemplate.java:1) at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406) at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374) at org.springframework.orm.hibernate3.HibernateTemplate.findByCriteria(HibernateTemplate.java:1046) at com.bochy.link.cn.dao.impl.StorageDaoImpl.likeSelect(StorageDaoImpl.java:59) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:319) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202) at com.sun.proxy.$Proxy19.likeSelect(Unknown Source) at com.bochy.link.cn.controller.StorageController.likeSelect(StorageController.java:47) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:100) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:604) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:565) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882) at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789) at javax.servlet.http.HttpServlet.service(HttpServlet.java:650) at javax.servlet.http.HttpServlet.service(HttpServlet.java:731) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:958) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:452) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1087) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745)

菜鸟:高手帮看一下什么 原因?用代理方式时jdbcTemplate为NULL

<p>用代理方式执行时jdbcTemplate为NULL,高手帮看一下怎么回事呀????</p> <p> </p> <p>Exception in thread "main" java.lang.reflect.InvocationTargetException<br> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)<br> at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)<br> at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)<br> at java.lang.reflect.Method.invoke(Method.java:597)<br> at com.okgj.core.MessageExecutor.invoke(MessageExecutor.java:46)<br> at com.okgj.core.MessageExecutor.main(MessageExecutor.java:64)<br>Caused by: java.lang.NullPointerException<br> at com.okgj.service.dao.impl.UserDaoImpl.getUserInfo(UserDaoImpl.java:42)<br> at com.okgj.service.impl.UserServiceImpl.getUserInfo(UserServiceImpl.java:43)<br> at com.okgj.service.impl.UserServiceImpl$$EnhancerByCGLIB$$398c34af.getUserInfo(&lt;generated&gt;)<br> ... 6 more</p> <p> </p> <p>package com.okgj.service.dao.impl;<br><br>import java.util.ArrayList;<br>import java.util.List;<br><br>import javax.annotation.Resource;<br><br>import org.springframework.beans.factory.annotation.Autowired;<br>import org.springframework.jdbc.core.JdbcTemplate;<br>import org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport;<br>import org.springframework.jdbc.core.support.JdbcDaoSupport;<br>import org.springframework.orm.hibernate3.HibernateTemplate;<br>import org.springframework.stereotype.Repository;<br><br>import com.okgj.service.dao.UserDao;<br>import com.okgj.service.entity.userInfo;<br><br>@Repository<br>public class UserDaoImpl implements UserDao {<br><br>    private JdbcTemplate jdbcTemplate;<br><br>    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {<br>        this.jdbcTemplate = jdbcTemplate;<br>    }<br><br>    public JdbcTemplate getJdbcTemplate() {<br>        return jdbcTemplate;<br>    }<br><br>    @Override<br>    public List getUserInfo(String condition) {<br>        String sql = "select username,userpwd from tb_user";<br>        List userList = jdbcTemplate.queryForList(sql);<br>        return userList;<br>    }<br>}</p> <p> </p> <p>debug下面类时不会出错,</p> <p> </p> <p>package com.okgj.service.impl;<br><br>import java.lang.reflect.Method;<br>import java.util.List;<br><br>import javax.annotation.Resource;<br><br>import org.springframework.context.ApplicationContext;<br>import org.springframework.context.support.FileSystemXmlApplicationContext;<br>import org.springframework.stereotype.Service;<br>import org.springframework.transaction.annotation.Transactional;<br><br>import com.okgj.service.UserService;<br>import com.okgj.service.dao.UserDao;<br>import com.okgj.service.dao.impl.UserDaoImpl;<br><br>import org.springframework.transaction.annotation.Propagation;<br><br>@Service<br>@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)<br>public class UserServiceImpl implements UserService {<br>    @Resource<br>    private UserDao userDao = new UserDaoImpl();<br><br>    public UserDao getUserDao() {<br>        return userDao;<br>    }<br><br>    public void setUserDao(UserDao userDao) {<br>        this.userDao = userDao;<br>    }<br><br>    public List getUserInfo(String condition) {<br>        return userDao.getUserInfo(condition);<br>    }<br><br>    public static void main(String[] args) throws Throwable {<br>        ApplicationContext context = new FileSystemXmlApplicationContext(<br>                "classpath:spring-service.xml");<br>         UserService userService = (UserService)<br>         context.getBean("userService");<br>        <br>         List list = userService.getUserInfo("");<br>         System.out.println(list.toString());<br><br>    }<br><br>}</p> <p> </p> <p>而通过代理的方式执行却报上面的错,为什么 呀?急呀!!!!!!</p> <p> </p> <p>package com.okgj.service.impl;<br><br>import java.lang.reflect.Method;<br>import java.util.List;<br><br>import javax.annotation.Resource;<br><br>import org.springframework.context.ApplicationContext;<br>import org.springframework.context.support.FileSystemXmlApplicationContext;<br>import org.springframework.stereotype.Service;<br>import org.springframework.transaction.annotation.Transactional;<br><br>import com.okgj.service.UserService;<br>import com.okgj.service.dao.UserDao;<br>import com.okgj.service.dao.impl.UserDaoImpl;<br><br>import org.springframework.transaction.annotation.Propagation;<br><br>@Service<br>@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)<br>public class UserServiceImpl implements UserService {<br>    @Resource<br>    private UserDao userDao = new UserDaoImpl();<br><br>    public UserDao getUserDao() {<br>        return userDao;<br>    }<br><br>    public void setUserDao(UserDao userDao) {<br>        this.userDao = userDao;<br>    }<br><br>    public List getUserInfo(String condition) {<br>        return userDao.getUserInfo(condition);<br>    }<br><br>    public static void main(String[] args) throws Throwable {<br>        ApplicationContext context = new FileSystemXmlApplicationContext(<br>                "classpath:spring-service.xml");<br>        <br><br>        Class&lt;?&gt; c = (Class&lt;?&gt;) context.getBean("userService").getClass();<br>        Object obj = c.newInstance();<br><br>        Method m = c.getMethod("getUserInfo",<br>                new Class[] { java.lang.String.class });<br>        Object result = m.invoke(obj, new Object[] { "" });<br>    }<br><br>}</p> <p> </p> <p>spring的配置文件如下:</p> <p>&lt;?xml version="1.0" encoding="UTF-8"?&gt;<br><br>&lt;beans xmlns="http://www.springframework.org/schema/beans"<br>    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"<br>    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"<br>    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd<br>                http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd<br>                http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd<br>                http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"&gt;<br><br>    &lt;import resource="spring-db-connectionpool.xml" /&gt;<br><br>    &lt;bean id="userService" class="com.okgj.service.impl.UserServiceImpl"&gt;<br>        &lt;property name="userDao" ref="userDao" /&gt;<br>    &lt;/bean&gt;<br>    &lt;bean id="orderService" class="com.okgj.service.impl.OrderServiceImpl"&gt;<br>        &lt;property name="userDao" ref="userDao" /&gt;<br>    &lt;/bean&gt;<br>    &lt;bean id="userDao" class="com.okgj.service.dao.impl.UserDaoImpl"&gt;<br>        &lt;property name="jdbcTemplate" ref="jdbcTemplate" /&gt;<br>    &lt;/bean&gt;<br><br>&lt;/beans&gt;</p> <p> </p> <p>&lt;!--数据源配置,使用应用内的C3P0数据库连接池  --&gt;<br>    &lt;bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"<br>        destroy-method="close"&gt;<br>        &lt;property name="driverClass" value="com.mysql.jdbc.Driver" /&gt;<br>        &lt;property name="jdbcUrl" value="jdbc:mysql://localhost/projectmanagesystem" /&gt;<br>        &lt;property name="user" value="root" /&gt;<br>        &lt;property name="password" value="" /&gt;<br>        &lt;property name="numHelperThreads" value="5" /&gt;<br>        &lt;property name="maxPoolSize" value="20" /&gt;<br>        &lt;property name="minPoolSize" value="5" /&gt;<br>        &lt;property name="initialPoolSize" value="5" /&gt;<br>    &lt;/bean&gt;</p> <p> </p> <p>&lt;!-- 添加AnnotationSessionFactoryBean,提供注解注入支持 --&gt;<br>    &lt;bean id="sessionFactory"<br>        class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"&gt;<br>        &lt;property name="dataSource" ref="dataSource" /&gt;<br>        &lt;property name="packagesToScan"&gt;<br>            &lt;list&gt;<br>                &lt;value&gt;com.okgj.service.*&lt;/value&gt;<br>            &lt;/list&gt;<br>        &lt;/property&gt;<br>        &lt;property name="hibernateProperties"&gt;<br>            &lt;props&gt;<br>                &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/prop&gt;<br>                &lt;prop key="hibernate.show_sql"&gt;false&lt;/prop&gt;<br>                &lt;prop key="hibernate.hbm2ddl.auto"&gt;create&lt;/prop&gt;<br>                &lt;prop key="hibernate.format_sql"&gt;false&lt;/prop&gt;<br>                &lt;!-- &lt;prop key="hibernate.connection.autocommit"&gt;true &lt;/prop&gt;--&gt;<br>                &lt;prop key="hibernate.cache.provider_class"&gt;<br>                    net.sf.ehcache.hibernate.EhCacheProvider<br>                &lt;/prop&gt;<br>                &lt;prop key="hibernate.cache.use_query_cache"&gt;true&lt;/prop&gt;<br>            &lt;/props&gt;<br>        &lt;/property&gt;<br>    &lt;/bean&gt;<br><br>    &lt;bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate"&gt;<br>        &lt;property name="sessionFactory" ref="sessionFactory" /&gt;<br>    &lt;/bean&gt;<br><br>    &lt;!--   JdbcTemplate   --&gt;<br>    &lt;bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"&gt;<br>        &lt;property name="dataSource" ref="dataSource" /&gt;<br>    &lt;/bean&gt;</p> <p> </p>

使用ssh框架做新增功能时无法将数据写入数据库

在spring配置文件中配置了事务管理 <!-- 配置事务管理器 --> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <!-- 开启事务注解 --> <tx:annotation-driven transaction-manager="transactionManager"/> <!-- 开启注解扫描 --> <context:component-scan base-package="com"></context:component-scan > 而且在类上面也开启了事务注解: import javax.transaction.Transactional; import com.dao.YongHuDao; import com.entity.YongHu; import com.service.YongHuService; @Transactional public class YongHuServiceImpl implements YongHuService { private YongHuDao yhdi; @Override public void add(YongHu t) { yhdi.add(t); } 控制台没有错误信息,只输出一条查询伪表id的sql语句: DEBUG - Found thread-bound Session for HibernateTemplate DEBUG - trace com.mchange.v2.resourcepool.BasicResourcePool@58aff4cd [managed: 3, unused: 2, excluded: 0] (e.g. com.mchange.v2.c3p0.impl.NewPooledConnection@49056629) Hibernate: select hibernate_sequence.nextval from dual DEBUG - Not closing pre-bound Hibernate Session after HibernateTemplate hahahhaah26hahahahhahha DEBUG - Entering nullPropertyValue [target=[com.entity.YongHu@2e81070, com.action.UserAction@3e625613, com.opensymphony.xwork2.DefaultTextProvider@17e36931], property=struts] DEBUG - Entering nullPropertyValue [target=[com.entity.YongHu@2e81070, com.action.UserAction@3e625613, com.opensymphony.xwork2.DefaultTextProvider@17e36931], property=org] DEBUG - after Locale=zh_CN 实在找不出哪里错了,求大神解答

大学四年自学走来,这些私藏的实用工具/学习网站我贡献出来了

大学四年,看课本是不可能一直看课本的了,对于学习,特别是自学,善于搜索网上的一些资源来辅助,还是非常有必要的,下面我就把这几年私藏的各种资源,网站贡献出来给你们。主要有:电子书搜索、实用工具、在线视频学习网站、非视频学习网站、软件下载、面试/求职必备网站。 注意:文中提到的所有资源,文末我都给你整理好了,你们只管拿去,如果觉得不错,转发、分享就是最大的支持了。 一、电子书搜索 对于大部分程序员...

在中国程序员是青春饭吗?

今年,我也32了 ,为了不给大家误导,咨询了猎头、圈内好友,以及年过35岁的几位老程序员……舍了老脸去揭人家伤疤……希望能给大家以帮助,记得帮我点赞哦。 目录: 你以为的人生 一次又一次的伤害 猎头界的真相 如何应对互联网行业的「中年危机」 一、你以为的人生 刚入行时,拿着傲人的工资,想着好好干,以为我们的人生是这样的: 等真到了那一天,你会发现,你的人生很可能是这样的: ...

程序员请照顾好自己,周末病魔差点一套带走我。

程序员在一个周末的时间,得了重病,差点当场去世,还好及时挽救回来了。

技术大佬:我去,你写的 switch 语句也太老土了吧

昨天早上通过远程的方式 review 了两名新来同事的代码,大部分代码都写得很漂亮,严谨的同时注释也很到位,这令我非常满意。但当我看到他们当中有一个人写的 switch 语句时,还是忍不住破口大骂:“我擦,小王,你丫写的 switch 语句也太老土了吧!” 来看看小王写的代码吧,看完不要骂我装逼啊。 private static String createPlayer(PlayerTypes p...

和黑客斗争的 6 天!

互联网公司工作,很难避免不和黑客们打交道,我呆过的两家互联网公司,几乎每月每天每分钟都有黑客在公司网站上扫描。有的是寻找 Sql 注入的缺口,有的是寻找线上服务器可能存在的漏洞,大部分都...

点沙成金:英特尔芯片制造全过程揭密

“亚马逊丛林里的蝴蝶扇动几下翅膀就可能引起两周后美国德州的一次飓风……” 这句人人皆知的话最初用来描述非线性系统中微小参数的变化所引起的系统极大变化。 而在更长的时间尺度内,我们所生活的这个世界就是这样一个异常复杂的非线性系统…… 水泥、穹顶、透视——关于时间与技艺的蝴蝶效应 公元前3000年,古埃及人将尼罗河中挖出的泥浆与纳特龙盐湖中的矿物盐混合,再掺入煅烧石灰石制成的石灰,由此得来了人...

讲一个程序员如何副业月赚三万的真实故事

loonggg读完需要3分钟速读仅需 1 分钟大家好,我是你们的校长。我之前讲过,这年头,只要肯动脑,肯行动,程序员凭借自己的技术,赚钱的方式还是有很多种的。仅仅靠在公司出卖自己的劳动时...

上班一个月,后悔当初着急入职的选择了

最近有个老铁,告诉我说,上班一个月,后悔当初着急入职现在公司了。他之前在美图做手机研发,今年美图那边今年也有一波组织优化调整,他是其中一个,在协商离职后,当时捉急找工作上班,因为有房贷供着,不能没有收入来源。所以匆忙选了一家公司,实际上是一个大型外包公司,主要派遣给其他手机厂商做外包项目。**当时承诺待遇还不错,所以就立马入职去上班了。但是后面入职后,发现薪酬待遇这块并不是HR所说那样,那个HR自...

女程序员,为什么比男程序员少???

昨天看到一档综艺节目,讨论了两个话题:(1)中国学生的数学成绩,平均下来看,会比国外好?为什么?(2)男生的数学成绩,平均下来看,会比女生好?为什么?同时,我又联想到了一个技术圈经常讨...

副业收入是我做程序媛的3倍,工作外的B面人生是怎样的?

提到“程序员”,多数人脑海里首先想到的大约是:为人木讷、薪水超高、工作枯燥…… 然而,当离开工作岗位,撕去层层标签,脱下“程序员”这身外套,有的人生动又有趣,马上展现出了完全不同的A/B面人生! 不论是简单的爱好,还是正经的副业,他们都干得同样出色。偶尔,还能和程序员的特质结合,产生奇妙的“化学反应”。 @Charlotte:平日素颜示人,周末美妆博主 大家都以为程序媛也个个不修边幅,但我们也许...

MySQL数据库面试题(2020最新版)

文章目录数据库基础知识为什么要使用数据库什么是SQL?什么是MySQL?数据库三大范式是什么mysql有关权限的表都有哪几个MySQL的binlog有有几种录入格式?分别有什么区别?数据类型mysql有哪些数据类型引擎MySQL存储引擎MyISAM与InnoDB区别MyISAM索引与InnoDB索引的区别?InnoDB引擎的4大特性存储引擎选择索引什么是索引?索引有哪些优缺点?索引使用场景(重点)...

如果你是老板,你会不会踢了这样的员工?

有个好朋友ZS,是技术总监,昨天问我:“有一个老下属,跟了我很多年,做事勤勤恳恳,主动性也很好。但随着公司的发展,他的进步速度,跟不上团队的步伐了,有点...

我入职阿里后,才知道原来简历这么写

私下里,有不少读者问我:“二哥,如何才能写出一份专业的技术简历呢?我总感觉自己写的简历太烂了,所以投了无数份,都石沉大海了。”说实话,我自己好多年没有写过简历了,但我认识的一个同行,他在阿里,给我说了一些他当年写简历的方法论,我感觉太牛逼了,实在是忍不住,就分享了出来,希望能够帮助到你。 01、简历的本质 作为简历的撰写者,你必须要搞清楚一点,简历的本质是什么,它就是为了来销售你的价值主张的。往深...

我说我不会算法,阿里把我挂了。

不说了,字节跳动也反手把我挂了。

优雅的替换if-else语句

场景 日常开发,if-else语句写的不少吧??当逻辑分支非常多的时候,if-else套了一层又一层,虽然业务功能倒是实现了,但是看起来是真的很不优雅,尤其是对于我这种有强迫症的程序"猿",看到这么多if-else,脑袋瓜子就嗡嗡的,总想着解锁新姿势:干掉过多的if-else!!!本文将介绍三板斧手段: 优先判断条件,条件不满足的,逻辑及时中断返回; 采用策略模式+工厂模式; 结合注解,锦...

离职半年了,老东家又发 offer,回不回?

有小伙伴问松哥这个问题,他在上海某公司,在离职了几个月后,前公司的领导联系到他,希望他能够返聘回去,他很纠结要不要回去? 俗话说好马不吃回头草,但是这个小伙伴既然感到纠结了,我觉得至少说明了两个问题:1.曾经的公司还不错;2.现在的日子也不是很如意。否则应该就不会纠结了。 老实说,松哥之前也有过类似的经历,今天就来和小伙伴们聊聊回头草到底吃不吃。 首先一个基本观点,就是离职了也没必要和老东家弄的苦...

为什么你不想学习?只想玩?人是如何一步一步废掉的

不知道是不是只有我这样子,还是你们也有过类似的经历。 上学的时候总有很多光辉历史,学年名列前茅,或者单科目大佬,但是虽然慢慢地长大了,你开始懈怠了,开始废掉了。。。 什么?你说不知道具体的情况是怎么样的? 我来告诉你: 你常常潜意识里或者心理觉得,自己真正的生活或者奋斗还没有开始。总是幻想着自己还拥有大把时间,还有无限的可能,自己还能逆风翻盘,只不是自己还没开始罢了,自己以后肯定会变得特别厉害...

男生更看重女生的身材脸蛋,还是思想?

往往,我们看不进去大段大段的逻辑。深刻的哲理,往往短而精悍,一阵见血。问:产品经理挺漂亮的,有点心动,但不知道合不合得来。男生更看重女生的身材脸蛋,还是...

为什么程序员做外包会被瞧不起?

二哥,有个事想询问下您的意见,您觉得应届生值得去外包吗?公司虽然挺大的,中xx,但待遇感觉挺低,马上要报到,挺纠结的。

当HR压你价,说你只值7K,你该怎么回答?

当HR压你价,说你只值7K时,你可以流畅地回答,记住,是流畅,不能犹豫。 礼貌地说:“7K是吗?了解了。嗯~其实我对贵司的面试官印象很好。只不过,现在我的手头上已经有一份11K的offer。来面试,主要也是自己对贵司挺有兴趣的,所以过来看看……”(未完) 这段话主要是陪HR互诈的同时,从公司兴趣,公司职员印象上,都给予对方正面的肯定,既能提升HR的好感度,又能让谈判气氛融洽,为后面的发挥留足空间。...

面试:第十六章:Java中级开发(16k)

HashMap底层实现原理,红黑树,B+树,B树的结构原理 Spring的AOP和IOC是什么?它们常见的使用场景有哪些?Spring事务,事务的属性,传播行为,数据库隔离级别 Spring和SpringMVC,MyBatis以及SpringBoot的注解分别有哪些?SpringMVC的工作原理,SpringBoot框架的优点,MyBatis框架的优点 SpringCould组件有哪些,他们...

面试阿里p7,被按在地上摩擦,鬼知道我经历了什么?

面试阿里p7被问到的问题(当时我只知道第一个):@Conditional是做什么的?@Conditional多个条件是什么逻辑关系?条件判断在什么时候执...

你打算用Java 8一辈子都不打算升级到Java 14,真香

我们程序员应该抱着尝鲜、猎奇的心态,否则就容易固步自封,技术停滞不前。

无代码时代来临,程序员如何保住饭碗?

编程语言层出不穷,从最初的机器语言到如今2500种以上的高级语言,程序员们大呼“学到头秃”。程序员一边面临编程语言不断推陈出新,一边面临由于许多代码已存在,程序员编写新应用程序时存在重复“搬砖”的现象。 无代码/低代码编程应运而生。无代码/低代码是一种创建应用的方法,它可以让开发者使用最少的编码知识来快速开发应用程序。开发者通过图形界面中,可视化建模来组装和配置应用程序。这样一来,开发者直...

面试了一个 31 岁程序员,让我有所触动,30岁以上的程序员该何去何从?

最近面试了一个31岁8年经验的程序猿,让我有点感慨,大龄程序猿该何去何从。

大三实习生,字节跳动面经分享,已拿Offer

说实话,自己的算法,我一个不会,太难了吧

程序员垃圾简历长什么样?

已经连续五年参加大厂校招、社招的技术面试工作,简历看的不下于万份 这篇文章会用实例告诉你,什么是差的程序员简历! 疫情快要结束了,各个公司也都开始春招了,作为即将红遍大江南北的新晋UP主,那当然要为小伙伴们做点事(手动狗头)。 就在公众号里公开征简历,义务帮大家看,并一一点评。《启舰:春招在即,义务帮大家看看简历吧》 一石激起千层浪,三天收到两百多封简历。 花光了两个星期的所有空闲时...

《经典算法案例》01-08:如何使用质数设计扫雷(Minesweeper)游戏

我们都玩过Windows操作系统中的经典游戏扫雷(Minesweeper),如果把质数当作一颗雷,那么,表格中红色的数字哪些是雷(质数)?您能找出多少个呢?文中用列表的方式罗列了10000以内的自然数、质数(素数),6的倍数等,方便大家观察质数的分布规律及特性,以便对算法求解有指导意义。另外,判断质数是初学算法,理解算法重要性的一个非常好的案例。

《Oracle Java SE编程自学与面试指南》最佳学习路线图(2020最新版)

正确选择比瞎努力更重要!

一文带你入门Java Stream流,太强了

两个星期以前,就有读者强烈要求我写一篇 Java Stream 流的文章,我说市面上不是已经有很多了吗,结果你猜他怎么说:“就想看你写的啊!”你看你看,多么苍白的喜欢啊。那就“勉为其难”写一篇吧,嘻嘻。 单从“Stream”这个单词上来看,它似乎和 java.io 包下的 InputStream 和 OutputStream 有些关系。实际上呢,没毛关系。Java 8 新增的 Stream 是为...

立即提问
相关内容推荐