- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 spring 3 配置 mybatis 我正在关注文章
http://www.raistudies.com/spring/integrating-mybatis-3-and-spring-frameworks-part-2/
我正在使用 mybatis 生成器来生成所有的映射器和模型类。使用 mybatis 生成器后,我得到了以下类(class)。
import java.util.Date;
public class User extends BaseModel {
/**
* This field was generated by MyBatis Generator. This field corresponds to the database column users.id
* @mbggenerated Fri Aug 03 09:28:44 BST 2012
*/
private Integer id;
/**
* This field was generated by MyBatis Generator. This field corresponds to the database column users.username
* @mbggenerated Fri Aug 03 09:28:44 BST 2012
*/
private String username;
/**
* This field was generated by MyBatis Generator. This field corresponds to the database column users.email
* @mbggenerated Fri Aug 03 09:28:44 BST 2012
*/
private String email;
/**
* This field was generated by MyBatis Generator. This field corresponds to the database column users.crypted_password
* @mbggenerated Fri Aug 03 09:28:44 BST 2012
*/
to the database column users.first_name
* @mbggenerated Fri Aug 03 09:28:44 BST 2012
*/
private String firstName;
/**
* This field was generated by MyBatis Generator. This field corresponds to the database column users.last_name
* @mbggenerated Fri Aug 03 09:28:44 BST 2012
*/
private String lastName;
// I renoved the getter setter to save space.
}
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class UserExample {
/**
* This field was generated by MyBatis Generator. This field corresponds to the database table users
* @mbggenerated Fri Aug 03 09:28:44 BST 2012
*/
protected String orderByClause;
/**
* This field was generated by MyBatis Generator. This field corresponds to the database table users
* @mbggenerated Fri Aug 03 09:28:44 BST 2012
*/
protected boolean distinct;
/**
* This field was generated by MyBatis Generator. This field corresponds to the database table users
* @mbggenerated Fri Aug 03 09:28:44 BST 2012
*/
protected List<Criteria> oredCriteria;
/**
* This method was generated by MyBatis Generator. This method corresponds to the database table users
* @mbggenerated Fri Aug 03 09:28:44 BST 2012
*/
public UserExample() {
oredCriteria = new ArrayList<Criteria>();
}
/**
* This method was generated by MyBatis Generator. This method corresponds to the database table users
* @mbggenerated Fri Aug 03 09:28:44 BST 2012
*/
public void setOrderByClause(String orderByClause) {
this.orderByClause = orderByClause;
}
/**
* This method was generated by MyBatis Generator. This method corresponds to the database table users
* @mbggenerated Fri Aug 03 09:28:44 BST 2012
*/
public String getOrderByClause() {
return orderByClause;
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.mycom.myproject.db.mybatis.dao.UserMapper">
<resultMap id="BaseResultMap" type="com.mycom.myproject.db.mybatis.model.User">
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Fri Aug 03 09:28:44 BST 2012.
-->
<result column="id" jdbcType="INTEGER" property="id" />
<result column="username" jdbcType="VARCHAR" property="username" />
<result column="email" jdbcType="VARCHAR" property="email" />
<result column="first_name" jdbcType="VARCHAR" property="firstName" />
<result column="last_name" jdbcType="VARCHAR" property="lastName" />
</resultMap>
<sql id="Example_Where_Clause">
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Fri Aug 03 09:28:44 BST 2012.
-->
<where>
<foreach collection="oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Update_By_Example_Where_Clause">
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Fri Aug 03 09:28:44 BST 2012.
-->
<where>
<foreach collection="example.oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Base_Column_List">
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Fri Aug 03 09:28:44 BST 2012.
-->
id, username, email, crypted_password, password_salt, persistence_token, login_count,
failed_login_count, last_request_at, current_login_at, last_login_at, current_login_ip,
last_login_ip, created_at, updated_at, creator_id, updater_id, first_name, last_name
</sql>
<select id="selectByExample" parameterType="com.mycom.myproject.db.mybatis.model.UserExample" resultMap="BaseResultMap">
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Fri Aug 03 09:28:44 BST 2012.
-->
select
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List" />
from users
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
import com.mycom.myproject.db.mybatis.model.User;
import com.mycom.myproject.db.mybatis.model.UserExample;
import java.util.List;
import org.apache.ibatis.annotations.Param;
public interface UserMapper {
/**
* This method was generated by MyBatis Generator. This method corresponds to the database table users
* @mbggenerated Fri Aug 03 09:28:44 BST 2012
*/
int countByExample(UserExample example);
/**
* This method was generated by MyBatis Generator. This method corresponds to the database table users
* @mbggenerated Fri Aug 03 09:28:44 BST 2012
*/
int deleteByExample(UserExample example);
/**
* This method was generated by MyBatis Generator. This method corresponds to the database table users
* @mbggenerated Fri Aug 03 09:28:44 BST 2012
*/
int insert(User record);
/**
* This method was generated by MyBatis Generator. This method corresponds to the database table users
* @mbggenerated Fri Aug 03 09:28:44 BST 2012
*/
int insertSelective(User record);
/**
* This method was generated by MyBatis Generator. This method corresponds to the database table users
* @mbggenerated Fri Aug 03 09:28:44 BST 2012
*/
List<User> selectByExample(UserExample example);
/**
* This method was generated by MyBatis Generator. This method corresponds to the database table users
* @mbggenerated Fri Aug 03 09:28:44 BST 2012
*/
int updateByExampleSelective(@Param("record") User record,
@Param("example") UserExample example);
/**
* This method was generated by MyBatis Generator. This method corresponds to the database table users
* @mbggenerated Fri Aug 03 09:28:44 BST 2012
*/
int updateByExample(@Param("record") User record,
@Param("example") UserExample example);
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">
<!-- Enable annotation driven controllers, validation etc... -->
<mvc:annotation-driven />
<context:component-scan
base-package="com.mycom.myproject" />
<mvc:resources mapping="/resources/**" location="/resources/" />
<bean id="datasource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost/mydatabase"/>
<property name="username" value="root"/>
<property name="password" value="root"/>
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="datasource" />
</bean>
<!-- scan for mappers and will automatically scan the whole classpath for xmls -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="sqlSessionFactory" ref="sqlSessionFactory" />
<property name="basePackage" value="com.mycom.myproject.db.mybatis.dao" />
</bean>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
@Controller
@RequestMapping("/")
public class LoginController
{
static final Logger logger = Logger.getLogger(LoginController.class);
private UserMapper userMapper = null;
@RequestMapping("/login")
public ModelAndView login(@ModelAttribute User userBean, Model model){
return new ModelAndView("login", "userBean", userBean);
}
@Autowired
public void setUserMapper(UserMapper userMapper) {
this.userMapper = userMapper;
}
}
Error creating bean with name 'loginController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void com.mycom.myproject.controller.LoginController.setUserMapper(com.mycom.myproject.db.mybatis.dao.UserMapper); nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.mycom.myproject.db.mybatis.dao.UserMapper] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
最佳答案
在 userMapper.xml 中可以读取:
<mapper namespace="com.mycom.myproject.db.mybatis.dao.UserMapper">
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.mycom.mydatabase.db.mybatis.sqlmap" />
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.mycom.myproject.db.mybatis.dao" />
</bean>
关于spring - 带有spring 3的mybatis无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11793692/
1.概述 转载:MyBatis 二级缓存全详解 上一篇文章中我们介绍到了 MyBatis 一级缓存其实就是 SqlSession 级别的缓存,什么是 SqlSession 级别的缓存呢?一级缓存的本质
1.概述 转载:核心配置综述之StatementHandler 2.MyBatis 四大组件之StatementHandler StatementHandler 是四大组件中最重要的一个对象,负责操作
1.概述 转载:MyBatis 启动流程 MyBatis 是第一个支持自定义 SQL、存储过程和高级映射的类持久框架。MyBatis 消除了大部分 JDBC 的样板代码、手动设置参数以及检索结果。My
1.概述 转载:MyBatis 基础搭建及架构概述 2.MyBatis 是什么? MyBatis是第一个支持自定义SQL、存储过程和高级映射的类持久框架。MyBatis消除了大部分JDBC的样板代码、
1.概述 转载:核心配置综述之 ParameterHandler MyBatis 四大核心组件我们已经了解到了两种,一个是 Executor ,它是MyBatis 解析SQL请求首先会经过的第一道关卡
1.概述 转载:核心配置综述之 ResultSetHandler 我们之前介绍过了MyBatis 四大核心配置之 Executor、StatementHandler、 ParameterHandler
如果我使用mybatis,我可以很容易地得到更新的行数,就像 update table set desc = 'xxx' where name = ? 但是,如果我想获取更新的行数,而不是计数,我该如
如何在MyBatis 3中使用小于等于 SELECT * FROM( SELECT * FROM TABLE1 WHERE COL1 =#{COL1,jdbc
我将 mybatis3.0.6 与 java 一起使用 哪个性能更好? [select id="getData" parameterType="Integer" resultType="Integer
我无法在 mybatis 中使用动态排序类型创建 SQL,如下例 select user_profile.user_profile_id, user_profile.first_name
这是一个流行的例子。 insert into ACCOUNT ( ACC_ID, ACC_FIRST_NAME, ACC_LAST_NAME, ACC_EMAIL )values (
我下载了MyBatis,文件夹中有一个mybatis-3.0.4-javadoc.jar,我解压并打开它,但它几乎是空的。 哪里可以找到MyBatis的API文档? 最佳答案 http://repo1
我正在尝试为 ArrayList 编写类型处理程序,但这给了我错误,任何人都可以帮助我。 我想将 ArrayList 作为 VARCHAR 存储在数据库中并将其检索为 ArrayList。 packa
目录 依赖 配置 CodeGenerator mybatis-plus-generator + clickhouse 自动生成代码 依赖
目录 三者实现对比 使用fluent mybatis 来实现上面的功能 换成mybatis原生实现效果 换成mybatis plus
例如,我有查询从员工中选择 ID、姓名、年龄、地址,而不是拥有员工对象列表。我希望有一个 map 列表,如 list{ map{ ("id", 123), ("name","jac
我在使 MyBatis (3.4.6) 工作时遇到一些麻烦。 我已将 mybatis-config.xml 文件放置在项目的 src/main/resources 文件夹中,但是当我运行单元测试时,出
我现在使用 Mybatis 和 spring-boot。我没有添加mybatis-config.xml。我根据说明通过 application.properties 为数据源和 mybatis 进行所
这是我的第一篇文章,用我糟糕的英语...... 我使用的是MyBatis3.0 在查询中,我使用 SqlBuilder 的方法如下: public class DataStatisticSqlBuil
主题:MyBatis:Boolean Paraeter:MyBatis 正在使用 Getter 内容: 大家好, 我一直在寻找解决我近乎简单的 MyBatis 问题的方法: 给定代码(仅必要部分):
我是一名优秀的程序员,十分优秀!