关于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 initParams = new HashMap(); // 设置忽略请求 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

现在遇到的问题是:
实体类中的格式 返回到页面后,字段格式变化了,如下图:
实体:
图片说明

数据库:
图片说明

返回到页面后的值(controller注解了@RestController):
图片说明

第二个字母 应该是大写C 结果变成了小写c。

而且有个现象是:
如果你的字段是 sName 那么前端拿到的是sname
如果你的字段是seName 那么前端拿到的就是seName 不会变化

也就是说 如果驼峰前字母是2个或2个以上 他就按照原来的格式了,不知道具体是什么原因,求大佬教导。

ps:
我试过很多种方法,只有一种有效果 就是给字段注解 @JsonProperty
但是这种方法会造成我的返回值里会有2个 sname 一个是sname 一个是sName 2个字段都是同样的值 给我一种复制的感觉。。

6个回答

我找到了两个回答,应该能说明你这个问题的,你看下:
http://blog.csdn.net/baggio7095586/article/details/6149768
http://blog.csdn.net/fenyuduanchangren/article/details/72964596
你可以把get/set方法改成这样子的试一试: getsName/setsName

一般情况下,属性的命名不应该使用第二个字母大写的方式,你可以看看你的getter/sertter方法就知道问题所在了,,

qq_34967750
qq_34967750 你没理解我的意思。。
大约 2 年之前 回复

能看看你controller对应方法的代码吗?

I'm sorry 我觉得你应该好好看看java的命名规范:
javabean命名要避免第二个字母大写,否在set,get的时候 它会有问题,会映射不上。反正各种问题,

拿走不谢^_^

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
关于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个字段都是同样的值 给我一种复制的感觉。。

springboot mybatis 整合后怎么答应输出sql语句

关于springboot mybatis 整合后,我想看到mybatis的sql语句日志输出,贴出我的Application.java代码 @SpringBootApplication //等价于@ComponentScan+@EnableAutoConfiguration+@Configuration @MapperScan("cn.no7player.mapper") public class Application { private static Logger logger = Logger.getLogger(Application.class); @Bean @ConfigurationProperties(prefix="spring.datasource") public DataSource dataSource() { return new org.apache.tomcat.jdbc.pool.DataSource(); } @Bean public SqlSessionFactory sqlSessionFactoryBean() throws Exception { SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean(); sqlSessionFactoryBean.setDataSource(dataSource()); PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); sqlSessionFactoryBean.setMapperLocations(resolver.getResources("classpath:/mybatis/*.xml")); return sqlSessionFactoryBean.getObject(); } @Bean public PlatformTransactionManager transactionManager() { return new DataSourceTransactionManager(dataSource()); } /** * Start */ public static void main(String[] args) { SpringApplication.run(Application.class, args); logger.info("SpringBoot Start Success"); } }

SpringBoot + MyBatis 内部实体类属性与数据库的对应关系

pojo 类 ``` //部门表 @Repository public class Department { private Integer id; private String departmentName; ``` ---- ``` //员工表 public class Employee { private Integer id; private String name; private String email; private Integer gender;//0 女 1男 private Department department; private Date birth; ``` 员工表中有个属性为Department ,员工表中department列该如何设计 整合Mybatis 时 EmployeeMapper.xml department 属性与 数据库对应列关系hai能自动关联么

springboot mybatis 动态表名后缀配置

比如现在数据库有不同版本的用户表 user_v1.5 ,user_v1.6,user_v1.7 现在我想通过配置,来读取不同版本的表 (配置v1.5 程序全局就读取user_v1.5这张表)

SpringBoot + MyBatis插入数据时乱码

SpringBoot + MyBatis插入数据时乱码应该怎么解决

用springboot+mybatis取出数据contant字段总是显示null(查了一下午debug没找出来)

