Я использую MyBatis и Spring, у меня есть 2 таблицы: Таблица пользователя и GroupMaster. Я хочу вставить данные в базу данных методом insert () следующим образом:
Класс пользователя:
public class User {
private Long user_id;
private GroupMaster group_id;
private String login_name;
private String password;
private String full_name;
private String full_name_kana;
private String email;
private String tel;
private Date birthday;
// getter and setter
}
Класс GroupMaster:
public class GroupMaster {
private Long group_id;
private String group_name;
// getter and setter
}
UserMapper.java
public interface UserMapper {
@Insert("INSERT INTO users(group_id, login_name, password, full_name,"
+ "full_name_kana, birthday, email, tel, rule, salt) VALUES"
+ "(#{group_id}, #{login_name},#{password}, #{full_name}, #{full_name_kana},"
+ "#{birthday}, #{email}, #{tel}, #{rule}, #{salt})")
@Options(useGeneratedKeys=true, keyProperty="id", flushCache=true, keyColumn="id")
public void insertUser(User user);
}
...
UserMapper.xml
<?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="net.project.springmybatis.mappers.UserMapper">
<resultMap id="userMap" type="User">
<id property="user_id" column="user_id"/>
<result property="login_name" column="login_name"/>
<result property="full_name" column="full_name"/>
<result property="full_name_kana" column="full_name_kana"/>
<result property="birthday" column="birthday"/>
<result property="email" column="email"/>
<result property="tel" column="tel"/>
<association property="group_id" javaType="GroupMaster">
<id property="group_id" column="group_id"/>
<result property="group_name" column="group_name"/>
</association>
<association property="detail_user_japan_id" javaType="DetailUserJapan">
<id property="detail_user_japan_id" column="detail_user_japan_id"/>
<result property="user_id" column="user_id"/>
<result property="code_level" column="code_level"/>
<result property="start_date" column="start_date"/>
<result property="end_date" column="end_date"/>
<result property="total" column="total"/>
</association>
<association property="code_level" javaType="JapanMaster">
<id property="code_level" column="code_level"/>
<result property="name_level" column="name_level"/>
</association>
</resultMap>
add_user.jsp:
<tr>
<td>group name</td>
<td>
<select name="groupSelected">
<c:forEach items="${groupMasterList}" var="groupMaster">
<option value="${groupMaster.group_id}">${groupMaster.group_name}</option>
</c:forEach>
</select>
</td>
</tr>
При развертывании возникает проблема и исключение, следующее как:
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.executor.ExecutorException: There was no TypeHandler found for parameter group_id of statement net.project.springmybatis.mappers.UserMapper.insertUser
org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73)
org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:365)
com.sun.proxy.$Proxy14.insert(Unknown Source)
org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:237)
org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:79)
org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:40)
com.sun.proxy.$Proxy20.insertUser(Unknown Source)
net.luvina.springmybatis.service.UserServiceImpl.insertUser(UserServiceImpl.java:31)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
в файле JSP. У меня есть форма для вставки с полем выбора, когда я отправляю сообщение об ошибке, возникает проблема. Как решить проблему
ОБНОВЛЕНИЕ:
Класс контроллера:
@RequestMapping(value = "/addUser", method = RequestMethod.POST)
public String submitAddNewUser(HttpServletRequest request, HttpServletResponse response,
@RequestParam("groupSelected") Integer groupSelected,
// @RequestParam("detailUserJapanSelected") Integer detailUserJapanSelected,
@RequestParam("japanMasterSelected") Integer japanMasterSelected,
@ModelAttribute("createUser") User createUser, ModelMap model) throws SQLException, IOException {
GroupMaster myGroupMaster = userService.getGroupById(groupSelected);
// DetailUserJapan myDetailUserJapan = userService.getDetailUserJapanById(detailUserJapanSelected);
JapanMaster myJapanMaster = userService.getJapanMasterById(japanMasterSelected);
// tao lan luot cho cac ham con lai
createUser.setGroup_id(myGroupMaster);
// createUser.setDetail_user_japan_id(myDetailUserJapan);
createUser.setCode_level(myJapanMaster);
// model.addAttribute("user", user);
userService.insertUser(createUser);
return "redirect:/";
}
add_user.jsp
<tr>
<td>資格: (name level | mst_japan)</td>
<td>
<select name="japanMasterSelected">
<c:forEach items="${japanMasterList}" var="japanMaster">
<option value="${japanMaster.code_level}">${japanMaster.name_level}</option>
</c:forEach>
</select>
</td>
</tr>
КогдаЯ добавляю больше с: code_level в mst_japan, это происходит ошибка 404 следующим образом: Ошибка 404:
HTTP Status 400 – Bad Request
Type Status Report
Description The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).