实现类 ``` public Page<Person> getNewPersonList( Integer currentPage, Integer pageSize) { // 实例化查询条件 final PersonExample personExample = new PersonExample(); PersonExample.Criteria criteria = personExample.createCriteria(); criteria.andIsDeleteEqualTo((byte)0); // 获取查询结果集 Page<Person> result = PageHelper.startPage(currentPage, pageSize).doSelectPage(new ISelect() { @Override public void doSelect() { // personRepository.selectByExample(personExample); personRepository.selectByExample(personExample); } }); return result; } ``` 其中返回值得实体类的代码: ``` package com.ebiz.code.repository.api.entity; import java.util.Date; public class Person { /** * * This field was generated by MyBatis Generator. * This field corresponds to the database column ebiz_person.id * * @mbg.generated Sat May 11 13:04:24 CST 2019 */ private Integer id; /** * * This field was generated by MyBatis Generator. * This field corresponds to the database column ebiz_person.name * * @mbg.generated Sat May 11 13:04:24 CST 2019 */ private String name; /** * * This field was generated by MyBatis Generator. * This field corresponds to the database column ebiz_person.duty * * @mbg.generated Sat May 11 13:04:24 CST 2019 */ private String duty; /** * * This field was generated by MyBatis Generator. * This field corresponds to the database column ebiz_person.Email * * @mbg.generated Sat May 11 13:04:24 CST 2019 */ private String email; /** * * This field was generated by MyBatis Generator. * This field corresponds to the database column ebiz_person.phone * * @mbg.generated Sat May 11 13:04:24 CST 2019 */ private String phone; /** * * This field was generated by MyBatis Generator. * This field corresponds to the database column ebiz_person.place * * @mbg.generated Sat May 11 13:04:24 CST 2019 */ private String place; /** * * This field was generated by MyBatis Generator. * This field corresponds to the database column ebiz_person.is_delete * * @mbg.generated Sat May 11 13:04:24 CST 2019 */ private Byte isDelete; /** * * This field was generated by MyBatis Generator. * This field corresponds to the database column ebiz_person.create_time * * @mbg.generated Sat May 11 13:04:24 CST 2019 */ private Date createTime; /** * * This field was generated by MyBatis Generator. * This field corresponds to the database column ebiz_person.update_time * * @mbg.generated Sat May 11 13:04:24 CST 2019 */ private Date updateTime; /** * * This field was generated by MyBatis Generator. * This field corresponds to the database column ebiz_person.photo * * @mbg.generated Sat May 11 13:04:24 CST 2019 */ private String photo; /** * * This field was generated by MyBatis Generator. * This field corresponds to the database column ebiz_person.type * * @mbg.generated Sat May 11 13:04:24 CST 2019 */ private Byte type; /** * * This field was generated by MyBatis Generator. * This field corresponds to the database column ebiz_person.contant * * @mbg.generated Sat May 11 13:04:24 CST 2019 */ private String contant; /** * This method was generated by MyBatis Generator. * This method returns the value of the database column ebiz_person.id * * @return the value of ebiz_person.id * * @mbg.generated Sat May 11 13:04:24 CST 2019 */ public Integer getId() { return id; } /** * This method was generated by MyBatis Generator. * This method sets the value of the database column ebiz_person.id * * @param id the value for ebiz_person.id * * @mbg.generated Sat May 11 13:04:24 CST 2019 */ public void setId(Integer id) { this.id = id; } /** * This method was generated by MyBatis Generator. * This method returns the value of the database column ebiz_person.name * * @return the value of ebiz_person.name * * @mbg.generated Sat May 11 13:04:24 CST 2019 */ public String getName() { return name; } /** * This method was generated by MyBatis Generator. * This method sets the value of the database column ebiz_person.name * * @param name the value for ebiz_person.name * * @mbg.generated Sat May 11 13:04:24 CST 2019 */ public void setName(String name) { this.name = name; } /** * This method was generated by MyBatis Generator. * This method returns the value of the database column ebiz_person.duty * * @return the value of ebiz_person.duty * * @mbg.generated Sat May 11 13:04:24 CST 2019 */ public String getDuty() { return duty; } /** * This method was generated by MyBatis Generator. * This method sets the value of the database column ebiz_person.duty * * @param duty the value for ebiz_person.duty * * @mbg.generated Sat May 11 13:04:24 CST 2019 */ public void setDuty(String duty) { this.duty = duty; } /** * This method was generated by MyBatis Generator. * This method returns the value of the database column ebiz_person.Email * * @return the value of ebiz_person.Email * * @mbg.generated Sat May 11 13:04:24 CST 2019 */ public String getEmail() { return email; } /** * This method was generated by MyBatis Generator. * This method sets the value of the database column ebiz_person.Email * * @param email the value for ebiz_person.Email * * @mbg.generated Sat May 11 13:04:24 CST 2019 */ public void setEmail(String email) { this.email = email; } /** * This method was generated by MyBatis Generator. * This method returns the value of the database column ebiz_person.phone * * @return the value of ebiz_person.phone * * @mbg.generated Sat May 11 13:04:24 CST 2019 */ public String getPhone() { return phone; } /** * This method was generated by MyBatis Generator. * This method sets the value of the database column ebiz_person.phone * * @param phone the value for ebiz_person.phone * * @mbg.generated Sat May 11 13:04:24 CST 2019 */ public void setPhone(String phone) { this.phone = phone; } /** * This method was generated by MyBatis Generator. * This method returns the value of the database column ebiz_person.place * * @return the value of ebiz_person.place * * @mbg.generated Sat May 11 13:04:24 CST 2019 */ public String getPlace() { return place; } /** * This method was generated by MyBatis Generator. * This method sets the value of the database column ebiz_person.place * * @param place the value for ebiz_person.place * * @mbg.generated Sat May 11 13:04:24 CST 2019 */ public void setPlace(String place) { this.place = place; } /** * This method was generated by MyBatis Generator. * This method returns the value of the database column ebiz_person.is_delete * * @return the value of ebiz_person.is_delete * * @mbg.generated Sat May 11 13:04:24 CST 2019 */ public Byte getIsDelete() { return isDelete; } /** * This method was generated by MyBatis Generator. * This method sets the value of the database column ebiz_person.is_delete * * @param isDelete the value for ebiz_person.is_delete * * @mbg.generated Sat May 11 13:04:24 CST 2019 */ public void setIsDelete(Byte isDelete) { this.isDelete = isDelete; } /** * This method was generated by MyBatis Generator. * This method returns the value of the database column ebiz_person.create_time * * @return the value of ebiz_person.create_time * * @mbg.generated Sat May 11 13:04:24 CST 2019 */ public Date getCreateTime() { return createTime; } /** * This method was generated by MyBatis Generator. * This method sets the value of the database column ebiz_person.create_time * * @param createTime the value for ebiz_person.create_time * * @mbg.generated Sat May 11 13:04:24 CST 2019 */ public void setCreateTime(Date createTime) { this.createTime = createTime; } /** * This method was generated by MyBatis Generator. * This method returns the value of the database column ebiz_person.update_time * * @return the value of ebiz_person.update_time * * @mbg.generated Sat May 11 13:04:24 CST 2019 */ public Date getUpdateTime() { return updateTime; } /** * This method was generated by MyBatis Generator. * This method sets the value of the database column ebiz_person.update_time * * @param updateTime the value for ebiz_person.update_time * * @mbg.generated Sat May 11 13:04:24 CST 2019 */ public void setUpdateTime(Date updateTime) { this.updateTime = updateTime; } /** * This method was generated by MyBatis Generator. * This method returns the value of the database column ebiz_person.photo * * @return the value of ebiz_person.photo * * @mbg.generated Sat May 11 13:04:24 CST 2019 */ public String getPhoto() { return photo; } /** * This method was generated by MyBatis Generator. * This method sets the value of the database column ebiz_person.photo * * @param photo the value for ebiz_person.photo * * @mbg.generated Sat May 11 13:04:24 CST 2019 */ public void setPhoto(String photo) { this.photo = photo; } /** * This method was generated by MyBatis Generator. * This method returns the value of the database column ebiz_person.type * * @return the value of ebiz_person.type * * @mbg.generated Sat May 11 13:04:24 CST 2019 */ public Byte getType() { return type; } /** * This method was generated by MyBatis Generator. * This method sets the value of the database column ebiz_person.type * * @param type the value for ebiz_person.type * * @mbg.generated Sat May 11 13:04:24 CST 2019 */ public void setType(Byte type) { this.type = type; } /** * This method was generated by MyBatis Generator. * This method returns the value of the database column ebiz_person.contant * * @return the value of ebiz_person.contant * * @mbg.generated Sat May 11 13:04:24 CST 2019 */ public String getContant() { return contant; } /** * This method was generated by MyBatis Generator. * This method sets the value of the database column ebiz_person.contant * * @param contant the value for ebiz_person.contant * * @mbg.generated Sat May 11 13:04:24 CST 2019 */ public void setContant(String contant) { this.contant = contant; } } ``` 数据库图字段没写错 ![图片说明](https://img-ask.csdn.net/upload/201905/11/1557568172_353594.png)

Springboot+Mybatis接收react前端POST请求查询不到结果

后台可以收到请求的json数据,用相同的数据单独测试后台也可以搜到结果。但是直接从react前端发送请求,搜索结果就为空。 单独测试后台StaffManagementController,main方法中创建staffAO对象department=chemistry, 可以搜索到staffVOList.size=6个结果。从react前端表单department输入chemistry,发送POST请求,搜索到结果却是staffVOList.size=0个结果. esclipse后台console也显示staffAO.department=chemistry,说明前端请求可以正确接收。但是不知道为什么搜索不到结果。问题应该出在后台,但是完全想不出还哪里能出问题。。 下面是controller,function,mapper代码。希望有高手指教,非常感谢! ``` @RestController @RequestMapping("/api") public class StaffManagementController { private StaffManagementFunction function; @PostMapping("staffs/find") List<StaffManagementViewObject> getStaffByKeys(@Valid @RequestBody StaffManagementArgumentObject staffAO) throws Exception { log.info("Request to search for staff: {}", staffAO); List<StaffManagementViewObject> staffs = function.findStaffByKeys(staffAO); if (staffs == null) { new ResponseEntity<>(HttpStatus.NOT_FOUND); } return staffs; ``` ``` @Service public class StaffManagementFunctionImpl implements StaffManagementFunction{ @Override public List<StaffManagementViewObject> findStaffByKeys(StaffManagementArgumentObject staffManagementArgumentObject) throws Exception { SqlSession session = MyBatisUtil.getSession(); StaffManagementMapper smMapper = session.getMapper(StaffManagementMapper.class); if(staffManagementArgumentObject==null){ throw new IllegalArgumentException("argumentObject cannot be blank"); } String genderInput = staffManagementArgumentObject.getGender(); String gender= (genderInput==null)?null:(genderInput=="male")?"true":"false"; staffManagementArgumentObject.setGender(gender); List<StaffManagement> staffList = smMapper.selectKeysLike(staffManagementArgumentObject); MyBatisUtil.closeSession(); List<StaffManagementViewObject> staffVOList = new ArrayList<StaffManagementViewObject> (); for(int i = 0 ; i < staffList.size() ; i++) { StaffManagement staff = staffList.get(i); String genderVO = AssertThrowUtil.parseGenderToString(staff.getGender()); String yearOfGraduationVO = AssertThrowUtil.parseYearToString(staff.getYear StaffManagementViewObject staffVO = new StaffManagementViewObject(); staffVO.setId(staff.getId()); staffVO.setName(staff.getName()); staffVO.setGender(genderVO); staffVO.setDepartment(staff.getDepartment()); staffVO.setYearOfGraduation(yearOfGraduation); staffVOList.add(staffVO); } return staffVOList; } ``` ``` StaffManagementMapper.xml <select id="selectKeysLike" parameterType="com.springboot.demo.controller.StaffManagementArgumentObject" resultMap="BaseResultMap"> select * from staff_management where Name like '%${name}%' AND Gender like '%${gender}%' AND Department like '%${department}%' AND Position like '%${position}%' AND Year_of_graduation like '%${yearOfGraduation}%' </select> ```

springboot+mybatis事务使用

大家好我使用springboot集成mybatis,在一个业务处理中使用for循环插入数据, 比如list中有十条数据,for执行mappe.insert(user)十次,我的理解是方法上使用了 ``` @Transactional ``` 如果后面insert报错,前面插入的数据也会回滚,但是实际没有,我的理解哪里有问题吗?

springboot mybatis sqlserver 事务无法回滚

springboot mybatis sqlserver 事务无法回滚 控制台提示如下 明明已经加入了事务管理,抛出异常还是不会回滚 13:58:03.061 [http-nio-9000-exec-15] INFO c.n.c.u.d.DynamicDataSourceContextHolder - [setDataSourceType,26] - 切换到SQLSERVER_ERP数据源 Creating a new SqlSession Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5a38ece8] JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@595277fa] will be managed by Spring SQL提示巴拉巴拉 Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5a38ece8] Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5a38ece8] from current transaction SQL提示巴拉巴拉 Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5a38ece8] Fetched SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5a38ece8] from current transaction **执行插入sql,插入后执行 int a = 1/0;** Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5a38ece8] Transaction synchronization deregistering SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5a38ece8] Transaction synchronization closing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@5a38ece8] 13:58:03.313 [http-nio-9000-exec-15] ERROR c.n.f.e.GlobalExceptionHandler - [notFount,64] - 运行时异常: java.lang.ArithmeticException: / by zero at com.nbpt.yygs.service.hkhxkh.impl.YygsHkhxServiceImpl.excuteUpdateAndInsert(YygsHkhxServiceImpl.java:274) at com.nbpt.yygs.service.hkhxkh.impl.YygsHkhxServiceImpl.hexiao(YygsHkhxServiceImpl.java:245) at com.nbpt.yygs.service.hkhxkh.impl.YygsHkhxServiceImpl.ywyzidonghexiao(YygsHkhxServiceImpl.java:84) at com.nbpt.yygs.service.hkhxkh.impl.YygsHkhxServiceImpl$$FastClassBySpringCGLIB$$a7103f4.invoke(<generated>) at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:749) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:88) at com.nbpt.framework.aspectj.DataSourceAspect.around(DataSourceAspect.java:53) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:644) at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:633) at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:175) at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688) at com.nbpt.yygs.service.hkhxkh.impl.YygsHkhxServiceImpl$$EnhancerBySpringCGLIB$$971cc6f.ywyzidonghexiao(<generated>) at com.nbpt.yygs.service.hkhxkh.impl.YygsHkhxServiceImpl$$FastClassBySpringCGLIB$$a7103f4.invoke(<generated>) at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:749) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688) at com.nbpt.yygs.service.hkhxkh.impl.YygsHkhxServiceImpl$$EnhancerBySpringCGLIB$$da33e29b.ywyzidonghexiao(<generated>) at com.nbpt.web.yygs.hkhxkh.YygsHkhxController.ywyzidonghexiao(YygsHkhxController.java:90) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:189) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:800) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1038) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005) at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:908) at javax.servlet.http.HttpServlet.service(HttpServlet.java:660) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882) at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61) at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108) at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137) at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125) at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66) at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449) at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365) at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90) at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83) at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:387) at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362) at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108) at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137) at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:92) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:791) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1417) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748) 13:58:03.316 [http-nio-9000-exec-15] WARN o.s.w.s.m.m.a.ExceptionHandlerExceptionResolver - [logException,194] - Resolved [java.lang.ArithmeticException: / by zero]

springboot里面注解mybatis一对一无法自动映射

@Select(" SELECT * FROM buy_car WHERE user_id=#{user_id}") @Results({ @Result(column = "pro_Id",property = "productInfo", one=@One(select = "com.order.dao.ProductMapper.ProInfoByCar"))}) public ArrayList<BuyCar> CarInfoByUser(@Param("user_id")int user_id); 实现根据用户查找购物车的同时查出购物车里面商品的信息,运行无问题,购物车类里面的商品信息类里面可以拿到的,反而购物类本身的字段无法自动映射过去,需要手动在上面继续写result ArrayList<BuyCar> list=productService.CarInfoByUser(user.getUserId()) ; for (BuyCar buyCar : list) { System.out.println(buyCar.getBuy_time());//为空,无法映射,但是sql语句查询出来了 System.out.println(buyCar.getProductInfo().getPro_Name());//有拿到 System.out.println(buyCar.getProductInfo().getPro_logo()); } 购物车类 public class BuyCar { private Integer user_id;//拿不到 private Integer pro_id;//拿不到 private Integer buy_count;//拿不到 private Date buy_time;//拿不到 private ProductInfo productInfo;//自动映射到了 省略getset方法

springBoot集成mybatis与shiro

最近在做一个springBoot集成mybatis与shiro的Demo 但是遇到shiro验证用户名密码一直提示不正确,实在是搞不明白,demo奉上http://pan.baidu.com/s/1jI3m9ZC,望解答,谢谢。

springBoot + mybatis 执行SQL

在Controller中拼接一段自定义的SQL,这段SQL没有对应的mapper文件,如何让这段SQL执行并返回结果。

springboot+mybatis切换数据源问题

# 问题描述 springboot+mybatis想实现oracle和Mysql数据库切换,目前用 Mysql作为 主数据源时, 可以正常查询;用Oracle作为主数据源时,也可以正常查询;目前想实现,Mysql作为主数据源时,也可以切换到另外一个数据源。 # 相关代码如下 ## 创建数据源 ### 创建Mysql数据源 ``` @Bean(name = "dataSource") @Primary public ComboPooledDataSource createDataSource() throws PropertyVetoException { ComboPooledDataSource comboPooledDataSource = new ComboPooledDataSource(); comboPooledDataSource.setDriverClass(jdbcDriver); comboPooledDataSource.setJdbcUrl(jdbcUrl); comboPooledDataSource.setUser(jdbcUsername); comboPooledDataSource.setPassword(jdbcPassword); //连接关闭不自动提交 comboPooledDataSource.setAutoCommitOnClose(false); return comboPooledDataSource; } @Bean(name="sqlSessionFactory") @Primary public SqlSessionFactoryBean createSqlSessionFactoryBean(@Qualifier("dataSource") DataSource dataSource) throws IOException { SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean(); sqlSessionFactoryBean.setConfigLocation(new ClassPathResource(mybatisConfigFilePath)); PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); String packageSearchPath = PathMatchingResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + mapperPath; sqlSessionFactoryBean.setMapperLocations(resolver.getResources(packageSearchPath)); sqlSessionFactoryBean.setDataSource(dataSource); sqlSessionFactoryBean.setTypeAliasesPackage(entityPackage); return sqlSessionFactoryBean; } ``` ### 创建oracle数据源 ``` @Bean(name="oracleDataSource") public ComboPooledDataSource createOracleDataSource() throws PropertyVetoException { ComboPooledDataSource comboPooledOracleDataSource = new ComboPooledDataSource(); comboPooledOracleDataSource.setDriverClass(oracleJdbcDriver); comboPooledOracleDataSource.setJdbcUrl(oracleJdbcUrl); comboPooledOracleDataSource.setUser(oracleJdbcUser); comboPooledOracleDataSource.setPassword(oracleJdbcPassword); comboPooledOracleDataSource.setAutoCommitOnClose(false); return comboPooledOracleDataSource; } @Bean(name="oracleSqlSessionFactory") public SqlSessionFactoryBean createSqlSessionFactoryBean(@Qualifier("oracleDataSource") DataSource oracleDataSource) throws IOException { SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean(); sqlSessionFactoryBean.setConfigLocation(new ClassPathResource(mybatisConfigFilePath)); PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); String packageSearchPath = PathMatchingResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + oracleMapperPath; sqlSessionFactoryBean.setMapperLocations(resolver.getResources(packageSearchPath)); sqlSessionFactoryBean.setDataSource(oracleDataSource); sqlSessionFactoryBean.setTypeAliasesPackage(entityPackage); return sqlSessionFactoryBean; } ``` ## 事物管理代码段 ``` @Autowired @Qualifier("dataSource") private DataSource dataSource; @Autowired @Qualifier("oracleDataSource") private DataSource oracleDataSource; @Bean(name="localMysql") public PlatformTransactionManager localMysqlManager(){ return new DataSourceTransactionManager(dataSource); } @Bean(name="localOracle") public PlatformTransactionManager oracleManager(){ return new DataSourceTransactionManager(oracleDataSource); } ``` ## 切换数据源代码段 ``` @Override @Transactional(value = "localOracle") public List<Map> listOracle() { return helloOracleDao.listHello(); } ``` # 问题 感觉数据源创建什么的都没问题,但是最后一步切换不生效,不知道什么问题,还请大神赐教

mybatis 增加字段sql文

mybatis 增加字段sql文 怎么把下面这句话注解到xml alter table docdsp add dspcode char(200)

springboot整合mybatis中逆向生成的xxxExample文件

最近整合springboot+mybatis时候遇见两个问题, 一开始我用springboot2.1版本mysql8版本死活运行不了,一个劲找不到service的bean。 然后我换成了springboot2.0版本和mysql5.1版本就可以运行。 另外我按照网上的那些教材,发现当生成的model只有xxx一个时候,就没问题,而同时生成xxx和xxxExample时候,运行就会报错,说mapper无法生成bean,而生成时候取消Example就能正常运行。 没找到原因,头大。

Springboot下mybatis如何配置databaseId

Springboot设置了mybatis.config-location,然后在mybatis-config.xml下配置了databaseIdProvider type="DB_VENDOR" <databaseIdProvider type="DB_VENDOR"> <property name="DB2" value="db2"/> <property name="Oracle" value="oracle" /> <property name="Adaptive Server Enterprise" value="sybase"/> <property name="MySQL" value="mysql" /> </databaseIdProvider> 但是不会生效,调试发现初始化时由于Database是在application.propertities下定义的,mybatis初始化时会检测Environment是否为null,为null则不设置databaseId,在Spring下知道如何配置,但是SpringBoot下搞不定,求大神指点

springboot+mybatis+db2+vue

问题是这样的springboot+mybatis连接db2查询数据库 要1分钟有4600条数据 我看了看写的代码 用了javafor循环递归查询子机构 我改成数据库递归有就快了10几秒 在改成异步还是慢 我想了想 能不能先查询父机构 再点击父机构再去根据父机构查询子机构 思路倒是出来了 前端vue不知道怎么处理 tree树形菜单 求指点

springboot+mybatis+数据库连接池+mysql

**求助** 我这边有一个springboot的应用,通过浏览器请求后台服务,后台服务通过mybatis查询数据库的数据(数据库服务关闭),由于数据库连接不上连接池会报数据库无法连接,并且重复尝试连接,此时后台服务请求的无法捕获到数据库无法连接的异常整个线程一直处于等待状态,不知道该怎么捕获异常,这个请求资源能够正常释放?

springboot集成mybatis在日志中打印完整的sql语句(sql中不带有问号的那种)

我创建了一个springboot项目,集成了mybatis,和logback,可以打印日志也有sql,如下图: ![图片说明](https://img-ask.csdn.net/upload/202004/05/1586060984_340103.png) 这个打印的sql里带有问号,下面是对应的参数,但我不想要这种的sql,我想要完整的sql,就是把下面的参数填到对应的问号中去,这样只要把sql复制下来就可以执行在数据库中运行的那种,有没有办法,各位大佬

请问springboot+mybatis返回map类型时下划线怎么转驼峰命名?

有大佬有这方面的资料吗? 今天找了一个不用写拦截器的,但是没起到作用..

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

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

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

今年,我也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 是为...

立即提问
相关内容推荐